mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Merge pull request #1611 from bryanm1529/feat/notification-action-ipc
notifications: add IPC functions for action invocation
This commit is contained in:
@@ -29,6 +29,20 @@ Singleton {
|
||||
Logger.i("IPCService", "Service started");
|
||||
}
|
||||
|
||||
// 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() {
|
||||
@@ -193,6 +207,47 @@ Singleton {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user