mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
feat: rename plugins to clarify context (#1392)
This commit is contained in:
@ -11,7 +11,7 @@ export default defineConfig({
|
||||
const commonConfig: UserConfig = {
|
||||
plugins: [
|
||||
viteResolve({
|
||||
'virtual:MainPlugins': pluginVirtualModuleGenerator('back'),
|
||||
'virtual:MainPlugins': pluginVirtualModuleGenerator('main'),
|
||||
'virtual:MenuPlugins': pluginVirtualModuleGenerator('menu'),
|
||||
}),
|
||||
],
|
||||
@ -85,7 +85,7 @@ export default defineConfig({
|
||||
const commonConfig: UserConfig = {
|
||||
plugins: [
|
||||
viteResolve({
|
||||
'virtual:RendererPlugins': pluginVirtualModuleGenerator('front'),
|
||||
'virtual:RendererPlugins': pluginVirtualModuleGenerator('renderer'),
|
||||
}),
|
||||
],
|
||||
root: './src/',
|
||||
|
||||
@ -207,7 +207,7 @@ Create a folder in `plugins/YOUR-PLUGIN-NAME`:
|
||||
- if you need to manipulate the BrowserWindow, create a file with the following template:
|
||||
|
||||
```typescript
|
||||
// file: back.ts
|
||||
// file: main.ts
|
||||
export default (win: Electron.BrowserWindow, config: ConfigType<'YOUR-PLUGIN-NAME'>) => {
|
||||
// something
|
||||
};
|
||||
@ -229,7 +229,7 @@ const mainPlugins = {
|
||||
- if you need to change the front, create a file with the following template:
|
||||
|
||||
```typescript
|
||||
// file: front.ts
|
||||
// file: renderer.ts
|
||||
export default (config: ConfigType<'YOUR-PLUGIN-NAME'>) => {
|
||||
// This function will be called as a preload script
|
||||
// So you can use front features like `document.querySelector`
|
||||
@ -269,7 +269,7 @@ export default {
|
||||
import path from 'node:path';
|
||||
import style from './style.css';
|
||||
|
||||
// back.ts
|
||||
// main.ts
|
||||
export default (win: Electron.BrowserWindow) => {
|
||||
injectCSS(win.webContents, style);
|
||||
};
|
||||
@ -278,7 +278,7 @@ export default (win: Electron.BrowserWindow) => {
|
||||
- changing the HTML:
|
||||
|
||||
```typescript
|
||||
// front.ts
|
||||
// renderer.ts
|
||||
export default () => {
|
||||
// Remove the login button
|
||||
document.querySelector(".sign-in-link.ytmusic-nav-bar").remove();
|
||||
|
||||
20
src/index.ts
20
src/index.ts
@ -21,9 +21,9 @@ import { restart, setupAppControls } from './providers/app-controls';
|
||||
import { APP_PROTOCOL, handleProtocol, setupProtocolHandler } from './providers/protocol-handler';
|
||||
|
||||
// eslint-disable-next-line import/order
|
||||
import { pluginList as mainPluginList } from 'virtual:MainPlugins';
|
||||
import { mainPlugins } from 'virtual:MainPlugins';
|
||||
|
||||
import { setOptions as pipSetOptions } from './plugins/picture-in-picture/back';
|
||||
import { setOptions as pipSetOptions } from './plugins/picture-in-picture/main';
|
||||
|
||||
import youtubeMusicCSS from './youtube-music.css';
|
||||
|
||||
@ -83,18 +83,18 @@ function onClosed() {
|
||||
mainWindow = null;
|
||||
}
|
||||
|
||||
export const mainPluginNames = Object.keys(mainPluginList);
|
||||
export const mainPluginNames = Object.keys(mainPlugins);
|
||||
|
||||
if (is.windows()) {
|
||||
delete mainPluginList['touchbar'];
|
||||
delete mainPlugins['touchbar'];
|
||||
} else if (is.macOS()) {
|
||||
delete mainPluginList['taskbar-mediacontrol'];
|
||||
delete mainPlugins['taskbar-mediacontrol'];
|
||||
} else {
|
||||
delete mainPluginList['touchbar'];
|
||||
delete mainPluginList['taskbar-mediacontrol'];
|
||||
delete mainPlugins['touchbar'];
|
||||
delete mainPlugins['taskbar-mediacontrol'];
|
||||
}
|
||||
|
||||
ipcMain.handle('get-main-plugin-names', () => Object.keys(mainPluginList));
|
||||
ipcMain.handle('get-main-plugin-names', () => Object.keys(mainPlugins));
|
||||
|
||||
async function loadPlugins(win: BrowserWindow) {
|
||||
injectCSS(win.webContents, youtubeMusicCSS);
|
||||
@ -123,9 +123,9 @@ async function loadPlugins(win: BrowserWindow) {
|
||||
|
||||
for (const [plugin, options] of config.plugins.getEnabled()) {
|
||||
try {
|
||||
if (Object.hasOwn(mainPluginList, plugin)) {
|
||||
if (Object.hasOwn(mainPlugins, plugin)) {
|
||||
console.log('Loaded plugin - ' + plugin);
|
||||
const handler = mainPluginList[plugin as keyof typeof mainPluginList];
|
||||
const handler = mainPlugins[plugin as keyof typeof mainPlugins];
|
||||
if (handler) {
|
||||
await handler(win, options as never);
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import { startingPages } from './providers/extracted-data';
|
||||
import promptOptions from './providers/prompt-options';
|
||||
|
||||
// eslint-disable-next-line import/order
|
||||
import { pluginList as menuList } from 'virtual:MenuPlugins';
|
||||
import { menuPlugins as menuList } from 'virtual:MenuPlugins';
|
||||
|
||||
import { getAvailablePluginNames } from './plugins/utils/main';
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import prompt from 'custom-electron-prompt';
|
||||
|
||||
import { clear, connect, isConnected, registerRefresh } from './back';
|
||||
import { clear, connect, isConnected, registerRefresh } from './main';
|
||||
|
||||
import { setMenuOptions } from '../../config/plugins';
|
||||
import promptOptions from '../../providers/prompt-options';
|
||||
|
||||
@ -32,7 +32,7 @@ import { YoutubeFormatList, type Preset, DefaultPresetList } from './types';
|
||||
|
||||
import style from './style.css';
|
||||
|
||||
import { fetchFromGenius } from '../lyrics-genius/back';
|
||||
import { fetchFromGenius } from '../lyrics-genius/main';
|
||||
import { isEnabled } from '../../config/plugins';
|
||||
import { cleanupName, getImage, SongInfo } from '../../providers/song-info';
|
||||
import { injectCSS } from '../utils/main';
|
||||
@ -1,6 +1,6 @@
|
||||
import { dialog } from 'electron';
|
||||
|
||||
import { downloadPlaylist } from './back';
|
||||
import { downloadPlaylist } from './main';
|
||||
import { defaultMenuDownloadLabel, getFolder } from './utils';
|
||||
import { DefaultPresetList } from './types';
|
||||
import config from './config';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { BrowserWindow, MenuItem } from 'electron';
|
||||
|
||||
import { LyricGeniusType, toggleRomanized } from './back';
|
||||
import { LyricGeniusType, toggleRomanized } from './main';
|
||||
|
||||
import { setOptions } from '../../config/plugins';
|
||||
import { MenuTemplate } from '../../menu';
|
||||
|
||||
@ -2,7 +2,7 @@ import prompt from 'custom-electron-prompt';
|
||||
|
||||
import { BrowserWindow } from 'electron';
|
||||
|
||||
import { setOptions } from './back';
|
||||
import { setOptions } from './main';
|
||||
|
||||
import promptOptions from '../../providers/prompt-options';
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import prompt, { KeybindOptions } from 'custom-electron-prompt';
|
||||
|
||||
import { BrowserWindow, MenuItem } from 'electron';
|
||||
|
||||
import { enabled } from './back';
|
||||
import { enabled } from './main';
|
||||
|
||||
import { setMenuOptions } from '../../config/plugins';
|
||||
import promptOptions from '../../providers/prompt-options';
|
||||
|
||||
@ -2,7 +2,7 @@ import buttonTemplate from './templates/button_template.html?raw';
|
||||
|
||||
import { ElementFromHtml } from '../utils/renderer';
|
||||
|
||||
import { moveVolumeHud as preciseVolumeMoveVolumeHud } from '../precise-volume/front';
|
||||
import { moveVolumeHud as preciseVolumeMoveVolumeHud } from '../precise-volume/renderer';
|
||||
|
||||
import { YoutubePlayer } from '../../types/youtube-player';
|
||||
import { ThumbnailElement } from '../../types/get-player-response';
|
||||
@ -4,7 +4,7 @@ import is from 'electron-is';
|
||||
import config from './config';
|
||||
|
||||
// eslint-disable-next-line import/order
|
||||
import { pluginList as preloadPluginList } from 'virtual:PreloadPlugins';
|
||||
import { preloadPlugins } from 'virtual:PreloadPlugins';
|
||||
|
||||
import type { ConfigType, OneOfDefaultConfigKey } from './config/dynamic';
|
||||
|
||||
@ -19,8 +19,8 @@ export type PluginMapper<Type extends 'renderer' | 'preload' | 'backend'> = {
|
||||
const enabledPluginNameAndOptions = config.plugins.getEnabled();
|
||||
|
||||
enabledPluginNameAndOptions.forEach(async ([plugin, options]) => {
|
||||
if (Object.hasOwn(preloadPluginList, plugin)) {
|
||||
const handler = preloadPluginList[plugin];
|
||||
if (Object.hasOwn(preloadPlugins, plugin)) {
|
||||
const handler = preloadPlugins[plugin];
|
||||
try {
|
||||
await handler?.(options);
|
||||
} catch (error) {
|
||||
|
||||
@ -3,7 +3,7 @@ import { setupSongControls } from './providers/song-controls-front';
|
||||
import { startingPages } from './providers/extracted-data';
|
||||
|
||||
// eslint-disable-next-line import/order
|
||||
import { pluginList as rendererPluginList } from 'virtual:RendererPlugins';
|
||||
import { rendererPlugins } from 'virtual:RendererPlugins';
|
||||
|
||||
const enabledPluginNameAndOptions = window.mainConfig.plugins.getEnabled();
|
||||
|
||||
@ -93,8 +93,8 @@ function onApiLoaded() {
|
||||
|
||||
(() => {
|
||||
enabledPluginNameAndOptions.forEach(async ([pluginName, options]) => {
|
||||
if (Object.hasOwn(rendererPluginList, pluginName)) {
|
||||
const handler = rendererPluginList[pluginName];
|
||||
if (Object.hasOwn(rendererPlugins, pluginName)) {
|
||||
const handler = rendererPlugins[pluginName];
|
||||
try {
|
||||
await handler?.(options as never);
|
||||
} catch (error) {
|
||||
|
||||
8
src/virtual-module.d.ts
vendored
8
src/virtual-module.d.ts
vendored
@ -2,7 +2,7 @@ declare module 'virtual:MainPlugins' {
|
||||
import type { BrowserWindow } from 'electron';
|
||||
import type { ConfigType } from './config/dynamic';
|
||||
|
||||
export const pluginList: Record<string, (win: BrowserWindow, options: ConfigType) => Promise<void>>;
|
||||
export const mainPlugins: Record<string, (win: BrowserWindow, options: ConfigType) => Promise<void>>;
|
||||
}
|
||||
|
||||
declare module 'virtual:MenuPlugins' {
|
||||
@ -10,17 +10,17 @@ declare module 'virtual:MenuPlugins' {
|
||||
import type { MenuTemplate } from './menu';
|
||||
import type { ConfigType } from './config/dynamic';
|
||||
|
||||
export const pluginList: Record<string, (win: BrowserWindow, options: ConfigType, refreshMenu: () => void) => MenuTemplate>;
|
||||
export const menuPlugins: Record<string, (win: BrowserWindow, options: ConfigType, refreshMenu: () => void) => MenuTemplate>;
|
||||
}
|
||||
|
||||
declare module 'virtual:PreloadPlugins' {
|
||||
import type { ConfigType } from './config/dynamic';
|
||||
|
||||
export const pluginList: Record<string, (options: ConfigType) => Promise<void>>;
|
||||
export const preloadPlugins: Record<string, (options: ConfigType) => Promise<void>>;
|
||||
}
|
||||
|
||||
declare module 'virtual:RendererPlugins' {
|
||||
import type { ConfigType } from './config/dynamic';
|
||||
|
||||
export const pluginList: Record<string, (options: ConfigType) => Promise<void>>;
|
||||
export const rendererPlugins: Record<string, (options: ConfigType) => Promise<void>>;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import { globSync } from 'glob';
|
||||
|
||||
const snakeToCamel = (text: string) => text.replace(/-(\w)/g, (_, letter: string) => letter.toUpperCase());
|
||||
|
||||
export const pluginVirtualModuleGenerator = (mode: 'back' | 'preload' | 'front' | 'menu') => {
|
||||
export const pluginVirtualModuleGenerator = (mode: 'main' | 'preload' | 'renderer' | 'menu') => {
|
||||
const srcPath = resolve(__dirname, '..', 'src');
|
||||
|
||||
const plugins = globSync(`${srcPath}/plugins/*`)
|
||||
@ -18,7 +18,7 @@ export const pluginVirtualModuleGenerator = (mode: 'back' | 'preload' | 'front'
|
||||
result += `import ${snakeToCamel(name)}Plugin from "./${relative(resolve(srcPath, '..'), path).replace(/\\/g, '/')}/${mode}";\n`;
|
||||
}
|
||||
|
||||
result += 'export const pluginList = {\n';
|
||||
result += `export const ${mode}Plugins = {\n`;
|
||||
for (const { name } of plugins) {
|
||||
result += ` "${name}": ${snakeToCamel(name)}Plugin,\n`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user