total restructure: isolate functionality to core so web works
This commit is contained in:
56
src/core/PluginManager.js
Normal file
56
src/core/PluginManager.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import PluginRegistry from './PluginRegistry.js'
|
||||
import IpcAdapter from './IpcAdapter.js'
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
return {
|
||||
listPlugins() {
|
||||
return registry.list()
|
||||
},
|
||||
|
||||
getPlugin(pluginId) {
|
||||
return registry.get(pluginId)
|
||||
},
|
||||
|
||||
getAdapter(pluginId, adapterConfig = {}) {
|
||||
const plugin = registry.get(pluginId)
|
||||
|
||||
if (environment === 'electron') {
|
||||
return new IpcAdapter()
|
||||
}
|
||||
|
||||
if (!plugin) {
|
||||
throw new Error(`Plugin not found: ${pluginId}`)
|
||||
}
|
||||
|
||||
return plugin.createAdapter(adapterConfig)
|
||||
},
|
||||
|
||||
setActivePlugin(pluginId, adapterConfig = {}) {
|
||||
activePluginId = pluginId
|
||||
adapter = this.getAdapter(pluginId, adapterConfig)
|
||||
return adapter
|
||||
},
|
||||
|
||||
getActiveAdapter() {
|
||||
return adapter
|
||||
},
|
||||
|
||||
getActivePluginId() {
|
||||
return activePluginId
|
||||
},
|
||||
|
||||
getEnvironment() {
|
||||
return environment
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user