mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
fix: plugin config default value
This commit is contained in:
@ -11,8 +11,8 @@ import { restart } from '@/providers/app-controls';
|
||||
const set = (key: string, value: unknown) => {
|
||||
store.set(key, value);
|
||||
};
|
||||
const setPartial = (key: string, value: object) => {
|
||||
const newValue = deepmerge(store.get(key) ?? {}, value);
|
||||
const setPartial = (key: string, value: object, defaultValue?: object) => {
|
||||
const newValue = deepmerge(defaultValue ?? {}, store.get(key) ?? {}, value);
|
||||
store.set(key, newValue);
|
||||
};
|
||||
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { allPlugins } from 'virtual:plugins';
|
||||
|
||||
import store from './store';
|
||||
|
||||
@ -10,7 +12,7 @@ export function getPlugins() {
|
||||
}
|
||||
|
||||
export function isEnabled(plugin: string) {
|
||||
const pluginConfig = (store.get('plugins') as Record<string, PluginConfig>)[plugin];
|
||||
const pluginConfig = deepmerge(allPlugins[plugin].config ?? { enabled: false }, (store.get('plugins') as Record<string, PluginConfig>)[plugin] ?? {});
|
||||
return pluginConfig !== undefined && pluginConfig.enabled;
|
||||
}
|
||||
|
||||
|
||||
@ -116,12 +116,12 @@ const initHook = (win: BrowserWindow) => {
|
||||
'get-config',
|
||||
(_, id: string) =>
|
||||
deepmerge(
|
||||
allPlugins[id].config,
|
||||
allPlugins[id].config ?? { enabled: false },
|
||||
config.get(`plugins.${id}`) ?? {},
|
||||
) as PluginConfig,
|
||||
);
|
||||
ipcMain.handle('set-config', (_, name: string, obj: object) =>
|
||||
config.setPartial(`plugins.${name}`, obj),
|
||||
config.setPartial(`plugins.${name}`, obj, allPlugins[name].config),
|
||||
);
|
||||
|
||||
config.watch((newValue, oldValue) => {
|
||||
@ -140,8 +140,8 @@ const initHook = (win: BrowserWindow) => {
|
||||
if (!isEqual) {
|
||||
const oldConfig = oldPluginConfigList[id] as PluginConfig;
|
||||
const config = deepmerge(
|
||||
allPlugins[id].config,
|
||||
newPluginConfig,
|
||||
allPlugins[id].config ?? { enabled: false },
|
||||
newPluginConfig ?? {},
|
||||
) as PluginConfig;
|
||||
|
||||
if (config.enabled !== oldConfig?.enabled) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { BrowserWindow, ipcMain } from 'electron';
|
||||
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { mainPlugins } from 'virtual:plugins';
|
||||
import { allPlugins, mainPlugins } from 'virtual:plugins';
|
||||
|
||||
import config from '@/config';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
@ -14,11 +14,11 @@ const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {}
|
||||
const createContext = (id: string, win: BrowserWindow): BackendContext<PluginConfig> => ({
|
||||
getConfig: () =>
|
||||
deepmerge(
|
||||
mainPlugins[id].config,
|
||||
config.get(`plugins.${id}`) ?? { enabled: false },
|
||||
allPlugins[id].config ?? { enabled: false },
|
||||
config.get(`plugins.${id}`) ?? {},
|
||||
) as PluginConfig,
|
||||
setConfig: (newConfig) => {
|
||||
config.setPartial(`plugins.${id}`, newConfig);
|
||||
config.setPartial(`plugins.${id}`, newConfig, allPlugins[id].config);
|
||||
},
|
||||
|
||||
ipc: {
|
||||
@ -102,11 +102,10 @@ export const forceLoadMainPlugin = async (
|
||||
) {
|
||||
loadedPluginMap[id] = plugin;
|
||||
resolve();
|
||||
} else {
|
||||
console.log('[YTMusic]', `Cannot load "${id}" plugin`);
|
||||
reject();
|
||||
}
|
||||
|
||||
console.log('[YTMusic]', `Cannot load "${id}" plugin`);
|
||||
reject();
|
||||
return;
|
||||
} catch (err) {
|
||||
console.error(
|
||||
'[YTMusic]',
|
||||
|
||||
@ -10,9 +10,13 @@ import type { PluginConfig } from '@/types/plugins';
|
||||
|
||||
const menuTemplateMap: Record<string, MenuItemConstructorOptions[]> = {};
|
||||
const createContext = (id: string, win: BrowserWindow): MenuContext<PluginConfig> => ({
|
||||
getConfig: () => config.plugins.getOptions(id),
|
||||
getConfig: () =>
|
||||
deepmerge(
|
||||
allPlugins[id].config ?? { enabled: false },
|
||||
config.get(`plugins.${id}`) ?? {},
|
||||
) as PluginConfig,
|
||||
setConfig: (newConfig) => {
|
||||
config.setPartial(`plugins.${id}`, newConfig);
|
||||
config.setPartial(`plugins.${id}`, newConfig, allPlugins[id].config);
|
||||
},
|
||||
window: win,
|
||||
refresh: () => {
|
||||
@ -44,7 +48,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 ?? { enabled: false }, pluginConfigs[pluginId] ?? {});
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadMenuPlugin(pluginId, win);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { preloadPlugins } from 'virtual:plugins';
|
||||
import { allPlugins, preloadPlugins } from 'virtual:plugins';
|
||||
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
@ -10,9 +10,13 @@ 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),
|
||||
getConfig: () =>
|
||||
deepmerge(
|
||||
allPlugins[id].config ?? { enabled: false },
|
||||
config.get(`plugins.${id}`) ?? {},
|
||||
) as PluginConfig,
|
||||
setConfig: (newConfig) => {
|
||||
config.setPartial(`plugins.${id}`, newConfig);
|
||||
config.setPartial(`plugins.${id}`, newConfig, allPlugins[id].config);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -84,7 +84,6 @@ export default createPlugin({
|
||||
}
|
||||
},
|
||||
async onConfigChange(newConfig) {
|
||||
console.log('Adblocker config changed', newConfig);
|
||||
if (this.mainWindow) {
|
||||
if (newConfig.blocker === blockers.WithBlocklists && !isBlockerEnabled(this.mainWindow.webContents.session)) {
|
||||
await loadAdBlockerEngine(
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { createPlugin } from '@/utils';
|
||||
import {YoutubePlayer} from "@/types/youtube-player";
|
||||
|
||||
import type { YoutubePlayer } from '@/types/youtube-player';
|
||||
|
||||
export type DisableAutoPlayPluginConfig = {
|
||||
enabled: boolean;
|
||||
|
||||
@ -13,7 +13,13 @@ export default createPlugin({
|
||||
name: 'In-App Menu',
|
||||
restartNeeded: true,
|
||||
config: {
|
||||
enabled: false,
|
||||
enabled: (
|
||||
typeof window !== 'undefined' &&
|
||||
!window.navigator?.userAgent?.includes('mac')
|
||||
) || (
|
||||
typeof global !== 'undefined' &&
|
||||
global.process?.platform !== 'darwin'
|
||||
),
|
||||
hideDOMWindowControls: false,
|
||||
} as InAppMenuConfig,
|
||||
stylesheets: [titlebarStyle],
|
||||
|
||||
@ -9,7 +9,7 @@ export default createPlugin({
|
||||
name: 'Navigation',
|
||||
restartNeeded: true,
|
||||
config: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
},
|
||||
stylesheets: [style],
|
||||
renderer() {
|
||||
|
||||
Reference in New Issue
Block a user