Skip to content

Commit

Permalink
fix: ignore full restart notification when already full restart
Browse files Browse the repository at this point in the history
  • Loading branch information
subframe7536 committed Dec 17, 2024
1 parent d0e4e45 commit 8ef1fad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
15 changes: 0 additions & 15 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfigObject } from 'reactive-vscode'
import * as Meta from './generated/meta'
import { showMessage } from './utils'

export const config = defineConfigObject<Meta.ScopedConfigKeyTypeMap>(
Meta.scopedConfigs.scope,
Expand All @@ -17,17 +16,3 @@ export function getFamilies() {
sansSerif: config['font.sansSerif'],
}
}

let last = hasElectronWindowOptions()
function hasElectronWindowOptions(): string {
return JSON.stringify(config.electron)
}

export function logWindowOptionsChanged() {
const current = hasElectronWindowOptions()
if (last !== current) {
const method = process.platform === 'darwin' ? 'Press "Command + Q"' : 'Close all windows'
showMessage(`Note: Please TOTALLY restart VSCode (${method}) to take effect, "custom-ui-style.electron" is changed`)
}
last = current
}
4 changes: 1 addition & 3 deletions src/manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FileManager } from './base'
import { version } from 'vscode'
import { config, logWindowOptionsChanged } from '../config'
import { config } from '../config'
import { runAndRestart } from '../utils'
import { CssFileManager } from './css'
import { JsonFileManager } from './json'
Expand All @@ -27,7 +27,6 @@ export function createFileManagers() {
return {
hasBakFile: () => [...managers, productJsonManager].every(m => m.hasBakFile),
reload: async (text: string) => {
logWindowOptionsChanged()
await runAndRestart(
text,
isVSCodeUsingESM || config.preferRestart,
Expand All @@ -37,7 +36,6 @@ export function createFileManagers() {
)
},
rollback: async (text: string) => {
logWindowOptionsChanged()
await runAndRestart(
text,
isVSCodeUsingESM || config.preferRestart,
Expand Down
19 changes: 19 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'node:path'
import { readFileSync, writeFileSync } from 'atomically'
import { useLogger } from 'reactive-vscode'
import { commands, window } from 'vscode'
import { config } from './config'
import * as Meta from './generated/meta'
import { baseDir } from './path'
import { restartApp } from './restart'
Expand All @@ -12,6 +13,23 @@ export const log = useLogger(Meta.displayName)

const lockFile = path.join(baseDir, `__${Meta.name}__.lock`)

let last = hasElectronWindowOptions()
function hasElectronWindowOptions(): string {
return JSON.stringify(config.electron)
}

function logWindowOptionsChanged(useFullRestart: boolean) {
const current = hasElectronWindowOptions()
if (last !== current) {
if (useFullRestart) {
return
}
const method = process.platform === 'darwin' ? 'Press "Command + Q"' : 'Close all windows'
showMessage(`Note: Please TOTALLY restart VSCode (${method}) to take effect, "custom-ui-style.electron" is changed`)
}
last = current
}

export async function runAndRestart(message: string, fullRestart: boolean, action: () => Promise<any>) {
let count = 5
const check = () => fs.existsSync(lockFile)
Expand All @@ -34,6 +52,7 @@ export async function runAndRestart(message: string, fullRestart: boolean, actio
writeFileSync(lockFile, String(Date.now()))
let success = true
try {
logWindowOptionsChanged(fullRestart)
await action()
} catch (error) {
logError('Fail to execute action', error)
Expand Down

0 comments on commit 8ef1fad

Please sign in to comment.