mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
feat(plugins): Add toggle support with lazy daemon instantiation (#1407)
Add togglePlugin() function and IPC command to toggle plugin visibility,
particularly for slideout-capable daemon plugins like AI Assistant.
Implementation uses lazy instantiation for daemon plugins:
- Daemons remain uninstantiated on load (respecting lifecycle)
- First toggle() call instantiates the daemon on-demand
- Subsequent toggles use the existing instance
- Prevents duplicate instantiation while supporting toggle functionality
This approach preserves the fix from f9b9d986 (ensure daemon plugins
not instantiated twice) while enabling new toggle capabilities.
Changes:
- Add PluginService.togglePlugin() with lazy instantiation
- Add DMSShellIPC plugin.toggle() command
- Maintains compatibility with existing daemon plugins
This commit is contained in:
@@ -966,6 +966,17 @@ Item {
|
||||
return success ? `PLUGIN_DISABLE_SUCCESS: ${pluginId}` : `PLUGIN_DISABLE_FAILED: ${pluginId}`;
|
||||
}
|
||||
|
||||
function toggle(pluginId: string): string {
|
||||
if (!pluginId)
|
||||
return "ERROR: No plugin ID specified";
|
||||
|
||||
if (!PluginService.availablePlugins[pluginId])
|
||||
return `PLUGIN_NOT_FOUND: ${pluginId}`;
|
||||
|
||||
const success = PluginService.togglePlugin(pluginId);
|
||||
return success ? `PLUGIN_TOGGLE_SUCCESS: ${pluginId}` : `PLUGIN_TOGGLE_FAILED: ${pluginId}`;
|
||||
}
|
||||
|
||||
function list(): string {
|
||||
const plugins = PluginService.getAvailablePlugins();
|
||||
if (plugins.length === 0)
|
||||
|
||||
@@ -556,6 +556,33 @@ Singleton {
|
||||
return loadPlugin(pluginId, true);
|
||||
}
|
||||
|
||||
function togglePlugin(pluginId) {
|
||||
let instance = pluginInstances[pluginId];
|
||||
|
||||
// Lazy instantiate daemon plugins on first toggle
|
||||
// This respects the daemon lifecycle (not instantiated on load)
|
||||
// while supporting toggle functionality for slideout-capable daemons
|
||||
if (!instance && pluginDaemonComponents[pluginId]) {
|
||||
const comp = pluginDaemonComponents[pluginId];
|
||||
const newInstance = comp.createObject(root, {
|
||||
"pluginId": pluginId,
|
||||
"pluginService": root
|
||||
});
|
||||
if (newInstance) {
|
||||
const newInstances = Object.assign({}, pluginInstances);
|
||||
newInstances[pluginId] = newInstance;
|
||||
pluginInstances = newInstances;
|
||||
instance = newInstance;
|
||||
}
|
||||
}
|
||||
|
||||
if (instance && typeof instance.toggle === "function") {
|
||||
instance.toggle();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function savePluginData(pluginId, key, value) {
|
||||
SettingsData.setPluginSetting(pluginId, key, value);
|
||||
pluginDataChanged(pluginId);
|
||||
|
||||
Reference in New Issue
Block a user