From c7ff0dcbf6c9ea9712d668cd33d5c91777936f91 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sat, 11 Nov 2023 22:43:51 +0900 Subject: [PATCH] fix: remove defaults Co-authored-by: Su-Yong --- src/config/defaults.ts | 248 ++----------------------------- src/config/store.ts | 26 ++-- src/plugins/utils/main/plugin.ts | 23 +-- 3 files changed, 38 insertions(+), 259 deletions(-) diff --git a/src/config/defaults.ts b/src/config/defaults.ts index ff49b9cb..f6f0e646 100644 --- a/src/config/defaults.ts +++ b/src/config/defaults.ts @@ -1,22 +1,17 @@ -import { blockers } from '../plugins/adblocker/types'; - -import { DefaultPresetList } from '../plugins/downloader/types'; - export interface WindowSizeConfig { width: number; height: number; } +export interface WindowPositionConfig { + x: number; + y: number; +} + export interface DefaultConfig { - 'window-size': { - width: number; - height: number; - } + 'window-size': WindowSizeConfig; 'window-maximized': boolean; - 'window-position': { - x: number; - y: number; - } + 'window-position': WindowPositionConfig; url: string; options: { tray: boolean; @@ -37,10 +32,11 @@ export interface DefaultConfig { startingPage: string; overrideUserAgent: boolean; themes: string[]; - } + }, + plugins: Record, } -const defaultConfig = { +const defaultConfig: DefaultConfig = { 'window-size': { width: 1100, height: 550, @@ -69,229 +65,9 @@ const defaultConfig = { proxy: '', startingPage: '', overrideUserAgent: false, - themes: [] as string[], - }, - /** please order alphabetically */ - 'plugins': { - 'adblocker': { - enabled: true, - cache: true, - blocker: blockers.InPlayer as string, - additionalBlockLists: [], // Additional list of filters, e.g "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt" - disableDefaultLists: false, - }, - 'album-color-theme': {}, - 'ambient-mode': { - enabled: false, - quality: 50, - buffer: 30, - interpolationTime: 1500, - blur: 100, - size: 100, - opacity: 1, - fullscreen: false, - }, - 'audio-compressor': {}, - 'blur-nav-bar': {}, - 'bypass-age-restrictions': {}, - 'captions-selector': { - enabled: false, - disableCaptions: false, - autoload: false, - lastCaptionsCode: '', - }, - 'compact-sidebar': {}, - 'crossfade': { - enabled: false, - fadeInDuration: 1500, // Ms - fadeOutDuration: 5000, // Ms - secondsBeforeEnd: 10, // S - fadeScaling: 'linear', // 'linear', 'logarithmic' or a positive number in dB - }, - 'disable-autoplay': { - applyOnce: false, - }, - 'discord': { - enabled: false, - autoReconnect: true, // If enabled, will try to reconnect to discord every 5 seconds after disconnecting or failing to connect - activityTimoutEnabled: true, // If enabled, the discord rich presence gets cleared when music paused after the time specified below - activityTimoutTime: 10 * 60 * 1000, // 10 minutes - playOnYouTubeMusic: true, // Add a "Play on YouTube Music" button to rich presence - hideGitHubButton: false, // Disable the "View App On GitHub" button - hideDurationLeft: false, // Hides the start and end time of the song to rich presence - }, - 'downloader': { - enabled: false, - downloadFolder: undefined as string | undefined, // Custom download folder (absolute path) - selectedPreset: 'mp3 (256kbps)', // Selected preset - customPresetSetting: DefaultPresetList['mp3 (256kbps)'], // Presets - skipExisting: false, - playlistMaxItems: undefined as number | undefined, - }, - 'exponential-volume': {}, - 'in-app-menu': { - /** - * true in Windows, false in Linux and macOS (see youtube-music/config/store.ts) - */ - enabled: false, - hideDOMWindowControls: false, - }, - 'last-fm': { - enabled: false, - token: undefined as string | undefined, // Token used for authentication - session_key: undefined as string | undefined, // Session key used for scrobbling - api_root: 'http://ws.audioscrobbler.com/2.0/', - api_key: '04d76faaac8726e60988e14c105d421a', // Api key registered by @semvis123 - secret: 'a5d2a36fdf64819290f6982481eaffa2', - }, - 'lumiastream': {}, - 'lyrics-genius': { - romanizedLyrics: false, - }, - 'navigation': { - enabled: true, - }, - 'no-google-login': {}, - 'notifications': { - enabled: false, - unpauseNotification: false, - urgency: 'normal', // Has effect only on Linux - // the following has effect only on Windows - interactive: true, - toastStyle: 1, // See plugins/notifications/utils for more info - refreshOnPlayPause: false, - trayControls: true, - hideButtonText: false, - }, - 'picture-in-picture': { - 'enabled': false, - 'alwaysOnTop': true, - 'savePosition': true, - 'saveSize': false, - 'hotkey': 'P', - 'pip-position': [10, 10], - 'pip-size': [450, 275], - 'isInPiP': false, - 'useNativePiP': true, - }, - 'playback-speed': {}, - 'precise-volume': { - enabled: false, - steps: 1, // Percentage of volume to change - arrowsShortcut: true, // Enable ArrowUp + ArrowDown local shortcuts - globalShortcuts: { - volumeUp: '', - volumeDown: '', - }, - savedVolume: undefined as number | undefined, // Plugin save volume between session here - }, - 'quality-changer': {}, - 'shortcuts': { - enabled: false, - overrideMediaKeys: false, - global: { - previous: '', - playPause: '', - next: '', - } as Record, - local: { - previous: '', - playPause: '', - next: '', - } as Record, - }, - 'skip-silences': { - onlySkipBeginning: false, - }, - 'sponsorblock': { - enabled: false, - apiURL: 'https://sponsor.ajay.app', - categories: [ - 'sponsor', - 'intro', - 'outro', - 'interaction', - 'selfpromo', - 'music_offtopic', - ], - }, - 'taskbar-mediacontrol': {}, - 'touchbar': {}, - 'tuna-obs': {}, - 'video-toggle': { - enabled: false, - hideVideo: false, - mode: 'custom', - forceHide: false, - align: '', - }, - 'visualizer': { - enabled: false, - type: 'butterchurn', - // Config per visualizer - butterchurn: { - preset: 'martin [shadow harlequins shape code] - fata morgana', - renderingFrequencyInMs: 500, - blendTimeInSeconds: 2.7, - }, - vudio: { - effect: 'lighting', - accuracy: 128, - lighting: { - maxHeight: 160, - maxSize: 12, - lineWidth: 1, - color: '#49f3f7', - shadowBlur: 2, - shadowColor: 'rgba(244,244,244,.5)', - fadeSide: true, - prettify: false, - horizontalAlign: 'center', - verticalAlign: 'middle', - dottify: true, - }, - }, - wave: { - animations: [ - { - type: 'Cubes', - config: { - bottom: true, - count: 30, - cubeHeight: 5, - fillColor: { gradient: ['#FAD961', '#F76B1C'] }, - lineColor: 'rgba(0,0,0,0)', - radius: 20, - }, - }, - { - type: 'Cubes', - config: { - top: true, - count: 12, - cubeHeight: 5, - fillColor: { gradient: ['#FAD961', '#F76B1C'] }, - lineColor: 'rgba(0,0,0,0)', - radius: 10, - }, - }, - { - type: 'Circles', - config: { - lineColor: { - gradient: ['#FAD961', '#FAD961', '#F76B1C'], - rotate: 90, - }, - lineWidth: 4, - diameter: 20, - count: 10, - frequencyBand: 'base', - }, - }, - ], - }, - }, + themes: [], }, + 'plugins': {}, }; export default defaultConfig; diff --git a/src/config/store.ts b/src/config/store.ts index e9271d64..80b6c8ff 100644 --- a/src/config/store.ts +++ b/src/config/store.ts @@ -1,21 +1,15 @@ import Store from 'electron-store'; import Conf from 'conf'; -import is from 'electron-is'; + +import { pluginBuilders } from 'virtual:PluginBuilders'; import defaults from './defaults'; import { DefaultPresetList, type Preset } from '../plugins/downloader/types'; -const getDefaults = () => { - if (is.windows()) { - defaults.plugins['in-app-menu'].enabled = true; - } - return defaults; -}; - -const setDefaultPluginOptions = (store: Conf>, plugin: keyof typeof defaults.plugins) => { +const setDefaultPluginOptions = (store: Conf>, plugin: keyof typeof pluginBuilders) => { if (!store.get(`plugins.${plugin}`)) { - store.set(`plugins.${plugin}`, defaults.plugins[plugin]); + store.set(`plugins.${plugin}`, pluginBuilders[plugin].config); } }; @@ -53,7 +47,7 @@ const migrations = { if (store.get('plugins.notifications.toastStyle') === undefined) { const pluginOptions = store.get('plugins.notifications') || {}; store.set('plugins.notifications', { - ...defaults.plugins.notifications, + ...pluginBuilders.notifications.config, ...pluginOptions, }); } @@ -155,7 +149,15 @@ const migrations = { }; export default new Store({ - defaults: getDefaults(), + defaults: { + ...defaults, + plugins: Object + .entries(pluginBuilders) + .reduce((prev, [id, builder]) => ({ + ...prev, + [id]: (builder as PluginBuilderList[keyof PluginBuilderList]).config, + }), {}), + }, clearInvalidConfig: false, migrations, }); diff --git a/src/plugins/utils/main/plugin.ts b/src/plugins/utils/main/plugin.ts index 4505e7ff..da9aab19 100644 --- a/src/plugins/utils/main/plugin.ts +++ b/src/plugins/utils/main/plugin.ts @@ -1,16 +1,17 @@ import is from 'electron-is'; -import defaultConfig from '../../../config/defaults'; +import { pluginBuilders } from 'virtual:PluginBuilders'; export const getAvailablePluginNames = () => { - return Object.keys(defaultConfig.plugins).filter((name) => { - if (is.windows() && name === 'touchbar') { - return false; - } else if (is.macOS() && name === 'taskbar-mediacontrol') { - return false; - } else if (is.linux() && (name === 'taskbar-mediacontrol' || name === 'touchbar')) { - return false; - } - return true; - }); + return Object.keys(pluginBuilders) + .filter((id) => { + if (is.windows() && id === 'touchbar') { + return false; + } else if (is.macOS() && id === 'taskbar-mediacontrol') { + return false; + } else if (is.linux() && (id === 'taskbar-mediacontrol' || id === 'touchbar')) { + return false; + } + return true; + }); };