core refactor for runtime support
This commit is contained in:
@@ -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 })
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user