mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
feat: reimplement inject css, fix types
This commit is contained in:
@ -1,33 +1,32 @@
|
||||
import type { IpcMain, IpcRenderer, BrowserWindow } from 'electron';
|
||||
import type { BrowserWindow } from 'electron';
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
|
||||
export interface BackendContext {
|
||||
export interface BaseContext {
|
||||
getConfig(): PluginConfig;
|
||||
setConfig(conf: Omit<PluginConfig, 'enabled'>): void;
|
||||
}
|
||||
|
||||
export interface BackendContext extends BaseContext {
|
||||
ipc: {
|
||||
send: (event: string, ...args: unknown[]) => void;
|
||||
handle: (event: string, listener: CallableFunction) => void;
|
||||
on: (event: string, listener: CallableFunction) => void;
|
||||
};
|
||||
|
||||
win: BrowserWindow;
|
||||
electron: typeof import('electron');
|
||||
window: BrowserWindow;
|
||||
}
|
||||
|
||||
export interface MenuContext {
|
||||
getConfig(): PluginConfig;
|
||||
setConfig(conf: Omit<PluginConfig, 'enabled'>): void;
|
||||
|
||||
export interface MenuContext extends BaseContext {
|
||||
window: BrowserWindow;
|
||||
refresh: () => Promise<void> | void;
|
||||
}
|
||||
|
||||
export interface PreloadContext {
|
||||
getConfig(): PluginConfig;
|
||||
setConfig(conf: Omit<PluginConfig, 'enabled'>): void;
|
||||
}
|
||||
export interface PreloadContext extends BaseContext {}
|
||||
|
||||
export interface RendererContext {
|
||||
getConfig(): PluginConfig;
|
||||
setConfig(conf: Omit<PluginConfig, 'enabled'>): void;
|
||||
export interface RendererContext extends BaseContext {
|
||||
ipc: {
|
||||
send: (event: string, ...args: unknown[]) => void;
|
||||
invoke: (event: string, ...args: unknown[]) => Promise<unknown>;
|
||||
on: (event: string, listener: CallableFunction) => void;
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import type { YoutubePlayer } from '@/types/youtube-player';
|
||||
|
||||
import type {
|
||||
BackendContext,
|
||||
MenuContext,
|
||||
@ -11,15 +13,17 @@ export type PluginConfig = {
|
||||
enabled: boolean;
|
||||
} & Record<string, unknown>;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type PluginExtra = Record<string, any>;
|
||||
type PluginExtra = Record<string, unknown>;
|
||||
|
||||
type PluginLifecycle<T> =
|
||||
| ((ctx: T) => void | Promise<void>)
|
||||
| ({
|
||||
start?(ctx: T): void | Promise<void>;
|
||||
stop?(ctx: T): void | Promise<void>;
|
||||
} & PluginExtra);
|
||||
export type PluginLifecycleSimple<T> = (ctx: T) => void | Promise<void>;
|
||||
export type PluginLifecycleExtra<T> = {
|
||||
start?: PluginLifecycleSimple<T>;
|
||||
stop?: PluginLifecycleSimple<T>;
|
||||
onConfigChange?: (newConfig: PluginConfig) => void | Promise<void>;
|
||||
onPlayerApiReady?: (playerApi: YoutubePlayer) => void | Promise<void>;
|
||||
} & PluginExtra;
|
||||
|
||||
export type PluginLifecycle<T> = PluginLifecycleSimple<T> | PluginLifecycleExtra<T>;
|
||||
|
||||
export interface PluginDef {
|
||||
name: string;
|
||||
@ -28,11 +32,10 @@ export interface PluginDef {
|
||||
config: PluginConfig;
|
||||
|
||||
menu?: (ctx: MenuContext) => Electron.MenuItemConstructorOptions[];
|
||||
stylesheets?: string[];
|
||||
restartNeeded?: boolean;
|
||||
|
||||
backend?: PluginLifecycle<BackendContext>;
|
||||
preload?: PluginLifecycle<PreloadContext>;
|
||||
renderer?: PluginLifecycle<RendererContext> & {
|
||||
stylesheet?: string;
|
||||
};
|
||||
renderer?: PluginLifecycle<RendererContext>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user