mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
clean code
This commit is contained in:
@ -23,7 +23,7 @@ import { parse } from 'node-html-parser';
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { deepEqual } from 'fast-equals';
|
||||
|
||||
import { mainPlugins } from 'virtual:plugins';
|
||||
import { allPlugins, mainPlugins } from 'virtual:plugins';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
@ -116,7 +116,7 @@ const initHook = (win: BrowserWindow) => {
|
||||
'get-config',
|
||||
(_, id: string) =>
|
||||
deepmerge(
|
||||
mainPlugins[id].config,
|
||||
allPlugins[id].config,
|
||||
config.get(`plugins.${id}`) ?? {},
|
||||
) as PluginConfig,
|
||||
);
|
||||
|
||||
@ -3,11 +3,12 @@ import { BrowserWindow, ipcMain } from 'electron';
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { mainPlugins } from 'virtual:plugins';
|
||||
|
||||
import { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { BackendContext } from '@/types/contexts';
|
||||
import config from '@/config';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import type { BackendContext } from '@/types/contexts';
|
||||
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
|
||||
|
||||
const createContext = (id: string, win: BrowserWindow): BackendContext<PluginConfig> => ({
|
||||
@ -122,7 +123,7 @@ export const loadAllMainPlugins = async (win: BrowserWindow) => {
|
||||
|
||||
export const unloadAllMainPlugins = (win: BrowserWindow) => {
|
||||
for (const id of Object.keys(loadedPluginMap)) {
|
||||
forceUnloadMainPlugin(id as keyof PluginBuilderList, win);
|
||||
forceUnloadMainPlugin(id, win);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { allPlugins } from 'virtual:plugins';
|
||||
import { BrowserWindow, MenuItemConstructorOptions } from 'electron';
|
||||
|
||||
import { MenuContext } from '@/types/contexts';
|
||||
|
||||
import config from '@/config';
|
||||
import { setApplicationMenu } from '@/menu';
|
||||
|
||||
import type { MenuContext } from '@/types/contexts';
|
||||
import type { BrowserWindow, MenuItemConstructorOptions } from 'electron';
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
|
||||
const menuTemplateMap: Record<string, MenuItemConstructorOptions[]> = {};
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { preloadPlugins } from 'virtual:plugins';
|
||||
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { type PreloadContext } from '@/types/contexts';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
import type { PreloadContext } from '@/types/contexts';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
|
||||
const createContext = (id: string): PreloadContext<PluginConfig> => ({
|
||||
getConfig: () => config.plugins.getOptions(id),
|
||||
@ -52,7 +53,7 @@ export const loadAllPreloadPlugins = () => {
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
|
||||
for (const [pluginId, pluginDef] of Object.entries(preloadPlugins)) {
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) as PluginConfig;
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) ;
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadPreloadPlugin(pluginId);
|
||||
@ -66,7 +67,7 @@ export const loadAllPreloadPlugins = () => {
|
||||
|
||||
export const unloadAllPreloadPlugins = () => {
|
||||
for (const id of Object.keys(loadedPluginMap)) {
|
||||
forceUnloadPreloadPlugin(id as keyof PluginBuilderList);
|
||||
forceUnloadPreloadPlugin(id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -2,16 +2,16 @@ import { deepmerge } from 'deepmerge-ts';
|
||||
|
||||
import { rendererPlugins } from 'virtual:plugins';
|
||||
|
||||
import { RendererContext } from '@/types/contexts';
|
||||
|
||||
import { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import type { RendererContext } from '@/types/contexts';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
|
||||
const unregisterStyleMap: Record<string, (() => void)[]> = {};
|
||||
const loadedPluginMap: Record<string, PluginDef<unknown, unknown, unknown>> = {};
|
||||
|
||||
export const createContext = <Config extends PluginConfig>(id: string): RendererContext<Config> => ({
|
||||
getConfig: () => window.mainConfig.plugins.getOptions(id),
|
||||
getConfig: async () => window.ipcRenderer.invoke('get-config', id),
|
||||
setConfig: async (newConfig) => {
|
||||
await window.ipcRenderer.invoke('set-config', id, newConfig);
|
||||
},
|
||||
@ -80,7 +80,7 @@ export const loadAllRendererPlugins = () => {
|
||||
const pluginConfigs = window.mainConfig.plugins.getPlugins();
|
||||
|
||||
for (const [pluginId, pluginDef] of Object.entries(rendererPlugins)) {
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) as PluginConfig;
|
||||
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) ;
|
||||
|
||||
if (config.enabled) {
|
||||
forceLoadRendererPlugin(pluginId);
|
||||
|
||||
@ -11,8 +11,9 @@ import prompt from 'custom-electron-prompt';
|
||||
|
||||
import { allPlugins } from 'virtual:plugins';
|
||||
|
||||
import { restart } from './providers/app-controls';
|
||||
import config from './config';
|
||||
|
||||
import { restart } from './providers/app-controls';
|
||||
import { startingPages } from './providers/extracted-data';
|
||||
import promptOptions from './providers/prompt-options';
|
||||
|
||||
|
||||
@ -5,8 +5,9 @@ import { clear, connect, isConnected, registerRefresh } from './main';
|
||||
import { singleton } from '@/providers/decorators';
|
||||
import promptOptions from '@/providers/prompt-options';
|
||||
import { setMenuOptions } from '@/config/plugins';
|
||||
import { MenuContext } from '@/types/contexts';
|
||||
import { DiscordPluginConfig } from '@/plugins/discord/index';
|
||||
|
||||
import type { MenuContext } from '@/types/contexts';
|
||||
import type { DiscordPluginConfig } from './index';
|
||||
|
||||
import type { MenuTemplate } from '@/menu';
|
||||
|
||||
|
||||
@ -33,12 +33,13 @@ import { isEnabled } from '@/config/plugins';
|
||||
import { cleanupName, getImage, SongInfo } from '@/providers/song-info';
|
||||
import { getNetFetchAsFetch } from '@/plugins/utils/main';
|
||||
import { cache } from '@/providers/decorators';
|
||||
import { BackendContext } from '@/types/contexts';
|
||||
|
||||
import { YoutubeFormatList, type Preset, DefaultPresetList } from '../types';
|
||||
|
||||
import { defaultConfig, type DownloaderPluginConfig } from '../index';
|
||||
|
||||
import type { BackendContext } from '@/types/contexts';
|
||||
|
||||
import type { FormatOptions } from 'youtubei.js/dist/src/types/FormatUtils';
|
||||
import type PlayerErrorMessage from 'youtubei.js/dist/src/parser/classes/PlayerErrorMessage';
|
||||
import type { Playlist } from 'youtubei.js/dist/src/parser/ytmusic';
|
||||
|
||||
@ -2,8 +2,8 @@ import { register } from 'electron-localshortcut';
|
||||
|
||||
import { BrowserWindow, Menu, MenuItem, ipcMain, nativeImage } from 'electron';
|
||||
|
||||
import { BackendContext } from '@/types/contexts';
|
||||
import { InAppMenuConfig } from '@/plugins/in-app-menu/index';
|
||||
import type { BackendContext } from '@/types/contexts';
|
||||
import type { InAppMenuConfig } from './index';
|
||||
|
||||
export const onMainLoad = ({ window: win, ipc: { handle, send } }: BackendContext<InAppMenuConfig>) => {
|
||||
win.on('close', () => {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { RendererContext } from '@/types/contexts';
|
||||
|
||||
import type { RendererContext } from '@/types/contexts';
|
||||
import type { SkipSilencesPluginConfig } from './index';
|
||||
|
||||
let config: SkipSilencesPluginConfig;
|
||||
|
||||
@ -11,10 +11,10 @@ import {
|
||||
|
||||
loadAllPreloadPlugins();
|
||||
|
||||
ipcRenderer.on('plugin:unload', (_, id: keyof PluginBuilderList) => {
|
||||
ipcRenderer.on('plugin:unload', (_, id: string) => {
|
||||
forceUnloadPreloadPlugin(id);
|
||||
});
|
||||
ipcRenderer.on('plugin:enable', (_, id: keyof PluginBuilderList) => {
|
||||
ipcRenderer.on('plugin:enable', (_, id: string) => {
|
||||
forceLoadPreloadPlugin(id);
|
||||
});
|
||||
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { app, BrowserWindow, ipcMain, ipcRenderer } from 'electron';
|
||||
import { app, BrowserWindow, ipcMain } from 'electron';
|
||||
|
||||
import config from '../config';
|
||||
import config from '@/config';
|
||||
|
||||
export const restart = () => {
|
||||
process.type === 'browser' ? restartInternal() : ipcRenderer.send('restart');
|
||||
};
|
||||
export const restart = () => restartInternal();
|
||||
|
||||
export const setupAppControls = () => {
|
||||
ipcMain.on('restart', restart);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { singleton } from './decorators';
|
||||
|
||||
import type { YoutubePlayer } from '../types/youtube-player';
|
||||
import type { GetState } from '../types/datahost-get-state';
|
||||
import type { VideoDataChangeValue } from '../types/player-api-events';
|
||||
import type { YoutubePlayer } from '@/types/youtube-player';
|
||||
import type { GetState } from '@/types/datahost-get-state';
|
||||
import type { VideoDataChangeValue } from '@/types/player-api-events';
|
||||
|
||||
import type { SongInfo } from './song-info';
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@ import { BrowserWindow, ipcMain, nativeImage, net } from 'electron';
|
||||
|
||||
import { cache } from './decorators';
|
||||
|
||||
import config from '../config';
|
||||
import config from '@/config';
|
||||
|
||||
import type { GetPlayerResponse } from '../types/get-player-response';
|
||||
import type { GetPlayerResponse } from '@/types/get-player-response';
|
||||
|
||||
export interface SongInfo {
|
||||
title: string;
|
||||
|
||||
6
src/reset.d.ts
vendored
6
src/reset.d.ts
vendored
@ -1,9 +1,9 @@
|
||||
import '@total-typescript/ts-reset';
|
||||
|
||||
import { ipcRenderer as electronIpcRenderer } from 'electron';
|
||||
import is from 'electron-is';
|
||||
import type { ipcRenderer as electronIpcRenderer } from 'electron';
|
||||
import type is from 'electron-is';
|
||||
|
||||
import config from './config';
|
||||
import type config from './config';
|
||||
|
||||
declare global {
|
||||
interface Compressor {
|
||||
|
||||
@ -2,8 +2,9 @@ import { Menu, nativeImage, Tray } from 'electron';
|
||||
|
||||
import youtubeMusicTrayIcon from '@assets/youtube-music-tray.png?asset&asarUnpack';
|
||||
|
||||
import { restart } from './providers/app-controls';
|
||||
import config from './config';
|
||||
|
||||
import { restart } from './providers/app-controls';
|
||||
import getSongControls from './providers/song-controls';
|
||||
|
||||
import type { MenuTemplate } from './menu';
|
||||
|
||||
Reference in New Issue
Block a user