mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
feat: remove unnecessary export default for better tree-shaking
This commit is contained in:
@ -40,7 +40,7 @@ export interface DefaultConfig {
|
||||
'plugins': Record<string, unknown>;
|
||||
}
|
||||
|
||||
const defaultConfig: DefaultConfig = {
|
||||
export const defaultConfig: DefaultConfig = {
|
||||
'window-size': {
|
||||
width: 1100,
|
||||
height: 550,
|
||||
@ -74,5 +74,3 @@ const defaultConfig: DefaultConfig = {
|
||||
},
|
||||
'plugins': {},
|
||||
};
|
||||
|
||||
export default defaultConfig;
|
||||
|
||||
@ -1,30 +1,36 @@
|
||||
import { deepmergeCustom } from 'deepmerge-ts';
|
||||
|
||||
import defaultConfig from './defaults';
|
||||
|
||||
import store, { type IStore } from './store';
|
||||
import plugins from './plugins';
|
||||
|
||||
import { store, type IStore } from './store';
|
||||
import { restart } from '@/providers/app-controls';
|
||||
|
||||
import type { defaultConfig } from './defaults';
|
||||
|
||||
const deepmerge = deepmergeCustom({
|
||||
mergeArrays: false,
|
||||
});
|
||||
|
||||
const set = (key: string, value: unknown) => {
|
||||
export { defaultConfig } from './defaults';
|
||||
export * as plugins from './plugins';
|
||||
|
||||
export const set = (key: string, value: unknown) => {
|
||||
store.set(key, value);
|
||||
};
|
||||
const setPartial = (key: string, value: object, defaultValue?: object) => {
|
||||
|
||||
export const setPartial = (
|
||||
key: string,
|
||||
value: object,
|
||||
defaultValue?: object,
|
||||
) => {
|
||||
const newValue = deepmerge(defaultValue ?? {}, store.get(key) ?? {}, value);
|
||||
store.set(key, newValue);
|
||||
};
|
||||
|
||||
function setMenuOption(key: string, value: unknown) {
|
||||
export const setMenuOption = (key: string, value: unknown) => {
|
||||
set(key, value);
|
||||
if (store.get('options.restartOnConfigChanges')) {
|
||||
restart();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// MAGIC OF TYPESCRIPT
|
||||
|
||||
@ -74,18 +80,11 @@ type PathValue<T, K extends string> =
|
||||
? PathValue<T[A], B>
|
||||
: T;
|
||||
|
||||
const get = <Key extends Paths<typeof defaultConfig>>(key: Key) =>
|
||||
export const get = <Key extends Paths<typeof defaultConfig>>(key: Key) =>
|
||||
store.get(key) as PathValue<typeof defaultConfig, typeof key>;
|
||||
|
||||
export default {
|
||||
defaultConfig,
|
||||
get,
|
||||
set,
|
||||
setPartial,
|
||||
setMenuOption,
|
||||
edit: () => store.openInEditor(),
|
||||
watch(cb: Parameters<IStore['onDidAnyChange']>[0]) {
|
||||
store.onDidAnyChange(cb);
|
||||
},
|
||||
plugins,
|
||||
export const edit = () => store.openInEditor();
|
||||
|
||||
export const watch = (cb: Parameters<IStore['onDidAnyChange']>[0]) => {
|
||||
store.onDidAnyChange(cb);
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { allPlugins } from 'virtual:plugins';
|
||||
|
||||
import store from './store';
|
||||
import { store } from './store';
|
||||
|
||||
import { restart } from '@/providers/app-controls';
|
||||
|
||||
@ -68,13 +68,3 @@ export function enable(plugin: string) {
|
||||
export function disable(plugin: string) {
|
||||
setMenuOptions(plugin, { enabled: false }, []);
|
||||
}
|
||||
|
||||
export default {
|
||||
isEnabled,
|
||||
getPlugins,
|
||||
enable,
|
||||
disable,
|
||||
setOptions,
|
||||
setMenuOptions,
|
||||
getOptions,
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import Store from 'electron-store';
|
||||
|
||||
import defaults from './defaults';
|
||||
import { defaultConfig as defaults } from './defaults';
|
||||
|
||||
import { DefaultPresetList, type Preset } from '@/plugins/downloader/types';
|
||||
|
||||
@ -257,7 +257,7 @@ const migrations = {
|
||||
},
|
||||
};
|
||||
|
||||
export default new Store({
|
||||
export const store = new Store({
|
||||
defaults: {
|
||||
...defaults,
|
||||
// README: 'plugin' uses deepmerge to populate the default values, so it is not necessary to include it here
|
||||
|
||||
Reference in New Issue
Block a user