mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 02:51:46 +00:00
feat: run prettier
This commit is contained in:
@ -9,9 +9,15 @@ import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import type { BackendContext } from '@/types/contexts';
|
||||
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
|
||||
const loadedPluginMap: Record<
|
||||
string,
|
||||
PluginDef<unknown, unknown, unknown>
|
||||
> = {};
|
||||
|
||||
const createContext = (id: string, win: BrowserWindow): BackendContext<PluginConfig> => ({
|
||||
const createContext = (
|
||||
id: string,
|
||||
win: BrowserWindow,
|
||||
): BackendContext<PluginConfig> => ({
|
||||
getConfig: () =>
|
||||
deepmerge(
|
||||
allPlugins[id].config ?? { enabled: false },
|
||||
@ -36,7 +42,7 @@ const createContext = (id: string, win: BrowserWindow): BackendContext<PluginCon
|
||||
},
|
||||
removeHandler: (event: string) => {
|
||||
ipcMain.removeHandler(event);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
window: win,
|
||||
@ -56,19 +62,15 @@ export const forceUnloadMainPlugin = async (
|
||||
});
|
||||
if (
|
||||
hasStopped ||
|
||||
(
|
||||
hasStopped === null &&
|
||||
typeof plugin.backend !== 'function' && plugin.backend
|
||||
)
|
||||
(hasStopped === null &&
|
||||
typeof plugin.backend !== 'function' &&
|
||||
plugin.backend)
|
||||
) {
|
||||
delete loadedPluginMap[id];
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
return;
|
||||
} else {
|
||||
console.log(
|
||||
LoggerPrefix,
|
||||
`Cannot unload "${id}" plugin`,
|
||||
);
|
||||
console.log(LoggerPrefix, `Cannot unload "${id}" plugin`);
|
||||
return Promise.reject();
|
||||
}
|
||||
} catch (err) {
|
||||
@ -92,10 +94,9 @@ export const forceLoadMainPlugin = async (
|
||||
});
|
||||
if (
|
||||
hasStarted ||
|
||||
(
|
||||
hasStarted === null &&
|
||||
typeof plugin.backend !== 'function' && plugin.backend
|
||||
)
|
||||
(hasStarted === null &&
|
||||
typeof plugin.backend !== 'function' &&
|
||||
plugin.backend)
|
||||
) {
|
||||
loadedPluginMap[id] = plugin;
|
||||
} else {
|
||||
@ -103,10 +104,7 @@ export const forceLoadMainPlugin = async (
|
||||
return Promise.reject();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(
|
||||
LoggerPrefix,
|
||||
`Cannot initialize "${id}" plugin: `,
|
||||
);
|
||||
console.error(LoggerPrefix, `Cannot initialize "${id}" plugin: `);
|
||||
console.trace(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
@ -135,7 +133,9 @@ export const unloadAllMainPlugins = async (win: BrowserWindow) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getLoadedMainPlugin = (id: string): PluginDef<unknown, unknown, unknown> | undefined => {
|
||||
export const getLoadedMainPlugin = (
|
||||
id: string,
|
||||
): PluginDef<unknown, unknown, unknown> | undefined => {
|
||||
return loadedPluginMap[id];
|
||||
};
|
||||
|
||||
|
||||
@ -11,7 +11,10 @@ import type { BrowserWindow, MenuItemConstructorOptions } from 'electron';
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
|
||||
const menuTemplateMap: Record<string, MenuItemConstructorOptions[]> = {};
|
||||
const createContext = (id: string, win: BrowserWindow): MenuContext<PluginConfig> => ({
|
||||
const createContext = (
|
||||
id: string,
|
||||
win: BrowserWindow,
|
||||
): MenuContext<PluginConfig> => ({
|
||||
getConfig: () =>
|
||||
deepmerge(
|
||||
allPlugins[id].config ?? { enabled: false },
|
||||
@ -43,8 +46,7 @@ export const forceLoadMenuPlugin = async (id: string, win: BrowserWindow) => {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else return;
|
||||
} else return;
|
||||
|
||||
console.log(LoggerPrefix, `Successfully loaded '${id}::menu'`);
|
||||
} catch (err) {
|
||||
@ -57,7 +59,10 @@ export const loadAllMenuPlugins = async (win: BrowserWindow) => {
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
|
||||
for (const [pluginId, pluginDef] of Object.entries(allPlugins)) {
|
||||
const config = deepmerge(pluginDef.config ?? { enabled: false }, pluginConfigs[pluginId] ?? {});
|
||||
const config = deepmerge(
|
||||
pluginDef.config ?? { enabled: false },
|
||||
pluginConfigs[pluginId] ?? {},
|
||||
);
|
||||
|
||||
if (config.enabled) {
|
||||
await forceLoadMenuPlugin(pluginId, win);
|
||||
|
||||
@ -8,7 +8,10 @@ import config from '@/config';
|
||||
import type { PreloadContext } from '@/types/contexts';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
|
||||
const loadedPluginMap: Record<
|
||||
string,
|
||||
PluginDef<unknown, unknown, unknown>
|
||||
> = {};
|
||||
const createContext = (id: string): PreloadContext<PluginConfig> => ({
|
||||
getConfig: () =>
|
||||
deepmerge(
|
||||
@ -27,13 +30,7 @@ export const forceUnloadPreloadPlugin = async (id: string) => {
|
||||
ctx: 'preload',
|
||||
context: createContext(id),
|
||||
});
|
||||
if (
|
||||
hasStopped ||
|
||||
(
|
||||
hasStopped === null &&
|
||||
loadedPluginMap[id].preload
|
||||
)
|
||||
) {
|
||||
if (hasStopped || (hasStopped === null && loadedPluginMap[id].preload)) {
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
delete loadedPluginMap[id];
|
||||
} else {
|
||||
@ -53,20 +50,16 @@ export const forceLoadPreloadPlugin = async (id: string) => {
|
||||
|
||||
if (
|
||||
hasStarted ||
|
||||
(
|
||||
hasStarted === null &&
|
||||
typeof plugin.preload !== 'function' && plugin.preload
|
||||
)
|
||||
(hasStarted === null &&
|
||||
typeof plugin.preload !== 'function' &&
|
||||
plugin.preload)
|
||||
) {
|
||||
loadedPluginMap[id] = plugin;
|
||||
}
|
||||
|
||||
console.log(LoggerPrefix, `"${id}" plugin is loaded`);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
LoggerPrefix,
|
||||
`Cannot initialize "${id}" plugin: `,
|
||||
);
|
||||
console.error(LoggerPrefix, `Cannot initialize "${id}" plugin: `);
|
||||
console.trace(err);
|
||||
}
|
||||
};
|
||||
@ -75,7 +68,10 @@ export const loadAllPreloadPlugins = () => {
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
|
||||
for (const [pluginId, pluginDef] of Object.entries(preloadPlugins)) {
|
||||
const config = deepmerge(pluginDef.config ?? { enable: false }, pluginConfigs[pluginId] ?? {});
|
||||
const config = deepmerge(
|
||||
pluginDef.config ?? { enable: false },
|
||||
pluginConfigs[pluginId] ?? {},
|
||||
);
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadPreloadPlugin(pluginId);
|
||||
@ -93,7 +89,9 @@ export const unloadAllPreloadPlugins = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getLoadedPreloadPlugin = (id: string): PluginDef<unknown, unknown, unknown> | undefined => {
|
||||
export const getLoadedPreloadPlugin = (
|
||||
id: string,
|
||||
): PluginDef<unknown, unknown, unknown> | undefined => {
|
||||
return loadedPluginMap[id];
|
||||
};
|
||||
|
||||
|
||||
@ -8,9 +8,14 @@ import type { RendererContext } from '@/types/contexts';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
|
||||
const unregisterStyleMap: Record<string, (() => void)[]> = {};
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
|
||||
const loadedPluginMap: Record<
|
||||
string,
|
||||
PluginDef<unknown, unknown, unknown>
|
||||
> = {};
|
||||
|
||||
export const createContext = <Config extends PluginConfig>(id: string): RendererContext<Config> => ({
|
||||
export const createContext = <Config extends PluginConfig>(
|
||||
id: string,
|
||||
): RendererContext<Config> => ({
|
||||
getConfig: async () => window.ipcRenderer.invoke('get-config', id),
|
||||
setConfig: async (newConfig) => {
|
||||
await window.ipcRenderer.invoke('set-config', id, newConfig);
|
||||
@ -19,7 +24,8 @@ export const createContext = <Config extends PluginConfig>(id: string): Renderer
|
||||
send: (event: string, ...args: unknown[]) => {
|
||||
window.ipcRenderer.send(event, ...args);
|
||||
},
|
||||
invoke: (event: string, ...args: unknown[]) => window.ipcRenderer.invoke(event, ...args),
|
||||
invoke: (event: string, ...args: unknown[]) =>
|
||||
window.ipcRenderer.invoke(event, ...args),
|
||||
on: (event: string, listener: CallableFunction) => {
|
||||
window.ipcRenderer.on(event, (_, ...args: unknown[]) => {
|
||||
listener(...args);
|
||||
@ -27,7 +33,7 @@ export const createContext = <Config extends PluginConfig>(id: string): Renderer
|
||||
},
|
||||
removeAllListeners: (event: string) => {
|
||||
window.ipcRenderer.removeAllListeners(event);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@ -40,17 +46,14 @@ export const forceUnloadRendererPlugin = async (id: string) => {
|
||||
const plugin = rendererPlugins[id];
|
||||
if (!plugin) return;
|
||||
|
||||
const hasStopped = await stopPlugin(id, plugin, { ctx: 'renderer', context: createContext(id) });
|
||||
const hasStopped = await stopPlugin(id, plugin, {
|
||||
ctx: 'renderer',
|
||||
context: createContext(id),
|
||||
});
|
||||
if (plugin?.stylesheets) {
|
||||
document.querySelector(`style#plugin-${id}`)?.remove();
|
||||
}
|
||||
if (
|
||||
hasStopped ||
|
||||
(
|
||||
hasStopped === null &&
|
||||
plugin?.renderer
|
||||
)
|
||||
) {
|
||||
if (hasStopped || (hasStopped === null && plugin?.renderer)) {
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
} else {
|
||||
console.error(LoggerPrefix, `Cannot stop "${id}" plugin`);
|
||||
@ -69,10 +72,9 @@ export const forceLoadRendererPlugin = async (id: string) => {
|
||||
if (
|
||||
hasEvaled ||
|
||||
plugin?.stylesheets ||
|
||||
(
|
||||
hasEvaled === null &&
|
||||
typeof plugin?.renderer !== 'function' && plugin?.renderer
|
||||
)
|
||||
(hasEvaled === null &&
|
||||
typeof plugin?.renderer !== 'function' &&
|
||||
plugin?.renderer)
|
||||
) {
|
||||
loadedPluginMap[id] = plugin;
|
||||
|
||||
@ -84,7 +86,10 @@ export const forceLoadRendererPlugin = async (id: string) => {
|
||||
return styleSheet;
|
||||
});
|
||||
|
||||
document.adoptedStyleSheets = [...document.adoptedStyleSheets, ...styleSheetList];
|
||||
document.adoptedStyleSheets = [
|
||||
...document.adoptedStyleSheets,
|
||||
...styleSheetList,
|
||||
];
|
||||
}
|
||||
|
||||
console.log(LoggerPrefix, `"${id}" plugin is loaded`);
|
||||
@ -97,7 +102,7 @@ export const loadAllRendererPlugins = async () => {
|
||||
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] ?? {});
|
||||
|
||||
if (config.enabled) {
|
||||
await forceLoadRendererPlugin(pluginId);
|
||||
@ -115,7 +120,9 @@ export const unloadAllRendererPlugins = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getLoadedRendererPlugin = (id: string): PluginDef<unknown, unknown, unknown> | undefined => {
|
||||
export const getLoadedRendererPlugin = (
|
||||
id: string,
|
||||
): PluginDef<unknown, unknown, unknown> | undefined => {
|
||||
return loadedPluginMap[id];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user