mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import store from './store';
|
|
import defaultConfig from './defaults';
|
|
|
|
import { restart } from '../providers/app-controls';
|
|
import { Entries } from '../utils/type-utils';
|
|
|
|
interface Plugin {
|
|
enabled: boolean;
|
|
}
|
|
|
|
type DefaultPluginsConfig = typeof defaultConfig.plugins;
|
|
|
|
export function getEnabled() {
|
|
const plugins = store.get('plugins') as DefaultPluginsConfig;
|
|
return (Object.entries(plugins) as Entries<DefaultPluginsConfig>).filter(([plugin]) =>
|
|
isEnabled(plugin),
|
|
);
|
|
}
|
|
|
|
export function isEnabled(plugin: string) {
|
|
const pluginConfig = (store.get('plugins') as Record<string, Plugin>)[plugin];
|
|
return pluginConfig !== undefined && pluginConfig.enabled;
|
|
}
|
|
|
|
export function setOptions<T>(plugin: string, options: T) {
|
|
const plugins = store.get('plugins') as Record<string, T>;
|
|
store.set('plugins', {
|
|
...plugins,
|
|
[plugin]: {
|
|
...plugins[plugin],
|
|
...options,
|
|
},
|
|
});
|
|
}
|
|
|
|
export function setMenuOptions<T>(plugin: string, options: T) {
|
|
setOptions(plugin, options);
|
|
if (store.get('options.restartOnConfigChanges')) {
|
|
restart();
|
|
}
|
|
}
|
|
|
|
export function getOptions<T>(plugin: string): T {
|
|
return (store.get('plugins') as Record<string, T>)[plugin];
|
|
}
|
|
|
|
export function enable(plugin: string) {
|
|
setMenuOptions(plugin, { enabled: true });
|
|
}
|
|
|
|
export function disable(plugin: string) {
|
|
setMenuOptions(plugin, { enabled: false });
|
|
}
|
|
|
|
export default {
|
|
isEnabled,
|
|
getEnabled,
|
|
enable,
|
|
disable,
|
|
setOptions,
|
|
setMenuOptions,
|
|
getOptions,
|
|
};
|