From b56f3bd363e5a582bf0cfab4d00faaf0e5fc5d0b Mon Sep 17 00:00:00 2001 From: Lysec Date: Sat, 7 Feb 2026 11:00:44 +0100 Subject: [PATCH] SessionMenu: properly run custom commands via IPC (fix #1708) --- Assets/Translations/en.json | 2 +- .../Launcher/Providers/SessionProvider.qml | 13 ++----- Modules/Panels/SessionMenu/SessionMenu.qml | 20 +--------- Services/Compositor/CompositorService.qml | 39 ++++++++++++++++++- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index 707a16cb1..1d7fc289e 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -1889,4 +1889,4 @@ "poor": "Poor" } } -} +} \ No newline at end of file diff --git a/Modules/Panels/Launcher/Providers/SessionProvider.qml b/Modules/Panels/Launcher/Providers/SessionProvider.qml index 8752e23f0..1d614c12f 100644 --- a/Modules/Panels/Launcher/Providers/SessionProvider.qml +++ b/Modules/Panels/Launcher/Providers/SessionProvider.qml @@ -141,20 +141,13 @@ Item { launcher.close(); Qt.callLater(() => { - executeAction(action, command); + executeAction(action); }); }; } - function executeAction(action, command) { - // If custom command is defined, execute it - if (command && command.trim() !== "") { - Logger.i("SessionProvider", "Executing custom command for action:", action, "Command:", command); - Quickshell.execDetached(["sh", "-c", command]); - return; - } - - // Otherwise, use default behavior + function executeAction(action) { + // Default behavior or custom command handled by CompositorService switch (action) { case "lock": if (PanelService.lockScreen && !PanelService.lockScreen.active) { diff --git a/Modules/Panels/SessionMenu/SessionMenu.qml b/Modules/Panels/SessionMenu/SessionMenu.qml index 809ee98c1..aea8b0aa3 100644 --- a/Modules/Panels/SessionMenu/SessionMenu.qml +++ b/Modules/Panels/SessionMenu/SessionMenu.qml @@ -211,25 +211,7 @@ SmartPanel { // Stop timer but don't reset other properties yet countdownTimer.stop(); - // Find the option to check for custom command - var option = null; - for (var i = 0; i < powerOptions.length; i++) { - if (powerOptions[i].action === action) { - option = powerOptions[i]; - break; - } - } - - // If custom command is defined, execute it - if (option && option.command && option.command.trim() !== "") { - Logger.i("SessionMenu", "Executing custom command for action:", action, "Command:", option.command); - Quickshell.execDetached(["sh", "-c", option.command]); - cancelTimer(); - root.close(); - return; - } - - // Otherwise, use default behavior + // Use default behavior or custom command handled by CompositorService switch (action) { case "lock": // Access lockScreen via PanelService diff --git a/Services/Compositor/CompositorService.qml b/Services/Compositor/CompositorService.qml index 9c57752ef..817b5b5e1 100644 --- a/Services/Compositor/CompositorService.qml +++ b/Services/Compositor/CompositorService.qml @@ -425,10 +425,35 @@ Singleton { } } + // Session management helper for custom commands + function getCustomCommand(action) { + const powerOptions = Settings.data.sessionMenu.powerOptions || []; + for (let i = 0; i < powerOptions.length; i++) { + const option = powerOptions[i]; + if (option.action === action && option.enabled && option.command && option.command.trim() !== "") { + return option.command.trim(); + } + } + return ""; + } + + function executeSessionAction(action, defaultCommand) { + const customCommand = getCustomCommand(action); + if (customCommand) { + Logger.i("Compositor", `Executing custom command for action: ${action} Command: ${customCommand}`); + Quickshell.execDetached(["sh", "-c", customCommand]); + return true; + } + return false; + } + // Session management function logout() { + Logger.i("Compositor", "Logout requested"); + if (executeSessionAction("logout")) + return; + if (backend && backend.logout) { - Logger.i("Compositor", "Logout requested"); backend.logout(); } else { Logger.w("Compositor", "No backend available for logout"); @@ -437,6 +462,9 @@ Singleton { function shutdown() { Logger.i("Compositor", "Shutdown requested"); + if (executeSessionAction("shutdown")) + return; + HooksService.executeSessionHook("shutdown", () => { Quickshell.execDetached(["sh", "-c", "systemctl poweroff || loginctl poweroff"]); }); @@ -444,6 +472,9 @@ Singleton { function reboot() { Logger.i("Compositor", "Reboot requested"); + if (executeSessionAction("reboot")) + return; + HooksService.executeSessionHook("reboot", () => { Quickshell.execDetached(["sh", "-c", "systemctl reboot || loginctl reboot"]); }); @@ -451,11 +482,17 @@ Singleton { function suspend() { Logger.i("Compositor", "Suspend requested"); + if (executeSessionAction("suspend")) + return; + Quickshell.execDetached(["sh", "-c", "systemctl suspend || loginctl suspend"]); } function hibernate() { Logger.i("Compositor", "Hibernate requested"); + if (executeSessionAction("hibernate")) + return; + Quickshell.execDetached(["sh", "-c", "systemctl hibernate || loginctl hibernate"]); }