From 47835d14211617be5dc75edc95cb84710d838c34 Mon Sep 17 00:00:00 2001 From: Bryan Martinez-Sanchez <68625150+bryanm1529@users.noreply.github.com> Date: Wed, 28 Jan 2026 21:57:20 -0500 Subject: [PATCH] notifications: add IPC functions for action invocation Adds four new IPC functions to the notifications handler: - getActions: returns actions for a notification by index - invokeDefault: invokes the default (or first) action - invokeDefaultAndDismiss: invokes default action and dismisses - invokeAction: invokes a specific action by notification id Enables external tools and scripts to interact with notification actions programmatically via the existing IPC mechanism. --- Services/Control/IPCService.qml | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Services/Control/IPCService.qml b/Services/Control/IPCService.qml index 48f21322d..c0177565c 100644 --- a/Services/Control/IPCService.qml +++ b/Services/Control/IPCService.qml @@ -22,6 +22,20 @@ Item { // Screen detector passed from shell.qml required property CurrentScreenDetector screenDetector + // Helper for index-based notification lookups in IPC + function _getNotificationByIndex(index: string, funcName: string) { + var idx = index === "" ? 0 : parseInt(index); + if (isNaN(idx)) { + Logger.w("IPC", "Argument to ipc call '" + funcName + "' must be a number"); + return null; + } + if (idx < 0 || idx >= NotificationService.activeList.count) { + Logger.w("IPC", "Notification index out of range: " + idx); + return null; + } + return NotificationService.activeList.get(idx); + } + IpcHandler { target: "bar" function toggle() { @@ -101,6 +115,47 @@ Item { function removeFromHistory(id: string): bool { return NotificationService.removeFromHistory(id); } + + function invokeDefault(index: string): bool { + var notif = root._getNotificationByIndex(index, "notifications invokeDefault"); + if (!notif) return false; + + var actions = JSON.parse(notif.actionsJson || "[]"); + if (actions.length === 0) return false; + + var actionId = actions.find(a => a.identifier === "default")?.identifier ?? actions[0].identifier; + return NotificationService.invokeAction(notif.id, actionId); + } + + function invokeDefaultAndDismiss(index: string): bool { + var notif = root._getNotificationByIndex(index, "notifications invokeDefaultAndDismiss"); + if (!notif) return false; + + var actions = JSON.parse(notif.actionsJson || "[]"); + if (actions.length === 0) { + NotificationService.dismissActiveNotification(notif.id); + return false; + } + + var actionId = actions.find(a => a.identifier === "default")?.identifier ?? actions[0].identifier; + var result = NotificationService.invokeAction(notif.id, actionId); + NotificationService.dismissActiveNotification(notif.id); + return result; + } + + function invokeAction(id: string, actionId: string): bool { + if (!id || !actionId) { + Logger.w("IPC", "Both 'id' and 'actionId' are required for 'notifications invokeAction'"); + return false; + } + return NotificationService.invokeAction(id, actionId); + } + + function getActions(index: string): string { + var notif = root._getNotificationByIndex(index, "notifications getActions"); + if (!notif) return "[]"; + return notif.actionsJson || "[]"; + } } IpcHandler {