Fix invoking actions on notifications

We need to only connect to 'action-invoked' on notification once
when the notification is created. We were accumulating callbacks
otherwise, which resulted, for example, in the Rhythmbox skipping
through multiple tracks when the 'Next' button was hit.

Always be sure to destroy the notification when its source is
destroyed, which is the case when an action is invoked.

Note that in the future, we might not want to destroy the source
for some notifications when an action is invoked. For example,
it makes sense to keep Rhythmbox in the tray while the music is
playing and allow the user to use the controls from the summary
notification too.
This commit is contained in:
Marina Zhurakhinskaya 2010-07-14 17:07:06 -04:00
parent 11c73fcbc3
commit 5695c8b0aa
2 changed files with 8 additions and 4 deletions

View File

@ -80,6 +80,8 @@ Notification.prototype = {
this.emit('dismissed');
}));
source.connect('destroy', Lang.bind(this, this.destroy));
this.actor = new St.Table({ name: 'notification',
reactive: true });
this.actor.connect('style-changed', Lang.bind(this, this._styleChanged));

View File

@ -209,9 +209,13 @@ NotificationDaemon.prototype = {
this._currentNotifications[id] = notification;
notification.connect('dismissed', Lang.bind(this,
function(n) {
n.destroy();
this._emitNotificationClosed(n.id, NotificationClosedReason.DISMISSED);
}));
notification.connect('destroy', Lang.bind(this,
function(n) {
delete this._currentNotifications[id];
}));
notification.connect('action-invoked', Lang.bind(this, this._actionInvoked, source, id));
} else {
// passing in true as the last parameter will clear out extra actors,
// such as actions
@ -221,7 +225,6 @@ NotificationDaemon.prototype = {
if (actions.length) {
for (let i = 0; i < actions.length - 1; i += 2)
notification.addButton(actions[i], actions[i + 1]);
notification.connect('action-invoked', Lang.bind(this, this._actionInvoked, source, id));
}
notification.setUrgent(hints.urgency == Urgency.CRITICAL);
@ -267,12 +270,11 @@ NotificationDaemon.prototype = {
},
_actionInvoked: function(notification, action, source, id) {
this._emitActionInvoked(id, action);
source.destroy();
this._emitActionInvoked(id, action);
},
_emitNotificationClosed: function(id, reason) {
delete this._currentNotifications[id];
DBus.session.emit_signal('/org/freedesktop/Notifications',
'org.freedesktop.Notifications',
'NotificationClosed', 'uu',