From 539502d7ffad9fd343d71e932af4c9f29fc162ce Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Tue, 14 Apr 2026 23:39:40 +0530 Subject: [PATCH] feat(plugins): wire plugin system into app initialization - Add plugin system bootstrap in renderer.js after sidebar/commands init - Wire status bar DOM insertion, editor API, and IPC adapters - Add plugin-settings:get/set IPC channels to preload allowlist - Add IPC handlers in main process using existing settings store - Fix eqeqeq warning in EventBus.hasHandler Amit Haridas --- src/main.js | 8 +++++++ src/plugins/event-bus.js | 2 +- src/preload.js | 6 ++++- src/renderer.js | 52 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 00d9874..ec367ff 100644 --- a/src/main.js +++ b/src/main.js @@ -283,6 +283,14 @@ const store = { } }; +// Plugin settings IPC handlers +ipcMain.handle('plugin-settings:get', (_event, key) => { + return store.get(key); +}); +ipcMain.handle('plugin-settings:set', (_event, { key, value }) => { + store.set(key, value); +}); + let mainWindow; let currentFile = null; // This will now represent the active tab's file let pandocAvailable = null; // Cache pandoc availability check diff --git a/src/plugins/event-bus.js b/src/plugins/event-bus.js index fe49c77..8e9b315 100644 --- a/src/plugins/event-bus.js +++ b/src/plugins/event-bus.js @@ -36,7 +36,7 @@ class EventBus { hasHandler(event) { const handlers = this.listeners.get(event); - return handlers != null && handlers.length > 0; + return handlers !== undefined && handlers !== null && handlers.length > 0; } } diff --git a/src/preload.js b/src/preload.js index 390d9d9..8217436 100644 --- a/src/preload.js +++ b/src/preload.js @@ -135,7 +135,11 @@ const ALLOWED_SEND_CHANNELS = [ 'export', // Git diff - 'git-diff' + 'git-diff', + + // Plugin settings + 'plugin-settings:get', + 'plugin-settings:set' ]; const ALLOWED_RECEIVE_CHANNELS = [ diff --git a/src/renderer.js b/src/renderer.js index 60188d0..564870d 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -1545,6 +1545,58 @@ document.addEventListener('DOMContentLoaded', () => { } }); + // --- Plugin System --- + const { PluginLoader } = require('./plugins/plugin-loader'); + const { PluginRegistry } = require('./plugins/plugin-registry'); + const { EventBus } = require('./plugins/event-bus'); + const { SettingsStore } = require('./plugins/settings-store'); + const pluginPath = require('path'); + + const pluginEventBus = new EventBus(); + const pluginSettings = new SettingsStore({ + get: (key) => window.electronAPI.invoke('plugin-settings:get', key), + set: (key, value) => window.electronAPI.invoke('plugin-settings:set', { key, value }) + }); + + const statusBarRight = document.querySelector('.status-bar-right'); + const pluginRegistry = new PluginRegistry({ + sidebar: sidebarManager, + commands: commandPalette, + statusBar: { + registerIndicator: (id, opts) => { + const el = document.createElement('span'); + el.className = 'status-item'; + el.id = `plugin-status-${id}`; + if (opts.tooltip) el.title = opts.tooltip; + el.textContent = opts.text || ''; + const sep = document.createElement('span'); + sep.className = 'status-separator'; + sep.textContent = '|'; + if (statusBarRight) { + statusBarRight.appendChild(sep); + statusBarRight.appendChild(el); + } + } + }, + eventBus: pluginEventBus, + settings: pluginSettings, + editor: { + getContent: () => tabManager.getCurrentContent(), + getSelection: () => tabManager.getSelection(), + insertAtCursor: (text) => tabManager.insertAtCursor(text), + onContentChanged: (cb) => pluginEventBus.on('document:changed', cb) + }, + ipc: { + invoke: (ch, data) => window.electronAPI.invoke(ch, data), + on: (ch, cb) => window.electronAPI.on(ch, cb) + } + }); + + const builtInDir = pluginPath.join(__dirname, 'plugins', 'built-in'); + const loader = new PluginLoader([builtInDir]); + const discovered = loader.discoverPlugins(); + discovered.forEach(p => pluginRegistry.register(p)); + // Initialize Zen Mode const ZenModeClass = getZenMode(); const zenMode = new ZenModeClass(tabManager);