mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 02:51:46 +00:00
feat: migrate to new plugin api
Co-authored-by: Su-Yong <simssy2205@gmail.com>
This commit is contained in:
@ -8,11 +8,13 @@ export type PluginBaseConfig = {
|
||||
};
|
||||
export type BasePlugin<Config extends PluginBaseConfig> = {
|
||||
onLoad?: () => void;
|
||||
onUnload?: () => void;
|
||||
onConfigChange?: (newConfig: Config) => void;
|
||||
}
|
||||
export type RendererPlugin<Config extends PluginBaseConfig> = BasePlugin<Config>;
|
||||
export type MainPlugin<Config extends PluginBaseConfig> = Omit<BasePlugin<Config>, 'onLoad'> & {
|
||||
export type MainPlugin<Config extends PluginBaseConfig> = Omit<BasePlugin<Config>, 'onLoad' | 'onUnload'> & {
|
||||
onLoad?: (window: BrowserWindow) => void;
|
||||
onUnload?: (window: BrowserWindow) => void;
|
||||
};
|
||||
export type PreloadPlugin<Config extends PluginBaseConfig> = BasePlugin<Config>;
|
||||
|
||||
@ -30,6 +32,7 @@ export type PluginContext<Config extends PluginBaseConfig = PluginBaseConfig> =
|
||||
export type MainPluginContext<Config extends PluginBaseConfig = PluginBaseConfig> = PluginContext<Config> & {
|
||||
send: (event: string, ...args: unknown[]) => void;
|
||||
handle: <Arguments extends unknown[], Return>(event: string, listener: (...args: Arguments) => Promisable<Return>) => void;
|
||||
on: <Arguments extends unknown[]>(event: string, listener: (...args: Arguments) => Promisable<void>) => void;
|
||||
};
|
||||
export type RendererPluginContext<Config extends PluginBaseConfig = PluginBaseConfig> = PluginContext<Config> & {
|
||||
invoke: <Return>(event: string, ...args: unknown[]) => Promise<Return>;
|
||||
@ -37,6 +40,8 @@ export type RendererPluginContext<Config extends PluginBaseConfig = PluginBaseCo
|
||||
};
|
||||
export type MenuPluginContext<Config extends PluginBaseConfig = PluginBaseConfig> = PluginContext<Config> & {
|
||||
window: BrowserWindow;
|
||||
|
||||
refresh: () => void;
|
||||
};
|
||||
|
||||
export type RendererPluginFactory<Config extends PluginBaseConfig> = (context: RendererPluginContext<Config>) => Promisable<RendererPlugin<Config>>;
|
||||
@ -57,6 +62,7 @@ export type PluginBuilder<ID extends string, Config extends PluginBaseConfig> =
|
||||
};
|
||||
export type PluginBuilderOptions<Config extends PluginBaseConfig = PluginBaseConfig> = {
|
||||
name?: string;
|
||||
restartNeeded: boolean;
|
||||
|
||||
config: Config;
|
||||
styles?: string[];
|
||||
|
||||
21
src/plugins/utils/main/fetch.ts
Normal file
21
src/plugins/utils/main/fetch.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { net } from 'electron';
|
||||
|
||||
export const getNetFetchAsFetch = () => (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url =
|
||||
typeof input === 'string'
|
||||
? new URL(input)
|
||||
: input instanceof URL
|
||||
? input
|
||||
: new URL(input.url);
|
||||
|
||||
if (init?.body && !init.method) {
|
||||
init.method = 'POST';
|
||||
}
|
||||
|
||||
const request = new Request(
|
||||
url,
|
||||
input instanceof Request ? input : undefined,
|
||||
);
|
||||
|
||||
return net.fetch(request, init);
|
||||
}) as typeof fetch;
|
||||
@ -2,3 +2,4 @@ export * from './css';
|
||||
export * from './fs';
|
||||
export * from './plugin';
|
||||
export * from './types';
|
||||
export * from './fetch';
|
||||
|
||||
Reference in New Issue
Block a user