|
@@ -6,7 +6,8 @@ import '../plugin.dart';
|
|
|
import 'runner.dart';
|
|
|
|
|
|
class PluginSandbox {
|
|
|
- final LinkedHashMap<PluginType, PluginBuilder> _pluginMap = LinkedHashMap();
|
|
|
+ final LinkedHashMap<PluginType, PluginBuilder> _pluginBuilders = LinkedHashMap();
|
|
|
+ final Map<PluginType, PluginConfig> _pluginConfigs = <PluginType, PluginConfig>{};
|
|
|
late PluginRunner pluginRunner;
|
|
|
|
|
|
PluginSandbox() {
|
|
@@ -14,7 +15,7 @@ class PluginSandbox {
|
|
|
}
|
|
|
|
|
|
int indexOf(PluginType pluginType) {
|
|
|
- final index = _pluginMap.keys.toList().indexWhere((ty) => ty == pluginType);
|
|
|
+ final index = _pluginBuilders.keys.toList().indexWhere((ty) => ty == pluginType);
|
|
|
if (index == -1) {
|
|
|
throw PlatformException(code: '-1', message: "Can't find the flowy plugin type: $pluginType");
|
|
|
}
|
|
@@ -22,18 +23,24 @@ class PluginSandbox {
|
|
|
}
|
|
|
|
|
|
Plugin buildPlugin(PluginType pluginType, dynamic data) {
|
|
|
- final plugin = _pluginMap[pluginType]!.build(data);
|
|
|
+ final plugin = _pluginBuilders[pluginType]!.build(data);
|
|
|
return plugin;
|
|
|
}
|
|
|
|
|
|
- void registerPlugin(PluginType pluginType, PluginBuilder builder) {
|
|
|
- if (_pluginMap.containsKey(pluginType)) {
|
|
|
+ void registerPlugin(PluginType pluginType, PluginBuilder builder, {PluginConfig? config}) {
|
|
|
+ if (_pluginBuilders.containsKey(pluginType)) {
|
|
|
throw PlatformException(code: '-1', message: "$pluginType was registered before");
|
|
|
}
|
|
|
- _pluginMap[pluginType] = builder;
|
|
|
+ _pluginBuilders[pluginType] = builder;
|
|
|
+
|
|
|
+ if (config != null) {
|
|
|
+ _pluginConfigs[pluginType] = config;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- List<int> get supportPluginTypes => _pluginMap.keys.toList();
|
|
|
+ List<int> get supportPluginTypes => _pluginBuilders.keys.toList();
|
|
|
+
|
|
|
+ List<PluginBuilder> get builders => _pluginBuilders.values.toList();
|
|
|
|
|
|
- List<PluginBuilder> get builders => _pluginMap.values.toList();
|
|
|
+ Map<PluginType, PluginConfig> get pluginConfigs => _pluginConfigs;
|
|
|
}
|