1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

Compare commits

...

3 Commits

Author SHA1 Message Date
purian23
53f5240d41 notepad: Fix open/save modals 2026-01-17 15:23:57 -05:00
bbedward
27f0df07af widgets: refresh layout on plugin load
fixes #1414
2026-01-17 12:27:24 -05:00
Jon Rogers
ad940b5884 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
2026-01-17 12:05:04 -05:00
4 changed files with 279 additions and 206 deletions

View File

@@ -966,6 +966,17 @@ Item {
return success ? `PLUGIN_DISABLE_SUCCESS: ${pluginId}` : `PLUGIN_DISABLE_FAILED: ${pluginId}`; 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 { function list(): string {
const plugins = PluginService.getAvailablePlugins(); const plugins = PluginService.getAvailablePlugins();
if (plugins.length === 0) if (plugins.length === 0)

View File

@@ -365,6 +365,7 @@ Item {
onContentItemReady: contentItem => { onContentItemReady: contentItem => {
contentItem.widthChanged.connect(() => layoutTimer.restart()); contentItem.widthChanged.connect(() => layoutTimer.restart());
contentItem.heightChanged.connect(() => layoutTimer.restart()); contentItem.heightChanged.connect(() => layoutTimer.restart());
layoutTimer.restart();
} }
onActiveChanged: layoutTimer.restart() onActiveChanged: layoutTimer.restart()

View File

@@ -1,5 +1,6 @@
pragma ComponentBehavior: Bound pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import Quickshell
import Quickshell.Io import Quickshell.Io
import qs.Common import qs.Common
import qs.Modals.Common import qs.Modals.Common
@@ -51,7 +52,9 @@ Item {
if (tabIndex === NotepadStorageService.currentTabIndex && hasUnsavedChanges()) { if (tabIndex === NotepadStorageService.currentTabIndex && hasUnsavedChanges()) {
root.pendingAction = "close_tab_" + tabIndex; root.pendingAction = "close_tab_" + tabIndex;
root.confirmationDialogOpen = true; root.confirmationDialogOpen = true;
confirmationDialog.open(); confirmationDialogLoader.active = true;
if (confirmationDialogLoader.item)
confirmationDialogLoader.item.open();
} else { } else {
performCloseTab(tabIndex); performCloseTab(tabIndex);
} }
@@ -101,7 +104,9 @@ Item {
root.pendingFileUrl = fileUrl; root.pendingFileUrl = fileUrl;
root.pendingAction = "load_file"; root.pendingAction = "load_file";
root.confirmationDialogOpen = true; root.confirmationDialogOpen = true;
confirmationDialog.open(); confirmationDialogLoader.active = true;
if (confirmationDialogLoader.item)
confirmationDialogLoader.item.open();
} else { } else {
performLoadFromFile(fileUrl); performLoadFromFile(fileUrl);
} }
@@ -170,7 +175,9 @@ Item {
saveToFile(fileUrl); saveToFile(fileUrl);
} else { } else {
root.fileDialogOpen = true; root.fileDialogOpen = true;
saveBrowser.open(); saveBrowserLoader.active = true;
if (saveBrowserLoader.item)
saveBrowserLoader.item.open();
} }
} }
@@ -178,10 +185,14 @@ Item {
if (hasUnsavedChanges()) { if (hasUnsavedChanges()) {
root.pendingAction = "open"; root.pendingAction = "open";
root.confirmationDialogOpen = true; root.confirmationDialogOpen = true;
confirmationDialog.open(); confirmationDialogLoader.active = true;
if (confirmationDialogLoader.item)
confirmationDialogLoader.item.open();
} else { } else {
root.fileDialogOpen = true; root.fileDialogOpen = true;
loadBrowser.open(); loadBrowserLoader.active = true;
if (loadBrowserLoader.item)
loadBrowserLoader.item.open();
} }
} }
@@ -189,7 +200,9 @@ Item {
if (hasUnsavedChanges()) { if (hasUnsavedChanges()) {
root.pendingAction = "new"; root.pendingAction = "new";
root.confirmationDialogOpen = true; root.confirmationDialogOpen = true;
confirmationDialog.open(); confirmationDialogLoader.active = true;
if (confirmationDialogLoader.item)
confirmationDialogLoader.item.open();
} else { } else {
createNewTab(); createNewTab();
} }
@@ -249,238 +262,259 @@ Item {
onLoadFailed: error => {} onLoadFailed: error => {}
} }
FileBrowserModal { LazyLoader {
id: saveBrowser id: saveBrowserLoader
active: false
browserTitle: I18n.tr("Save Notepad File") FileBrowserModal {
browserIcon: "save" id: saveBrowser
browserType: "notepad_save"
fileExtensions: ["*.txt", "*.md", "*.*"]
allowStacking: true
saveMode: true
defaultFileName: {
if (currentTab && currentTab.title && currentTab.title !== "Untitled") {
return currentTab.title;
} else if (currentTab && !currentTab.isTemporary && currentTab.filePath) {
return currentTab.filePath.split('/').pop();
} else {
return "note.txt";
}
}
onFileSelected: path => { browserTitle: I18n.tr("Save Notepad File")
root.fileDialogOpen = false; browserIcon: "save"
const cleanPath = path.toString().replace(/^file:\/\//, ''); browserType: "notepad_save"
const fileName = cleanPath.split('/').pop(); fileExtensions: ["*.txt", "*.md", "*.*"]
const fileUrl = "file://" + cleanPath; allowStacking: true
saveMode: true
root.currentFileName = fileName; defaultFileName: {
root.currentFileUrl = fileUrl; if (currentTab && currentTab.title && currentTab.title !== "Untitled") {
return currentTab.title;
if (currentTab) { } else if (currentTab && !currentTab.isTemporary && currentTab.filePath) {
NotepadStorageService.saveTabAs(NotepadStorageService.currentTabIndex, cleanPath); return currentTab.filePath.split('/').pop();
} else {
return "note.txt";
}
} }
saveToFile(fileUrl); onFileSelected: path => {
root.fileDialogOpen = false;
const cleanPath = path.toString().replace(/^file:\/\//, '');
const fileName = cleanPath.split('/').pop();
const fileUrl = "file://" + cleanPath;
if (root.pendingAction === "new") { root.currentFileName = fileName;
Qt.callLater(() => { root.currentFileUrl = fileUrl;
createNewTab();
});
} else if (root.pendingAction === "open") {
Qt.callLater(() => {
root.fileDialogOpen = true;
loadBrowser.open();
});
} else if (root.pendingAction.startsWith("close_tab_")) {
Qt.callLater(() => {
var tabIndex = parseInt(root.pendingAction.split("_")[2]);
performCloseTab(tabIndex);
});
}
root.pendingAction = "";
close(); if (currentTab) {
} NotepadStorageService.saveTabAs(NotepadStorageService.currentTabIndex, cleanPath);
onDialogClosed: {
root.fileDialogOpen = false;
}
}
FileBrowserModal {
id: loadBrowser
browserTitle: I18n.tr("Open Notepad File")
browserIcon: "folder_open"
browserType: "notepad_load"
fileExtensions: ["*.txt", "*.md", "*.*"]
allowStacking: true
onFileSelected: path => {
root.fileDialogOpen = false;
const cleanPath = path.toString().replace(/^file:\/\//, '');
const fileName = cleanPath.split('/').pop();
const fileUrl = "file://" + cleanPath;
root.currentFileName = fileName;
root.currentFileUrl = fileUrl;
loadFromFile(fileUrl);
close();
}
onDialogClosed: {
root.fileDialogOpen = false;
}
}
DankModal {
id: confirmationDialog
width: 400
height: 180
shouldBeVisible: false
allowStacking: true
onBackgroundClicked: {
close();
root.confirmationDialogOpen = false;
}
content: Component {
FocusScope {
anchors.fill: parent
focus: true
Keys.onEscapePressed: event => {
confirmationDialog.close();
root.confirmationDialogOpen = false;
event.accepted = true;
} }
Column { saveToFile(fileUrl);
anchors.centerIn: parent
width: parent.width - Theme.spacingM * 2
spacing: Theme.spacingM
Row { if (root.pendingAction === "new") {
width: parent.width Qt.callLater(() => {
createNewTab();
});
} else if (root.pendingAction === "open") {
Qt.callLater(() => {
root.fileDialogOpen = true;
loadBrowserLoader.active = true;
if (loadBrowserLoader.item)
loadBrowserLoader.item.open();
});
} else if (root.pendingAction.startsWith("close_tab_")) {
Qt.callLater(() => {
var tabIndex = parseInt(root.pendingAction.split("_")[2]);
performCloseTab(tabIndex);
});
}
root.pendingAction = "";
Column { close();
width: parent.width - 40 }
spacing: Theme.spacingXS
StyledText { onDialogClosed: {
text: I18n.tr("Unsaved Changes") root.fileDialogOpen = false;
font.pixelSize: Theme.fontSizeLarge }
color: Theme.surfaceText }
font.weight: Font.Medium }
}
StyledText { LazyLoader {
text: root.pendingAction === "new" ? I18n.tr("You have unsaved changes. Save before creating a new file?") : root.pendingAction.startsWith("close_tab_") ? I18n.tr("You have unsaved changes. Save before closing this tab?") : root.pendingAction === "load_file" || root.pendingAction === "open" ? I18n.tr("You have unsaved changes. Save before opening a file?") : I18n.tr("You have unsaved changes. Save before continuing?") id: loadBrowserLoader
font.pixelSize: Theme.fontSizeMedium active: false
color: Theme.surfaceTextMedium
width: parent.width
wrapMode: Text.Wrap
}
}
DankActionButton { FileBrowserModal {
iconName: "close" id: loadBrowser
iconSize: Theme.iconSize - 4
iconColor: Theme.surfaceText browserTitle: I18n.tr("Open Notepad File")
onClicked: { browserIcon: "folder_open"
confirmationDialog.close(); browserType: "notepad_load"
root.confirmationDialogOpen = false; fileExtensions: ["*.txt", "*.md", "*.*"]
} allowStacking: true
}
onFileSelected: path => {
root.fileDialogOpen = false;
const cleanPath = path.toString().replace(/^file:\/\//, '');
const fileName = cleanPath.split('/').pop();
const fileUrl = "file://" + cleanPath;
root.currentFileName = fileName;
root.currentFileUrl = fileUrl;
loadFromFile(fileUrl);
close();
}
onDialogClosed: {
root.fileDialogOpen = false;
}
}
}
LazyLoader {
id: confirmationDialogLoader
active: false
DankModal {
id: confirmationDialog
width: 400
height: 180
shouldBeVisible: false
allowStacking: true
onBackgroundClicked: {
close();
root.confirmationDialogOpen = false;
}
content: Component {
FocusScope {
anchors.fill: parent
focus: true
Keys.onEscapePressed: event => {
confirmationDialog.close();
root.confirmationDialogOpen = false;
event.accepted = true;
} }
Item { Column {
width: parent.width anchors.centerIn: parent
height: 40 width: parent.width - Theme.spacingM * 2
spacing: Theme.spacingM
Row { Row {
anchors.right: parent.right width: parent.width
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingM
Rectangle { Column {
width: Math.max(80, discardText.contentWidth + Theme.spacingM * 2) width: parent.width - 40
height: 36 spacing: Theme.spacingXS
radius: Theme.cornerRadius
color: discardArea.containsMouse ? Theme.surfaceTextHover : "transparent"
border.color: Theme.surfaceVariantAlpha
border.width: 1
StyledText { StyledText {
id: discardText text: I18n.tr("Unsaved Changes")
anchors.centerIn: parent font.pixelSize: Theme.fontSizeLarge
text: I18n.tr("Don't Save")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText color: Theme.surfaceText
font.weight: Font.Medium font.weight: Font.Medium
} }
MouseArea { StyledText {
id: discardArea text: root.pendingAction === "new" ? I18n.tr("You have unsaved changes. Save before creating a new file?") : root.pendingAction.startsWith("close_tab_") ? I18n.tr("You have unsaved changes. Save before closing this tab?") : root.pendingAction === "load_file" || root.pendingAction === "open" ? I18n.tr("You have unsaved changes. Save before opening a file?") : I18n.tr("You have unsaved changes. Save before continuing?")
anchors.fill: parent font.pixelSize: Theme.fontSizeMedium
hoverEnabled: true color: Theme.surfaceTextMedium
cursorShape: Qt.PointingHandCursor width: parent.width
onClicked: { wrapMode: Text.Wrap
confirmationDialog.close();
root.confirmationDialogOpen = false;
if (root.pendingAction === "new") {
createNewTab();
} else if (root.pendingAction === "open") {
root.fileDialogOpen = true;
loadBrowser.open();
} else if (root.pendingAction === "load_file") {
performLoadFromFile(root.pendingFileUrl);
} else if (root.pendingAction.startsWith("close_tab_")) {
var tabIndex = parseInt(root.pendingAction.split("_")[2]);
performCloseTab(tabIndex);
}
root.pendingAction = "";
root.pendingFileUrl = "";
}
} }
} }
Rectangle { DankActionButton {
width: Math.max(70, saveAsText.contentWidth + Theme.spacingM * 2) iconName: "close"
height: 36 iconSize: Theme.iconSize - 4
radius: Theme.cornerRadius iconColor: Theme.surfaceText
color: saveAsArea.containsMouse ? Qt.darker(Theme.primary, 1.1) : Theme.primary onClicked: {
confirmationDialog.close();
StyledText { root.confirmationDialogOpen = false;
id: saveAsText
anchors.centerIn: parent
text: I18n.tr("Save")
font.pixelSize: Theme.fontSizeMedium
color: Theme.background
font.weight: Font.Medium
} }
}
}
MouseArea { Item {
id: saveAsArea width: parent.width
anchors.fill: parent height: 40
hoverEnabled: true
cursorShape: Qt.PointingHandCursor Row {
onClicked: { anchors.right: parent.right
confirmationDialog.close(); anchors.verticalCenter: parent.verticalCenter
root.confirmationDialogOpen = false; spacing: Theme.spacingM
root.fileDialogOpen = true;
saveBrowser.open(); Rectangle {
width: Math.max(80, discardText.contentWidth + Theme.spacingM * 2)
height: 36
radius: Theme.cornerRadius
color: discardArea.containsMouse ? Theme.surfaceTextHover : "transparent"
border.color: Theme.surfaceVariantAlpha
border.width: 1
StyledText {
id: discardText
anchors.centerIn: parent
text: I18n.tr("Don't Save")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
font.weight: Font.Medium
}
MouseArea {
id: discardArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
confirmationDialog.close();
root.confirmationDialogOpen = false;
if (root.pendingAction === "new") {
createNewTab();
} else if (root.pendingAction === "open") {
root.fileDialogOpen = true;
loadBrowserLoader.active = true;
if (loadBrowserLoader.item)
loadBrowserLoader.item.open();
} else if (root.pendingAction === "load_file") {
performLoadFromFile(root.pendingFileUrl);
} else if (root.pendingAction.startsWith("close_tab_")) {
var tabIndex = parseInt(root.pendingAction.split("_")[2]);
performCloseTab(tabIndex);
}
root.pendingAction = "";
root.pendingFileUrl = "";
}
} }
} }
Behavior on color { Rectangle {
ColorAnimation { width: Math.max(70, saveAsText.contentWidth + Theme.spacingM * 2)
duration: Theme.shortDuration height: 36
easing.type: Theme.standardEasing radius: Theme.cornerRadius
color: saveAsArea.containsMouse ? Qt.darker(Theme.primary, 1.1) : Theme.primary
StyledText {
id: saveAsText
anchors.centerIn: parent
text: I18n.tr("Save")
font.pixelSize: Theme.fontSizeMedium
color: Theme.background
font.weight: Font.Medium
}
MouseArea {
id: saveAsArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
confirmationDialog.close();
root.confirmationDialogOpen = false;
root.fileDialogOpen = true;
saveBrowserLoader.active = true;
if (saveBrowserLoader.item)
saveBrowserLoader.item.open();
}
}
Behavior on color {
ColorAnimation {
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
} }
} }
} }

View File

@@ -556,6 +556,33 @@ Singleton {
return loadPlugin(pluginId, true); 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) { function savePluginData(pluginId, key, value) {
SettingsData.setPluginSetting(pluginId, key, value); SettingsData.setPluginSetting(pluginId, key, value);
pluginDataChanged(pluginId); pluginDataChanged(pluginId);