mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
clean code
This commit is contained in:
@ -3,11 +3,12 @@ import { BrowserWindow, ipcMain } from 'electron';
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { mainPlugins } from 'virtual:plugins';
|
||||
|
||||
import { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { BackendContext } from '@/types/contexts';
|
||||
import config from '@/config';
|
||||
import { 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 createContext = (id: string, win: BrowserWindow): BackendContext<PluginConfig> => ({
|
||||
@ -122,7 +123,7 @@ export const loadAllMainPlugins = async (win: BrowserWindow) => {
|
||||
|
||||
export const unloadAllMainPlugins = (win: BrowserWindow) => {
|
||||
for (const id of Object.keys(loadedPluginMap)) {
|
||||
forceUnloadMainPlugin(id as keyof PluginBuilderList, win);
|
||||
forceUnloadMainPlugin(id, win);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { allPlugins } from 'virtual:plugins';
|
||||
import { BrowserWindow, MenuItemConstructorOptions } from 'electron';
|
||||
|
||||
import { MenuContext } from '@/types/contexts';
|
||||
|
||||
import config from '@/config';
|
||||
import { setApplicationMenu } from '@/menu';
|
||||
|
||||
import type { MenuContext } from '@/types/contexts';
|
||||
import type { BrowserWindow, MenuItemConstructorOptions } from 'electron';
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
|
||||
const menuTemplateMap: Record<string, MenuItemConstructorOptions[]> = {};
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { preloadPlugins } from 'virtual:plugins';
|
||||
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { type PreloadContext } from '@/types/contexts';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
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 createContext = (id: string): PreloadContext<PluginConfig> => ({
|
||||
getConfig: () => config.plugins.getOptions(id),
|
||||
@ -52,7 +53,7 @@ export const loadAllPreloadPlugins = () => {
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
|
||||
for (const [pluginId, pluginDef] of Object.entries(preloadPlugins)) {
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) as PluginConfig;
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) ;
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadPreloadPlugin(pluginId);
|
||||
@ -66,7 +67,7 @@ export const loadAllPreloadPlugins = () => {
|
||||
|
||||
export const unloadAllPreloadPlugins = () => {
|
||||
for (const id of Object.keys(loadedPluginMap)) {
|
||||
forceUnloadPreloadPlugin(id as keyof PluginBuilderList);
|
||||
forceUnloadPreloadPlugin(id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -2,16 +2,16 @@ import { deepmerge } from 'deepmerge-ts';
|
||||
|
||||
import { rendererPlugins } from 'virtual:plugins';
|
||||
|
||||
import { RendererContext } from '@/types/contexts';
|
||||
|
||||
import { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
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>> = {};
|
||||
|
||||
export const createContext = <Config extends PluginConfig>(id: string): RendererContext<Config> => ({
|
||||
getConfig: () => window.mainConfig.plugins.getOptions(id),
|
||||
getConfig: async () => window.ipcRenderer.invoke('get-config', id),
|
||||
setConfig: async (newConfig) => {
|
||||
await window.ipcRenderer.invoke('set-config', id, newConfig);
|
||||
},
|
||||
@ -80,7 +80,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] ?? {}) as PluginConfig;
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) ;
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadRendererPlugin(pluginId);
|
||||
|
||||
Reference in New Issue
Block a user