feat: remove unnecessary export default for better tree-shaking

This commit is contained in:
JellyBrick
2025-09-06 22:31:02 +09:00
parent 26fa1f85b2
commit c1a06ab955
29 changed files with 53 additions and 81 deletions

View File

@ -40,7 +40,7 @@ export interface DefaultConfig {
'plugins': Record<string, unknown>; 'plugins': Record<string, unknown>;
} }
const defaultConfig: DefaultConfig = { export const defaultConfig: DefaultConfig = {
'window-size': { 'window-size': {
width: 1100, width: 1100,
height: 550, height: 550,
@ -74,5 +74,3 @@ const defaultConfig: DefaultConfig = {
}, },
'plugins': {}, 'plugins': {},
}; };
export default defaultConfig;

View File

@ -1,30 +1,36 @@
import { deepmergeCustom } from 'deepmerge-ts'; import { deepmergeCustom } from 'deepmerge-ts';
import defaultConfig from './defaults'; import { store, type IStore } from './store';
import store, { type IStore } from './store';
import plugins from './plugins';
import { restart } from '@/providers/app-controls'; import { restart } from '@/providers/app-controls';
import type { defaultConfig } from './defaults';
const deepmerge = deepmergeCustom({ const deepmerge = deepmergeCustom({
mergeArrays: false, 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); 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); const newValue = deepmerge(defaultValue ?? {}, store.get(key) ?? {}, value);
store.set(key, newValue); store.set(key, newValue);
}; };
function setMenuOption(key: string, value: unknown) { export const setMenuOption = (key: string, value: unknown) => {
set(key, value); set(key, value);
if (store.get('options.restartOnConfigChanges')) { if (store.get('options.restartOnConfigChanges')) {
restart(); restart();
} }
} };
// MAGIC OF TYPESCRIPT // MAGIC OF TYPESCRIPT
@ -74,18 +80,11 @@ type PathValue<T, K extends string> =
? PathValue<T[A], B> ? PathValue<T[A], B>
: T; : 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>; store.get(key) as PathValue<typeof defaultConfig, typeof key>;
export default { export const edit = () => store.openInEditor();
defaultConfig,
get, export const watch = (cb: Parameters<IStore['onDidAnyChange']>[0]) => {
set,
setPartial,
setMenuOption,
edit: () => store.openInEditor(),
watch(cb: Parameters<IStore['onDidAnyChange']>[0]) {
store.onDidAnyChange(cb); store.onDidAnyChange(cb);
},
plugins,
}; };

View File

@ -1,7 +1,7 @@
import { deepmerge } from 'deepmerge-ts'; import { deepmerge } from 'deepmerge-ts';
import { allPlugins } from 'virtual:plugins'; import { allPlugins } from 'virtual:plugins';
import store from './store'; import { store } from './store';
import { restart } from '@/providers/app-controls'; import { restart } from '@/providers/app-controls';
@ -68,13 +68,3 @@ export function enable(plugin: string) {
export function disable(plugin: string) { export function disable(plugin: string) {
setMenuOptions(plugin, { enabled: false }, []); setMenuOptions(plugin, { enabled: false }, []);
} }
export default {
isEnabled,
getPlugins,
enable,
disable,
setOptions,
setMenuOptions,
getOptions,
};

View File

@ -1,6 +1,6 @@
import Store from 'electron-store'; import Store from 'electron-store';
import defaults from './defaults'; import { defaultConfig as defaults } from './defaults';
import { DefaultPresetList, type Preset } from '@/plugins/downloader/types'; 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: {
...defaults, ...defaults,
// README: 'plugin' uses deepmerge to populate the default values, so it is not necessary to include it here // README: 'plugin' uses deepmerge to populate the default values, so it is not necessary to include it here

View File

@ -29,7 +29,7 @@ import { allPlugins, mainPlugins } from 'virtual:plugins';
import { languageResources } from 'virtual:i18n'; import { languageResources } from 'virtual:i18n';
import config from '@/config'; import * as config from '@/config';
import { refreshMenu, setApplicationMenu } from '@/menu'; import { refreshMenu, setApplicationMenu } from '@/menu';
import { fileExists, injectCSS, injectCSSAsFile } from '@/plugins/utils/main'; import { fileExists, injectCSS, injectCSSAsFile } from '@/plugins/utils/main';

View File

@ -3,7 +3,7 @@ import { type BrowserWindow, ipcMain } from 'electron';
import { deepmerge } from 'deepmerge-ts'; import { deepmerge } from 'deepmerge-ts';
import { allPlugins, mainPlugins } from 'virtual:plugins'; import { allPlugins, mainPlugins } from 'virtual:plugins';
import config from '@/config'; import * as config from '@/config';
import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils'; import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
import { t } from '@/i18n'; import { t } from '@/i18n';

View File

@ -1,7 +1,7 @@
import { deepmerge } from 'deepmerge-ts'; import { deepmerge } from 'deepmerge-ts';
import { allPlugins } from 'virtual:plugins'; import { allPlugins } from 'virtual:plugins';
import config from '@/config'; import * as config from '@/config';
import { setApplicationMenu } from '@/menu'; import { setApplicationMenu } from '@/menu';
import { LoggerPrefix } from '@/utils'; import { LoggerPrefix } from '@/utils';

View File

@ -3,7 +3,7 @@ import { allPlugins, preloadPlugins } from 'virtual:plugins';
import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils'; import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
import config from '@/config'; import * as config from '@/config';
import { t } from '@/i18n'; import { t } from '@/i18n';

View File

@ -15,7 +15,7 @@ import { allPlugins } from 'virtual:plugins';
import { languageResources } from 'virtual:i18n'; import { languageResources } from 'virtual:i18n';
import config from './config'; import * as config from './config';
import { restart } from './providers/app-controls'; import { restart } from './providers/app-controls';
import { startingPages } from './providers/extracted-data'; import { startingPages } from './providers/extracted-data';

View File

@ -1,7 +1,7 @@
import { createRoute, z } from '@hono/zod-openapi'; import { createRoute, z } from '@hono/zod-openapi';
import { ipcMain } from 'electron'; import { ipcMain } from 'electron';
import getSongControls from '@/providers/song-controls'; import { getSongControls } from '@/providers/song-controls';
import { import {
LikeType, LikeType,
type RepeatMode, type RepeatMode,

View File

@ -1,17 +1,15 @@
import net from 'net'; import * as net from 'node:net';
import { SocksClient, type SocksClientOptions } from 'socks'; import { SocksClient, type SocksClientOptions } from 'socks';
import is from 'electron-is'; import is from 'electron-is';
import { createBackend, LoggerPrefix } from '@/utils'; import { createBackend, LoggerPrefix } from '@/utils';
import { type BackendType } from './types'; import * as config from '@/config';
import config from '@/config';
import { type AuthProxyConfig, defaultAuthProxyConfig } from '../config'; import { type AuthProxyConfig, defaultAuthProxyConfig } from '../config';
import type { BackendType } from './types';
import type { BackendContext } from '@/types/contexts'; import type { BackendContext } from '@/types/contexts';
// Parsing the upstream authentication SOCK proxy URL // Parsing the upstream authentication SOCK proxy URL

View File

@ -2,7 +2,7 @@ import { createSignal } from 'solid-js';
import { render } from 'solid-js/web'; import { render } from 'solid-js/web';
import defaultConfig from '@/config/defaults'; import { defaultConfig } from '@/config/defaults';
import { getSongMenu } from '@/providers/dom-elements'; import { getSongMenu } from '@/providers/dom-elements';
import { getSongInfo } from '@/providers/song-info-front'; import { getSongInfo } from '@/providers/song-info-front';
import { t } from '@/i18n'; import { t } from '@/i18n';

View File

@ -7,7 +7,7 @@ import previousIcon from '@assets/media-icons-black/previous.png?asset&asarUnpac
import { notificationImage, secondsToMinutes, ToastStyles } from './utils'; import { notificationImage, secondsToMinutes, ToastStyles } from './utils';
import getSongControls from '@/providers/song-controls'; import { getSongControls } from '@/providers/song-controls';
import { import {
registerCallback, registerCallback,
type SongInfo, type SongInfo,

View File

@ -2,8 +2,8 @@ import { type BrowserWindow, globalShortcut } from 'electron';
import is from 'electron-is'; import is from 'electron-is';
import { register as registerElectronLocalShortcut } from 'electron-localshortcut'; import { register as registerElectronLocalShortcut } from 'electron-localshortcut';
import registerMPRIS from './mpris'; import { registerMPRIS } from './mpris';
import getSongControls from '@/providers/song-controls'; import { getSongControls } from '@/providers/song-controls';
import type { ShortcutMappingType, ShortcutsPluginConfig } from './index'; import type { ShortcutMappingType, ShortcutsPluginConfig } from './index';

View File

@ -19,8 +19,8 @@ import {
type SongInfo, type SongInfo,
SongInfoEvent, SongInfoEvent,
} from '@/providers/song-info'; } from '@/providers/song-info';
import getSongControls from '@/providers/song-controls'; import { getSongControls } from '@/providers/song-controls';
import config from '@/config'; import * as config from '@/config';
import { LoggerPrefix } from '@/utils'; import { LoggerPrefix } from '@/utils';
import type { RepeatMode, VolumeState } from '@/types/datahost-get-state'; import type { RepeatMode, VolumeState } from '@/types/datahost-get-state';
@ -84,7 +84,7 @@ function setupMPRIS() {
return instance; return instance;
} }
function registerMPRIS(win: BrowserWindow) { export function registerMPRIS(win: BrowserWindow) {
const songControls = getSongControls(win); const songControls = getSongControls(win);
const { const {
playPause, playPause,
@ -363,5 +363,3 @@ function registerMPRIS(win: BrowserWindow) {
console.trace(error); console.trace(error);
} }
} }
export default registerMPRIS;

View File

@ -1,4 +1,4 @@
import { z } from 'zod'; import * as z from 'zod';
import { LRC } from '../parsers/lrc'; import { LRC } from '../parsers/lrc';
import { netFetch } from '../renderer'; import { netFetch } from '../renderer';

View File

@ -7,7 +7,7 @@ import nextIcon from '@assets/media-icons-black/next.png?asset&asarUnpack';
import previousIcon from '@assets/media-icons-black/previous.png?asset&asarUnpack'; import previousIcon from '@assets/media-icons-black/previous.png?asset&asarUnpack';
import { createPlugin } from '@/utils'; import { createPlugin } from '@/utils';
import getSongControls from '@/providers/song-controls'; import { getSongControls } from '@/providers/song-controls';
import { import {
registerCallback, registerCallback,
type SongInfo, type SongInfo,

View File

@ -1,7 +1,7 @@
import { nativeImage, type NativeImage, TouchBar } from 'electron'; import { nativeImage, type NativeImage, TouchBar } from 'electron';
import { createPlugin } from '@/utils'; import { createPlugin } from '@/utils';
import getSongControls from '@/providers/song-controls'; import { getSongControls } from '@/providers/song-controls';
import { registerCallback, SongInfoEvent } from '@/providers/song-info'; import { registerCallback, SongInfoEvent } from '@/providers/song-info';
import { t } from '@/i18n'; import { t } from '@/i18n';

View File

@ -6,7 +6,7 @@ import {
} from 'electron'; } from 'electron';
import is from 'electron-is'; import is from 'electron-is';
import config from './config'; import * as config from './config';
import { import {
forceLoadPreloadPlugin, forceLoadPreloadPlugin,

View File

@ -2,7 +2,7 @@ import path from 'node:path';
import { app, BrowserWindow, ipcMain } from 'electron'; import { app, BrowserWindow, ipcMain } from 'electron';
import config from '@/config'; import * as config from '@/config';
export const restart = () => restartInternal(); export const restart = () => restartInternal();

View File

@ -2,5 +2,3 @@ export const getSongMenu = () =>
document.querySelector<HTMLElement>( document.querySelector<HTMLElement>(
'ytmusic-menu-popup-renderer tp-yt-paper-listbox', 'ytmusic-menu-popup-renderer tp-yt-paper-listbox',
); );
export default { getSongMenu };

View File

@ -2,7 +2,7 @@ import path from 'node:path';
import { app, type BrowserWindow } from 'electron'; import { app, type BrowserWindow } from 'electron';
import getSongControls from './song-controls'; import { getSongControls } from './song-controls';
export const APP_PROTOCOL = 'youtubemusic'; export const APP_PROTOCOL = 'youtubemusic';
@ -36,10 +36,3 @@ export function changeProtocolHandler(
) { ) {
protocolHandler = f; protocolHandler = f;
} }
export default {
APP_PROTOCOL,
setupProtocolHandler,
handleProtocol,
changeProtocolHandler,
};

View File

@ -36,7 +36,7 @@ const parseStringFromArgsType = (args: ArgsType<string>) => {
} }
}; };
export default (win: BrowserWindow) => { export const getSongControls = (win: BrowserWindow) => {
return { return {
// Playback // Playback
previous: () => win.webContents.send('ytmd:previous-video'), previous: () => win.webContents.send('ytmd:previous-video'),

View File

@ -189,7 +189,7 @@ export const setupAutoPlayChangedListener = singleton(() => {
}); });
}); });
export default (api: YoutubePlayer) => { export const setupSongInfo = (api: YoutubePlayer) => {
window.ipcRenderer.on('ytmd:setup-time-changed-listener', () => { window.ipcRenderer.on('ytmd:setup-time-changed-listener', () => {
setupTimeChangedListener(); setupTimeChangedListener();
}); });

View File

@ -2,7 +2,7 @@ import { type BrowserWindow, ipcMain, nativeImage, net } from 'electron';
import { Mutex } from 'async-mutex'; import { Mutex } from 'async-mutex';
import config from '@/config'; import * as config from '@/config';
import type { GetPlayerResponse } from '@/types/get-player-response'; import type { GetPlayerResponse } from '@/types/get-player-response';

View File

@ -1,7 +1,7 @@
import i18next from 'i18next'; import i18next from 'i18next';
import { startingPages } from './providers/extracted-data'; import { startingPages } from './providers/extracted-data';
import setupSongInfo from './providers/song-info-front'; import { setupSongInfo } from './providers/song-info-front';
import { import {
createContext, createContext,
forceLoadRendererPlugin, forceLoadRendererPlugin,

2
src/reset.d.ts vendored
View File

@ -3,7 +3,7 @@ import '@total-typescript/ts-reset';
import type { ipcRenderer as electronIpcRenderer } from 'electron'; import type { ipcRenderer as electronIpcRenderer } from 'electron';
import type is from 'electron-is'; import type is from 'electron-is';
import type config from './config'; import type * as config from './config';
import type { VideoDataChanged } from '@/types/video-data-changed'; import type { VideoDataChanged } from '@/types/video-data-changed';
import type { t } from '@/i18n'; import type { t } from '@/i18n';
import type { trustedTypes } from 'trusted-types'; import type { trustedTypes } from 'trusted-types';

View File

@ -4,11 +4,11 @@ import is from 'electron-is';
import defaultTrayIconAsset from '@assets/youtube-music-tray.png?asset&asarUnpack'; import defaultTrayIconAsset from '@assets/youtube-music-tray.png?asset&asarUnpack';
import pausedTrayIconAsset from '@assets/youtube-music-tray-paused.png?asset&asarUnpack'; import pausedTrayIconAsset from '@assets/youtube-music-tray-paused.png?asset&asarUnpack';
import config from './config'; import * as config from './config';
import { restart } from './providers/app-controls'; import { restart } from './providers/app-controls';
import { registerCallback, SongInfoEvent } from './providers/song-info'; import { registerCallback, SongInfoEvent } from './providers/song-info';
import getSongControls from './providers/song-controls'; import { getSongControls } from './providers/song-controls';
import { t } from '@/i18n'; import { t } from '@/i18n';

View File

@ -1,3 +1 @@
export const isTesting = () => process.env.NODE_ENV === 'test'; export const isTesting = () => process.env.NODE_ENV === 'test';
export default { isTesting };