From 4bc62cc6eca1489bd6a581a6cf6cee582a59101f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=E1=BB=B3nh=20Thi=E1=BB=87n=20L=E1=BB=99c?= Date: Tue, 12 May 2026 20:29:17 +0700 Subject: [PATCH] feat: consolidate plugin directory management into a single dynamic button (#2400) * feat: add Open Dir button to Plugins settings * feat: consolidate plugin directory management into a single dynamic button --- quickshell/Modules/Settings/PluginsTab.qml | 12 ++++++--- quickshell/Services/PluginService.qml | 31 ++++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/quickshell/Modules/Settings/PluginsTab.qml b/quickshell/Modules/Settings/PluginsTab.qml index 9207a87b..0fccb660 100644 --- a/quickshell/Modules/Settings/PluginsTab.qml +++ b/quickshell/Modules/Settings/PluginsTab.qml @@ -250,11 +250,15 @@ FocusScope { } DankButton { - text: I18n.tr("Create Dir") - iconName: "create_new_folder" + text: PluginService.pluginDirectoryExists ? I18n.tr("Open Dir") : I18n.tr("Create Dir") + iconName: PluginService.pluginDirectoryExists ? "folder_open" : "create_new_folder" onClicked: { - PluginService.createPluginDirectory(); - ToastService.showInfo("Created plugin directory: " + PluginService.pluginDirectory); + if (PluginService.pluginDirectoryExists) { + PluginService.openPluginDirectory(); + } else { + PluginService.createPluginDirectory(); + ToastService.showInfo("Created plugin directory: " + PluginService.pluginDirectory); + } } } } diff --git a/quickshell/Services/PluginService.qml b/quickshell/Services/PluginService.qml index 0e1c556b..7bc476ec 100644 --- a/quickshell/Services/PluginService.qml +++ b/quickshell/Services/PluginService.qml @@ -20,14 +20,9 @@ Singleton { property var pluginLauncherComponents: ({}) property var pluginDesktopComponents: ({}) property var availablePluginsList: [] - property string pluginDirectory: { - var configDir = StandardPaths.writableLocation(StandardPaths.ConfigLocation); - var configDirStr = configDir.toString(); - if (configDirStr.startsWith("file://")) { - configDirStr = configDirStr.substring(7); - } - return configDirStr + "/DankMaterialShell/plugins"; - } + readonly property string pluginDirectory: Paths.strip(Paths.config) + "/plugins" + + property bool pluginDirectoryExists: false property string systemPluginDirectory: "/etc/xdg/quickshell/dms-plugins" property var knownManifests: ({}) @@ -64,10 +59,23 @@ Singleton { onTriggered: root._flushDirtyStates() } + Process { + id: directoryCheckProcess + command: ["test", "-d", root.pluginDirectory] + onExited: (exitCode) => { + root.pluginDirectoryExists = (exitCode === 0); + } + } + + function checkPluginDirectoryExists() { + directoryCheckProcess.running = true; + } + Component.onCompleted: { userWatcher.folder = Paths.toFileUrl(root.pluginDirectory); systemWatcher.folder = Paths.toFileUrl(root.systemPluginDirectory); Qt.callLater(resyncAll); + Qt.callLater(checkPluginDirectoryExists); } FolderListModel { @@ -758,6 +766,7 @@ Singleton { systemWatcher.folder = ""; systemWatcher.folder = systemUrl; resyncDebounce.restart(); + checkPluginDirectoryExists(); } function forceRescanPlugin(pluginId) { @@ -775,6 +784,12 @@ Singleton { function createPluginDirectory() { Quickshell.execDetached(["mkdir", "-p", pluginDirectory]); + Qt.callLater(checkPluginDirectoryExists); + return true; + } + + function openPluginDirectory() { + Qt.openUrlExternally(Paths.toFileUrl(pluginDirectory)); return true; }