From ffe53d5596001f187e0fbf5cfd59c1744a452a0c Mon Sep 17 00:00:00 2001 From: Su-Yong Date: Sun, 12 Nov 2023 02:02:54 +0900 Subject: [PATCH] feat(plugin): show dialog need to restart --- src/index.ts | 38 ++++++++++++++++++++++++++++++++++++ src/plugins/utils/builder.ts | 2 ++ 2 files changed, 40 insertions(+) diff --git a/src/index.ts b/src/index.ts index 8a03c2f8..7cecc620 100644 --- a/src/index.ts +++ b/src/index.ts @@ -131,12 +131,50 @@ const initHook = (win: BrowserWindow) => { } } + if (pluginBuilders[id as keyof PluginBuilderList].restartNeeded) { + showNeedToRestartDialog(id as keyof PluginBuilderList); + } + win.webContents.send('config-changed', id, config); } }); }); }; +const showNeedToRestartDialog = (id: keyof PluginBuilderList) => { + const builder = pluginBuilders[id]; + const dialogOptions: Electron.MessageBoxOptions = { + type: 'info', + buttons: ['Restart Now', 'Later'], + title: 'Restart Required', + message: `"${builder.name ?? builder.id}" needs to restart`, + detail: `"${builder.name ?? builder.id}" plugin requires a restart to take effect`, + defaultId: 0, + cancelId: 1, + }; + + let dialogPromise: Promise; + if (mainWindow) { + dialogPromise = dialog.showMessageBox(mainWindow, dialogOptions); + } else { + dialogPromise = dialog.showMessageBox(dialogOptions); + } + + dialogPromise.then((dialogOutput) => { + switch (dialogOutput.response) { + case 0: { + restart(); + break; + } + + // Ignore + default: { + break; + } + } + }); +}; + function initTheme(win: BrowserWindow) { injectCSS(win.webContents, youtubeMusicCSS); // Load user CSS diff --git a/src/plugins/utils/builder.ts b/src/plugins/utils/builder.ts index 965edf55..0c7bd655 100644 --- a/src/plugins/utils/builder.ts +++ b/src/plugins/utils/builder.ts @@ -62,6 +62,7 @@ export type PluginBuilder = config: Config; name?: string; styles?: string[]; + restartNeeded: boolean; }; export type PluginBuilderOptions = { name?: string; @@ -83,4 +84,5 @@ export const createPluginBuilder =