SessionMenu: properly run custom commands via IPC (fix #1708)

This commit is contained in:
Lysec
2026-02-07 11:00:44 +01:00
parent 80f35bf802
commit b56f3bd363
4 changed files with 43 additions and 31 deletions
+1 -1
View File
@@ -1889,4 +1889,4 @@
"poor": "Poor"
}
}
}
}
@@ -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) {
+1 -19
View File
@@ -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
+38 -1
View File
@@ -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"]);
}