Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions Modules/Notification/Notification.qml
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,12 @@ Variants {

function runAction(actionId, isDismissed) {
if (!isDismissed) {
if (NotificationService.invokeActionAndSuppressClose(notificationId, actionId))
card.animateOut();
} else {
if (Settings.data.notifications.clearDismissed)
NotificationService.removeFromHistory(notificationId);
card.animateOut();
NotificationService.focusSenderWindow(model.appName);
NotificationService.invokeActionAndSuppressClose(notificationId, actionId);
} else if (Settings.data.notifications.clearDismissed) {
NotificationService.removeFromHistory(notificationId);
}
card.animateOut();
}

Timer {
Expand Down Expand Up @@ -528,11 +527,9 @@ Variants {
var hasDefault = actions.some(function (a) {
return a.identifier === "default";
});
if (hasDefault && NotificationService.invokeActionAndSuppressClose(notificationId, "default")) {
card.animateOut();
if (hasDefault) {
card.runAction("default", false);
} else {
// Without a default action, or if invoking it fails,
// the best fallback is focusing the sender window by app identity.
NotificationService.focusSenderWindow(model.appName);
card.animateOut();
}
Expand Down
18 changes: 9 additions & 9 deletions Modules/Panels/NotificationHistory/NotificationHistoryPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ SmartPanel {
if (actionIndex >= 0) {
var actions = parseActions(item.actionsJson);
if (actionIndex < actions.length) {
if (NotificationService.invokeAction(item.id, actions[actionIndex].identifier))
root.close();
NotificationService.invokeAction(item.id, actions[actionIndex].identifier);
}
} else {
var delegate = notificationColumn.children[focusIndex];
Expand Down Expand Up @@ -792,18 +791,18 @@ SmartPanel {
return;
}

// Without a default action, or if invoking it fails,
// fall back to focusing the sender window by app identity.
// Focus sender window (and invoke default action if available)
var actions = notificationDelegate.actionsList;
var hasDefault = actions.some(function (a) {
return a.identifier === "default";
});
if (hasDefault && NotificationService.invokeAction(notificationDelegate.notificationId, "default")) {
root.close();
if (hasDefault) {
NotificationService.focusSenderWindow(notificationDelegate.appName);
NotificationService.invokeAction(notificationDelegate.notificationId, "default");
} else {
NotificationService.focusSenderWindow(notificationDelegate.appName);
root.close();
}
root.close();
}
onCanceled: {
notificationDelegate.isSwiping = false;
Expand Down Expand Up @@ -961,8 +960,9 @@ SmartPanel {
// Capture modelData in a property to avoid reference errors
property var actionData: modelData
onClicked: {
if (NotificationService.invokeAction(notificationDelegate.notificationId, actionData.identifier))
root.close();
NotificationService.focusSenderWindow(notificationDelegate.appName);
root.close();
NotificationService.invokeAction(notificationDelegate.notificationId, actionData.identifier);
}
}
}
Expand Down
22 changes: 3 additions & 19 deletions Services/System/NotificationService.qml
Original file line number Diff line number Diff line change
Expand Up @@ -923,29 +923,13 @@ Singleton {

function invokeActionAndSuppressClose(id, actionId) {
const notifData = popupState[id];
const notification = notifData?.notification;
const onClosed = notifData?.onClosed;
let restoreClosedHandler = false;

if (notification && onClosed) {
try {
// A successful action may synchronously close the notification. Disconnect
// our close handler first so the popup is only dismissed by the action path.
notification.closed.disconnect(onClosed);
restoreClosedHandler = true;
} catch (e) {}
}

const invoked = invokeAction(id, actionId);

if (!invoked && restoreClosedHandler && notification && onClosed) {
if (notifData && notifData.notification && notifData.onClosed) {
try {
// If invoking the action failed, restore normal close handling for this popup.
notification.closed.connect(onClosed);
notifData.notification.closed.disconnect(notifData.onClosed);
} catch (e) {}
}

return invoked;
return invokeAction(id, actionId);
}

function invokeAction(id, actionId) {
Expand Down