2024-11-27 01:02:05 +08:00
|
|
|
|
|
|
|
export interface PluginConfig {
|
|
|
|
name: string;
|
|
|
|
version: string;
|
|
|
|
displayName: string;
|
|
|
|
description?: string;
|
|
|
|
author?: string;
|
|
|
|
enabled: boolean;
|
|
|
|
icon?: string;
|
|
|
|
managePath?: string;
|
|
|
|
configuration?: Configuration;
|
|
|
|
routes: Set<{
|
|
|
|
description?: string;
|
|
|
|
path: string;
|
|
|
|
}>;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-11-16 23:03:55 +08:00
|
|
|
|
|
|
|
export class PluginManager {
|
2024-11-27 01:02:05 +08:00
|
|
|
private configurations: Map<string, PluginConfig> = new Map();
|
2024-11-22 13:13:04 +08:00
|
|
|
|
|
|
|
async loadPlugins() {
|
|
|
|
const pluginDirs = await this.scanPluginDirectory();
|
|
|
|
|
|
|
|
for (const dir of pluginDirs) {
|
|
|
|
try {
|
|
|
|
const config = await import(`@/plugins/${dir}/plugin.config.ts`);
|
|
|
|
const plugin: PluginProps = config.default;
|
|
|
|
|
|
|
|
this.plugins.set(plugin.name, plugin);
|
|
|
|
|
|
|
|
if (plugin.settingsSchema) {
|
|
|
|
this.configurations.set(plugin.name, plugin.settingsSchema);
|
2024-11-16 23:03:55 +08:00
|
|
|
}
|
|
|
|
|
2024-11-22 13:13:04 +08:00
|
|
|
if (plugin.extensions) {
|
|
|
|
Object.entries(plugin.extensions).forEach(([key, value]) => {
|
|
|
|
this.extensions.set(`${plugin.name}.${key}`, value.extension);
|
|
|
|
});
|
2024-11-16 23:03:55 +08:00
|
|
|
}
|
|
|
|
|
2024-11-22 13:13:04 +08:00
|
|
|
if (plugin.hooks?.onInstall) {
|
|
|
|
await plugin.hooks.onInstall({});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Failed to load plugin from directory ${dir}:`, error);
|
|
|
|
}
|
2024-11-16 23:03:55 +08:00
|
|
|
}
|
2024-11-22 13:13:04 +08:00
|
|
|
}
|
2024-11-16 23:03:55 +08:00
|
|
|
|
2024-11-22 13:13:04 +08:00
|
|
|
async getPluginConfig(
|
|
|
|
pluginName: string,
|
2024-11-27 01:02:05 +08:00
|
|
|
): Promise<PluginConfig | undefined> {
|
2024-11-22 13:13:04 +08:00
|
|
|
const dbConfig = await this.fetchConfigFromDB(pluginName);
|
|
|
|
if (dbConfig) {
|
|
|
|
return dbConfig;
|
2024-11-16 23:03:55 +08:00
|
|
|
}
|
2024-11-22 13:13:04 +08:00
|
|
|
return this.configurations.get(pluginName);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async fetchConfigFromDB(pluginName: string) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async scanPluginDirectory(): Promise<string[]> {
|
|
|
|
return [];
|
|
|
|
}
|
2024-11-19 00:20:31 +08:00
|
|
|
}
|