mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
feat(plugin): show dialog need to restart
This commit is contained in:
38
src/index.ts
38
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<Electron.MessageBoxReturnValue>;
|
||||
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
|
||||
|
||||
@ -62,6 +62,7 @@ export type PluginBuilder<ID extends string, Config extends PluginBaseConfig> =
|
||||
config: Config;
|
||||
name?: string;
|
||||
styles?: string[];
|
||||
restartNeeded: boolean;
|
||||
};
|
||||
export type PluginBuilderOptions<Config extends PluginBaseConfig = PluginBaseConfig> = {
|
||||
name?: string;
|
||||
@ -83,4 +84,5 @@ export const createPluginBuilder = <ID extends string, Config extends PluginBase
|
||||
name: options.name,
|
||||
config: options.config,
|
||||
styles: options.styles,
|
||||
restartNeeded: options.restartNeeded,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user