import type { MusicPlayer } from '@/types/music-player'; import type { BackendContext, MenuContext, PreloadContext, RendererContext, } from './contexts'; type Author = string; export type PluginConfig = { enabled: boolean; }; export type PluginLifecycleSimple = ( this: This, ctx: Context, ) => void | Promise; export type PluginLifecycleExtra = This & { start?: PluginLifecycleSimple; stop?: PluginLifecycleSimple; onConfigChange?: (this: This, newConfig: Config) => void | Promise; }; export type RendererPluginLifecycleExtra = This & PluginLifecycleExtra & { onPlayerApiReady?: ( this: This, playerApi: MusicPlayer, context: Context, ) => void | Promise; }; export type PluginLifecycle = | PluginLifecycleSimple | PluginLifecycleExtra; export type RendererPluginLifecycle = | PluginLifecycleSimple | RendererPluginLifecycleExtra; export enum Platform { Windows = 1 << 0, macOS = 1 << 1, Linux = 1 << 2, Freebsd = 1 << 3, } export interface PluginDef< BackendProperties, PreloadProperties, RendererProperties, Config extends PluginConfig = PluginConfig, > { name: () => string; authors?: Author[]; description?: () => string; addedVersion?: string; config?: Config; platform?: Platform; menu?: ( ctx: MenuContext, ) => | Promise | Electron.MenuItemConstructorOptions[]; stylesheets?: string[]; restartNeeded?: boolean; backend?: { [Key in keyof BackendProperties]: BackendProperties[Key]; } & PluginLifecycle, BackendProperties>; preload?: { [Key in keyof PreloadProperties]: PreloadProperties[Key]; } & PluginLifecycle, PreloadProperties>; renderer?: { [Key in keyof RendererProperties]: RendererProperties[Key]; } & RendererPluginLifecycle< Config, RendererContext, RendererProperties >; }