mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 03:11:46 +00:00
fix: fix onConfigChange
This commit is contained in:
@ -7,8 +7,10 @@ import { MenuContext } from '@/types/contexts';
|
||||
import config from '@/config';
|
||||
import { setApplicationMenu } from '@/menu';
|
||||
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
|
||||
const menuTemplateMap: Record<string, MenuItemConstructorOptions[]> = {};
|
||||
const createContext = (id: string, win: BrowserWindow): MenuContext => ({
|
||||
const createContext = (id: string, win: BrowserWindow): MenuContext<PluginConfig> => ({
|
||||
getConfig: () => config.plugins.getOptions(id),
|
||||
setConfig: (newConfig) => {
|
||||
config.setPartial(`plugins.${id}`, newConfig);
|
||||
@ -23,13 +25,13 @@ const createContext = (id: string, win: BrowserWindow): MenuContext => ({
|
||||
},
|
||||
});
|
||||
|
||||
export const forceLoadMenuPlugin = (id: string, win: BrowserWindow) => {
|
||||
export const forceLoadMenuPlugin = async (id: string, win: BrowserWindow) => {
|
||||
try {
|
||||
const plugin = allPlugins[id];
|
||||
if (!plugin) return;
|
||||
|
||||
const menu = plugin.menu?.(createContext(id, win));
|
||||
if (menu) menuTemplateMap[id] = menu;
|
||||
if (menu) menuTemplateMap[id] = await menu;
|
||||
else return;
|
||||
|
||||
console.log('[YTMusic]', `Successfully loaded '${id}::menu'`);
|
||||
@ -42,7 +44,7 @@ export const loadAllMenuPlugins = (win: BrowserWindow) => {
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
|
||||
for (const [pluginId, pluginDef] of Object.entries(allPlugins)) {
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {});
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) as PluginConfig;
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadMenuPlugin(pluginId, win);
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { preloadPlugins } from 'virtual:plugins';
|
||||
|
||||
import { type PluginDef } from '@/types/plugins';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { type PreloadContext } from '@/types/contexts';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
const loadedPluginMap: Record<string, PluginDef> = {};
|
||||
const createContext = (id: string): PreloadContext => ({
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
|
||||
const createContext = (id: string): PreloadContext<PluginConfig> => ({
|
||||
getConfig: () => config.plugins.getOptions(id),
|
||||
setConfig: (newConfig) => {
|
||||
config.setPartial(`plugins.${id}`, newConfig);
|
||||
@ -52,7 +52,7 @@ export const loadAllPreloadPlugins = () => {
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
|
||||
for (const [pluginId, pluginDef] of Object.entries(preloadPlugins)) {
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {});
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) as PluginConfig;
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadPreloadPlugin(pluginId);
|
||||
@ -70,7 +70,7 @@ export const unloadAllPreloadPlugins = () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getLoadedPreloadPlugin = (id: string): PluginDef | undefined => {
|
||||
export const getLoadedPreloadPlugin = (id: string): PluginDef<unknown, unknown, unknown> | undefined => {
|
||||
return loadedPluginMap[id];
|
||||
};
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
const unregisterStyleMap: Record<string, (() => void)[]> = {};
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown, PluginConfig>> = {};
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
|
||||
|
||||
const createContext = <Config extends PluginConfig>(id: string): RendererContext<Config> => ({
|
||||
getConfig: () => window.mainConfig.plugins.getOptions(id),
|
||||
@ -77,7 +77,7 @@ export const loadAllRendererPlugins = () => {
|
||||
const pluginConfigs = window.mainConfig.plugins.getPlugins();
|
||||
|
||||
for (const [pluginId, pluginDef] of Object.entries(rendererPlugins)) {
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {});
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) as PluginConfig;
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadRendererPlugin(pluginId);
|
||||
@ -95,7 +95,7 @@ export const unloadAllRendererPlugins = () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getLoadedRendererPlugin = (id: string): PluginDef | undefined => {
|
||||
export const getLoadedRendererPlugin = (id: string): PluginDef<unknown, unknown, unknown> | undefined => {
|
||||
return loadedPluginMap[id];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user