From 03e3d9f435b5e23ae4c43dc30846d18e02526ced Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 28 May 2024 18:03:11 +0100 Subject: [PATCH] messageTray: Add removeAction() method and allow references to actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Internally in gnome-shell it may be useful to modify the actions available on a notification while it’s still visible, but without clearing them all and re-creating them. Allow that by returning the action object when adding it, and adding a `removeAction()` method which takes that object and removes it. Signed-off-by: Philip Withnall Part-of: --- js/ui/messageTray.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 80240b1ee..7c6f2f5db 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -439,6 +439,16 @@ export class Notification extends GObject.Object { }); this._actions.push(action); this.emit('action-added', action); + return action; + } + + removeAction(action) { + const index = this._actions.indexOf(action); + if (index < 0) + throw new Error('Action was already removed previously'); + + this._actions.splice(index, 1); + this.emit('action-removed', action); } clearActions() {