mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
@ -163,13 +163,7 @@ const migrations = {
|
||||
export default new Store({
|
||||
defaults: {
|
||||
...defaults,
|
||||
plugins: Object.entries(allPlugins).reduce(
|
||||
(prev, [id, plugin]) => ({
|
||||
...prev,
|
||||
[id]: plugin.config,
|
||||
}),
|
||||
{},
|
||||
),
|
||||
// README: 'plugin' uses deepmerge to populate the default values, so it is not necessary to include it here
|
||||
},
|
||||
clearInvalidConfig: false,
|
||||
migrations,
|
||||
|
||||
@ -163,7 +163,7 @@ const initHook = (win: BrowserWindow) => {
|
||||
const mainPlugin = getAllLoadedMainPlugins()[id];
|
||||
if (mainPlugin) {
|
||||
if (config.enabled && typeof mainPlugin.backend !== 'function') {
|
||||
mainPlugin.backend?.onConfigChange?.(config);
|
||||
mainPlugin.backend?.onConfigChange?.bind(mainPlugin.backend)?.(config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -96,16 +96,18 @@ export const forceLoadMainPlugin = async (
|
||||
loadedPluginMap[id] = plugin;
|
||||
resolve();
|
||||
} catch (err) {
|
||||
console.log(
|
||||
console.error(
|
||||
'[YTMusic]',
|
||||
`Cannot initialize "${id}" plugin: ${String(err)}`,
|
||||
`Cannot initialize "${id}" plugin: `,
|
||||
);
|
||||
console.trace(err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const loadAllMainPlugins = async (win: BrowserWindow) => {
|
||||
console.log('[YTMusic]', 'Loading all plugins');
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
const queue: Promise<void>[] = [];
|
||||
|
||||
@ -118,7 +120,7 @@ export const loadAllMainPlugins = async (win: BrowserWindow) => {
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(queue);
|
||||
await Promise.allSettled(queue);
|
||||
};
|
||||
|
||||
export const unloadAllMainPlugins = (win: BrowserWindow) => {
|
||||
|
||||
@ -35,7 +35,8 @@ export const forceLoadMenuPlugin = async (id: string, win: BrowserWindow) => {
|
||||
|
||||
console.log('[YTMusic]', `Successfully loaded '${id}::menu'`);
|
||||
} catch (err) {
|
||||
console.log('[YTMusic]', `Cannot initialize '${id}::menu': ${String(err)}`);
|
||||
console.error('[YTMusic]', `Cannot initialize '${id}::menu': `);
|
||||
console.trace(err);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -42,10 +42,11 @@ export const forceLoadPreloadPlugin = (id: string) => {
|
||||
|
||||
console.log('[YTMusic]', `"${id}" plugin is loaded`);
|
||||
} catch (err) {
|
||||
console.log(
|
||||
console.error(
|
||||
'[YTMusic]',
|
||||
`Cannot initialize "${id}" plugin: ${String(err)}`,
|
||||
`Cannot initialize "${id}" plugin: `,
|
||||
);
|
||||
console.trace(err);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -28,12 +28,11 @@ interface CaptionsSelectorConfig {
|
||||
lastCaptionsCode: string;
|
||||
}
|
||||
|
||||
const captionsSettingsButton = ElementFromHtml(CaptionsSettingsButtonHTML);
|
||||
|
||||
export default createPlugin<
|
||||
unknown,
|
||||
unknown,
|
||||
{
|
||||
captionsSettingsButton: HTMLElement;
|
||||
captionTrackList: LanguageOptions[] | null;
|
||||
api: YoutubePlayer | null;
|
||||
config: CaptionsSelectorConfig | null;
|
||||
@ -98,6 +97,7 @@ export default createPlugin<
|
||||
},
|
||||
|
||||
renderer: {
|
||||
captionsSettingsButton: ElementFromHtml(CaptionsSettingsButtonHTML),
|
||||
captionTrackList: null,
|
||||
api: null,
|
||||
config: null,
|
||||
@ -133,7 +133,7 @@ export default createPlugin<
|
||||
captionsButtonClickListener() {
|
||||
if (this.config!.disableCaptions) {
|
||||
setTimeout(() => this.api!.unloadModule('captions'), 100);
|
||||
captionsSettingsButton.style.display = 'none';
|
||||
this.captionsSettingsButton.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ export default createPlugin<
|
||||
});
|
||||
}
|
||||
|
||||
captionsSettingsButton.style.display = this.captionTrackList?.length
|
||||
this.captionsSettingsButton.style.display = this.captionTrackList?.length
|
||||
? 'inline-block'
|
||||
: 'none';
|
||||
}, 250);
|
||||
@ -158,20 +158,20 @@ export default createPlugin<
|
||||
this.setConfig = setConfig;
|
||||
},
|
||||
stop() {
|
||||
document.querySelector('.right-controls-buttons')?.removeChild(captionsSettingsButton);
|
||||
document.querySelector('.right-controls-buttons')?.removeChild(this.captionsSettingsButton);
|
||||
document.querySelector<YoutubePlayer & HTMLElement>('#movie_player')?.unloadModule('captions');
|
||||
document.querySelector('video')?.removeEventListener('srcChanged', this.videoChangeListener);
|
||||
captionsSettingsButton.removeEventListener('click', this.captionsButtonClickListener);
|
||||
this.captionsSettingsButton.removeEventListener('click', this.captionsButtonClickListener);
|
||||
},
|
||||
onPlayerApiReady(playerApi) {
|
||||
this.api = playerApi;
|
||||
|
||||
document.querySelector('.right-controls-buttons')?.append(captionsSettingsButton);
|
||||
document.querySelector('.right-controls-buttons')?.append(this.captionsSettingsButton);
|
||||
|
||||
this.captionTrackList = this.api.getOption<LanguageOptions[]>('captions', 'tracklist') ?? [];
|
||||
|
||||
document.querySelector('video')?.addEventListener('srcChanged', this.videoChangeListener);
|
||||
captionsSettingsButton.addEventListener('click', this.captionsButtonClickListener);
|
||||
this.captionsSettingsButton.addEventListener('click', this.captionsButtonClickListener);
|
||||
},
|
||||
onConfigChange(newConfig) {
|
||||
this.config = newConfig;
|
||||
|
||||
@ -36,7 +36,7 @@ import { cache } from '@/providers/decorators';
|
||||
|
||||
import { YoutubeFormatList, type Preset, DefaultPresetList } from '../types';
|
||||
|
||||
import { defaultConfig, type DownloaderPluginConfig } from '../index';
|
||||
import type { DownloaderPluginConfig } from '../index';
|
||||
|
||||
import type { BackendContext } from '@/types/contexts';
|
||||
|
||||
@ -91,7 +91,7 @@ export const getCookieFromWindow = async (win: BrowserWindow) => {
|
||||
.join(';');
|
||||
};
|
||||
|
||||
let config: DownloaderPluginConfig = defaultConfig;
|
||||
let config: DownloaderPluginConfig;
|
||||
|
||||
export const onMainLoad = async ({ window: _win, getConfig, ipc }: BackendContext<DownloaderPluginConfig>) => {
|
||||
win = _win;
|
||||
|
||||
@ -5,12 +5,12 @@ import is from 'electron-is';
|
||||
import { notificationImage } from './utils';
|
||||
import interactive from './interactive';
|
||||
|
||||
import { defaultConfig, type NotificationsPluginConfig } from './index';
|
||||
import registerCallback, { type SongInfo } from '@/providers/song-info';
|
||||
|
||||
import type { NotificationsPluginConfig } from './index';
|
||||
import type { BackendContext } from '@/types/contexts';
|
||||
|
||||
let config: NotificationsPluginConfig = defaultConfig;
|
||||
let config: NotificationsPluginConfig;
|
||||
|
||||
const notify = (info: SongInfo) => {
|
||||
// Send the notification
|
||||
|
||||
@ -78,7 +78,7 @@ function onApiLoaded() {
|
||||
Object.entries(getAllLoadedRendererPlugins())
|
||||
.forEach(([id, plugin]) => {
|
||||
if (typeof plugin.renderer !== 'function') {
|
||||
plugin.renderer?.onPlayerApiReady?.(api!, createContext(id));
|
||||
plugin.renderer?.onPlayerApiReady?.bind(plugin.renderer)?.(api!, createContext(id));
|
||||
}
|
||||
});
|
||||
|
||||
@ -135,7 +135,7 @@ function onApiLoaded() {
|
||||
if (api) {
|
||||
const plugin = getLoadedRendererPlugin(id);
|
||||
if (plugin && typeof plugin.renderer !== 'function') {
|
||||
plugin.renderer?.onPlayerApiReady?.(api, createContext(id));
|
||||
plugin.renderer?.onPlayerApiReady?.bind(plugin.renderer)?.(api, createContext(id));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -146,7 +146,7 @@ function onApiLoaded() {
|
||||
(_event, id: string, newConfig: PluginConfig) => {
|
||||
const plugin = getAllLoadedRendererPlugins()[id];
|
||||
if (plugin && typeof plugin.renderer !== 'function') {
|
||||
plugin.renderer?.onConfigChange?.(newConfig);
|
||||
plugin.renderer?.onConfigChange?.bind(plugin.renderer)?.(newConfig);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@ -42,7 +42,7 @@ export const startPlugin = <Config extends PluginConfig>(id: string, def: Plugin
|
||||
|
||||
try {
|
||||
const start = performance.now();
|
||||
lifecycle(options.context as Config & typeof options.context);
|
||||
lifecycle.bind(def[options.ctx])(options.context as Config & typeof options.context);
|
||||
|
||||
console.log(`[YTM] Executed ${id}::${options.ctx} in ${performance.now() - start} ms`);
|
||||
|
||||
@ -62,7 +62,7 @@ export const stopPlugin = <Config extends PluginConfig>(id: string, def: PluginD
|
||||
|
||||
try {
|
||||
const start = performance.now();
|
||||
stop(options.context as Config & typeof options.context);
|
||||
stop.bind(def[options.ctx])(options.context as Config & typeof options.context);
|
||||
|
||||
console.log(`[YTM] Executed ${id}::${options.ctx} in ${performance.now() - start} ms`);
|
||||
|
||||
|
||||
1
src/virtual-module.d.ts
vendored
1
src/virtual-module.d.ts
vendored
@ -4,7 +4,6 @@ declare module 'virtual:plugins' {
|
||||
type Plugin = PluginDef<unknown, unknown, unknown, PluginConfig>;
|
||||
|
||||
export const mainPlugins: Record<string, Plugin>;
|
||||
export const menuPlugins: Record<string, Plugin>;
|
||||
export const preloadPlugins: Record<string, Plugin>;
|
||||
export const rendererPlugins: Record<string, Plugin>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user