1
0
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:
Jon Rogers
2026-01-17 12:05:04 -05:00
committed by GitHub
parent ec8ab47462
commit ad940b5884
2 changed files with 38 additions and 0 deletions

View File

@@ -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);