core refactor for runtime support

This commit is contained in:
nicwands
2026-03-23 16:30:38 -04:00
parent eea1cccf16
commit 4d64bc995f
32 changed files with 634 additions and 486 deletions

View File

@@ -1,16 +1,8 @@
import PluginRegistry from './PluginRegistry.js'
import IpcAdapter from './IpcAdapter.js'
import IpcAdapter from './IpcAdapter'
let registry = null
let activePluginId = null
let adapter = null
export default function createPluginManager(environment, plugins = []) {
registry = new PluginRegistry(environment)
for (const plugin of plugins) {
registry.register(plugin)
}
export const createPluginManager = (registry) => {
let activePluginId = null
let adapter = null
return {
listPlugins() {
@@ -24,10 +16,6 @@ export default function createPluginManager(environment, plugins = []) {
getAdapter(pluginId, adapterConfig = {}) {
const plugin = registry.get(pluginId)
if (environment === 'electron') {
return new IpcAdapter()
}
if (!plugin) {
throw new Error(`Plugin not found: ${pluginId}`)
}
@@ -41,6 +29,19 @@ export default function createPluginManager(environment, plugins = []) {
return adapter
},
async testPlugin(pluginId, adapterConfig = {}) {
const plugin = registry.get(pluginId)
if (!plugin) {
throw new Error(`Plugin not found: ${pluginId}`)
}
const adapter = this.getAdapter(pluginId, adapterConfig)
await adapter.init()
return await adapter.testConnection()
},
getActiveAdapter() {
return adapter
},
@@ -48,9 +49,30 @@ export default function createPluginManager(environment, plugins = []) {
getActivePluginId() {
return activePluginId
},
}
}
getEnvironment() {
return environment
// Client for calling manager through IPC
export const createPluginManagerClient = () => {
return {
listPlugins() {
return window.api.pluginManagerCall('listPlugins')
},
getAdapter(pluginId, config) {
return new IpcAdapter(pluginId, config)
},
setActivePlugin(pluginId, adapterConfig) {
return window.api.pluginManagerCall(
'setActivePlugin',
pluginId,
adapterConfig,
)
},
async testPlugin(id, config) {
return window.api.pluginManagerCall('testPlugin', { id, config })
},
}
}