| |
| |
| |
| |
| |
| |
| const fs = require('fs'); |
| const path = require('path'); |
| const os = require('os'); |
|
|
| class PluginManager { |
| constructor() { |
| this.projectFeatures = new Map(); |
|
|
| |
| const { app } = require('electron'); |
|
|
| if (app.isPackaged) { |
| |
| this.pluginsDir = path.join(path.dirname(app.getPath('exe')), 'plugins'); |
| } else { |
| |
| this.pluginsDir = path.join(app.getPath('userData'), 'plugins'); |
| } |
|
|
| |
| if (!fs.existsSync(this.pluginsDir)) { |
| try { |
| fs.mkdirSync(this.pluginsDir, { recursive: true }); |
| console.log(` Created user plugins directory at: ${this.pluginsDir}`); |
| } catch (error) { |
| console.error(` Failed to create user plugins directory:`, error); |
| } |
| } |
| |
| console.log(' Plugin Manager initialized. User plugins path is now:', this.pluginsDir); |
| } |
|
|
| |
| |
| |
| async loadPlugins() { |
| console.log(`[PluginManager] Scanning for manifests in '${this.pluginsDir}'...`); |
| this.projectFeatures.clear(); |
|
|
| if (!fs.existsSync(this.pluginsDir)) { |
| console.warn(`[PluginManager] Plugins directory not found, skipping scan.`); |
| return; |
| } |
|
|
| try { |
| const items = fs.readdirSync(this.pluginsDir, { withFileTypes: true }); |
|
|
| for (const item of items) { |
| if (!item.isDirectory()) continue; |
|
|
| const projectPath = path.join(this.pluginsDir, item.name); |
| const manifestPath = path.join(projectPath, 'chahua.json'); |
|
|
| if (fs.existsSync(manifestPath)) { |
| try { |
| const manifestContent = fs.readFileSync(manifestPath, 'utf8'); |
| const manifestData = JSON.parse(manifestContent); |
|
|
| this.projectFeatures.set(item.name, { |
| name: item.name, |
| displayName: manifestData.name || item.name, |
| path: projectPath, |
| description: manifestData.description || 'No description.', |
| type: manifestData.type || 'unknown', |
| icon: manifestData.icon || '', |
| buttons: manifestData.buttons || [] |
| }); |
| console.log(` -> Registered plugin: ${manifestData.name || item.name}`); |
| } catch (e) { |
| console.error(` -> Error parsing manifest for ${item.name}: ${e.message}`); |
| } |
| } |
| } |
| } catch (error) { |
| console.error(`[PluginManager] Error during manifest scan: ${error.message}`); |
| } |
| } |
|
|
| getProjectFeatures() { |
| return Array.from(this.projectFeatures.values()); |
| } |
|
|
| getPluginStats() { |
| return { |
| projects: this.getProjectFeatures() |
| }; |
| } |
| } |
|
|
| module.exports = PluginManager; |