Skip to content

Commit bd8ee9e

Browse files
committed
feat: add total restart prompt
1 parent ce024cd commit bd8ee9e

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

src/config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfigObject } from 'reactive-vscode'
22
import * as Meta from './generated/meta'
3+
import { showMessage } from './utils'
34

45
export const config = defineConfigObject<Meta.ScopedConfigKeyTypeMap>(
56
Meta.scopedConfigs.scope,
@@ -16,3 +17,17 @@ export function getFamilies() {
1617
sansSerif: config['font.sansSerif'],
1718
}
1819
}
20+
21+
let last = hasElectronWindowOptions()
22+
function hasElectronWindowOptions(): string {
23+
return JSON.stringify(config.electron)
24+
}
25+
26+
export function logWindowOptionsChanged() {
27+
const current = hasElectronWindowOptions()
28+
if (last !== current) {
29+
const method = process.platform === 'darwin' ? 'Press "Command + Q"' : 'Close all windows'
30+
showMessage(`Note: Please TOTALLY restart VSCode (${method}) to take effect, "custom-ui-style.electron" is changed`)
31+
}
32+
last = current
33+
}

src/index.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@ import * as Meta from './generated/meta'
44
import { createFileManagers } from './manager'
55
import { debounce, showMessage } from './utils'
66

7+
const changedMsg = 'UI Style changed.'
8+
const rollbackMsg = 'UI Style rollback.'
9+
710
const { activate, deactivate } = defineExtension(() => {
811
const { hasBakFile, reload, rollback } = createFileManagers()
912

1013
if (!hasBakFile()) {
1114
showMessage(
12-
'Seems like first time use or new version is installed, reload the configuration now?',
15+
'Seems like first time use or new version is installed, reload now?',
1316
'Reload',
1417
'Cancel',
1518
)
16-
.then<any>(item => item === 'Reload' && reload('UI style changed'))
19+
.then<any>(item => item === 'Reload' && reload(changedMsg))
1720
}
1821

19-
useCommand(Meta.commands.reload, () => reload('UI style changed'))
20-
useCommand(Meta.commands.rollback, () => rollback('UI style rollback'))
22+
useCommand(Meta.commands.reload, () => reload(changedMsg))
23+
useCommand(Meta.commands.rollback, () => rollback(rollbackMsg))
2124

22-
const watchAndReload = debounce(
23-
() => showMessage('Configuration changed, apply?', 'Apply', 'Cancel')
24-
.then<any>(item => item === 'Apply' && reload('UI style changed')),
25-
1500,
26-
)
2725
const startWatch = () => {
26+
const watchAndReload = debounce(
27+
() => showMessage('Configuration changed, apply?', 'Apply', 'Cancel')
28+
.then<any>(item => item === 'Apply' && reload(changedMsg)),
29+
1500,
30+
)
2831
const cleanup1 = watch(
2932
() => editorConfig.fontFamily,
3033
() => !config['font.monospace'] && watchAndReload(),
@@ -47,7 +50,7 @@ const { activate, deactivate } = defineExtension(() => {
4750
} else {
4851
cleanup()
4952
}
50-
})
53+
}, { immediate: true })
5154
})
5255

5356
export { activate, deactivate }

src/manager/index.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { FileManager } from './base'
2+
import { logWindowOptionsChanged } from '../config'
23
import { runAndRestart } from '../utils'
34
import { CssFileManager } from './css'
45
import { MainFileManager } from './main'
@@ -14,13 +15,19 @@ export function createFileManagers() {
1415
]
1516
return {
1617
hasBakFile: () => managers.every(m => m.hasBakFile),
17-
reload: (text: string) => runAndRestart(
18-
text,
19-
() => Promise.all(managers.map(m => m.reload())),
20-
),
21-
rollback: (text: string) => runAndRestart(
22-
text,
23-
() => Promise.all(managers.map(m => m.rollback())),
24-
),
18+
reload: (text: string) => {
19+
logWindowOptionsChanged()
20+
runAndRestart(
21+
text,
22+
() => Promise.all(managers.map(m => m.reload())),
23+
)
24+
},
25+
rollback: (text: string) => {
26+
logWindowOptionsChanged()
27+
runAndRestart(
28+
text,
29+
() => Promise.all(managers.map(m => m.rollback())),
30+
)
31+
},
2532
}
2633
}

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export async function runAndRestart(message: string, action: () => Promise<any>)
2929
try {
3030
writeFileSync(lockFile, String(Date.now()))
3131
await action()
32-
const item = await window.showInformationMessage(message, { title: 'Restart vscode' })
33-
if (item) {
32+
const item = await showMessage(message, 'Reload Window', 'Cancel')
33+
if (item === 'Reload Window') {
3434
commands.executeCommand('workbench.action.reloadWindow')
3535
}
3636
} catch (e) {

0 commit comments

Comments
 (0)