mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 04:41:47 +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);
|
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) {
|
function initTheme(win: BrowserWindow) {
|
||||||
injectCSS(win.webContents, youtubeMusicCSS);
|
injectCSS(win.webContents, youtubeMusicCSS);
|
||||||
// Load user CSS
|
// Load user CSS
|
||||||
|
|||||||
@ -62,6 +62,7 @@ export type PluginBuilder<ID extends string, Config extends PluginBaseConfig> =
|
|||||||
config: Config;
|
config: Config;
|
||||||
name?: string;
|
name?: string;
|
||||||
styles?: string[];
|
styles?: string[];
|
||||||
|
restartNeeded: boolean;
|
||||||
};
|
};
|
||||||
export type PluginBuilderOptions<Config extends PluginBaseConfig = PluginBaseConfig> = {
|
export type PluginBuilderOptions<Config extends PluginBaseConfig = PluginBaseConfig> = {
|
||||||
name?: string;
|
name?: string;
|
||||||
@ -83,4 +84,5 @@ export const createPluginBuilder = <ID extends string, Config extends PluginBase
|
|||||||
name: options.name,
|
name: options.name,
|
||||||
config: options.config,
|
config: options.config,
|
||||||
styles: options.styles,
|
styles: options.styles,
|
||||||
|
restartNeeded: options.restartNeeded,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user