mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
QOL: Move source code under the src directory. (#1318)
This commit is contained in:
63
src/config/plugins.ts
Normal file
63
src/config/plugins.ts
Normal file
@ -0,0 +1,63 @@
|
||||
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,
|
||||
};
|
||||
Reference in New Issue
Block a user