plugin system poc

This commit is contained in:
JellyBrick
2023-11-09 12:43:41 +09:00
parent 06dc0e80f0
commit b6e7e75ae8
5 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1 @@
export * from './types';

View File

@ -0,0 +1,29 @@
import type { BrowserWindow } from 'electron';
export interface Config {
enabled: boolean;
}
export interface Plugin<ConfigType extends Config> {
name: string;
description: string;
config: ConfigType;
}
export interface RendererPlugin<ConfigType extends Config> extends Plugin<ConfigType> {
onEnable: (config: ConfigType) => void;
}
export interface MainPlugin<ConfigType extends Config> extends Plugin<ConfigType> {
onEnable: (window: BrowserWindow, config: ConfigType) => string;
}
export interface PreloadPlugin<ConfigType extends Config> extends Plugin<ConfigType> {
onEnable: (config: ConfigType) => void;
}
export interface MenuPlugin<ConfigType extends Config> extends Plugin<ConfigType> {
onEnable: (config: ConfigType) => void;
}
export const defineConfig = <ConfigType extends Config>(config: ConfigType) => config;

View File

@ -1,3 +1,4 @@
export * from './css';
export * from './fs';
export * from './plugin';
export * from './types';

View File

@ -0,0 +1,7 @@
import type { Config, MainPlugin, MenuPlugin, PreloadPlugin } from '../common';
export const defineMainPlugin = <ConfigType extends Config>(plugin: MainPlugin<ConfigType>) => plugin;
export const definePreloadPlugin = <ConfigType extends Config>(plugin: PreloadPlugin<ConfigType>) => plugin;
export const defineMenuPlugin = <ConfigType extends Config>(plugin: MenuPlugin<ConfigType>) => plugin;

View File

@ -0,0 +1,3 @@
import type { Config, RendererPlugin } from '../common';
export const defineRendererPlugin = <ConfigType extends Config>(plugin: RendererPlugin<ConfigType>) => plugin;