Replace direct call to MessageTray::showNotification() with 'notify' signal in Source::notify()
This decouples Source and MessageTray, so Source doesn't need to know how MessageTray works.
This commit is contained in:
parent
863f9f285b
commit
ee75355e71
@ -59,6 +59,7 @@ function Source(id, createIcon) {
|
|||||||
Source.prototype = {
|
Source.prototype = {
|
||||||
_init: function(id, createIcon) {
|
_init: function(id, createIcon) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.text = null;
|
||||||
if (createIcon)
|
if (createIcon)
|
||||||
this.createIcon = createIcon;
|
this.createIcon = createIcon;
|
||||||
},
|
},
|
||||||
@ -70,7 +71,8 @@ Source.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
notify: function(text) {
|
notify: function(text) {
|
||||||
Main.messageTray.showNotification(new Notification(this.createIcon(ICON_SIZE), text));
|
this.text = text;
|
||||||
|
this.emit('notify');
|
||||||
},
|
},
|
||||||
|
|
||||||
clicked: function() {
|
clicked: function() {
|
||||||
@ -145,6 +147,8 @@ MessageTray.prototype = {
|
|||||||
this._icons[source.id] = iconBox;
|
this._icons[source.id] = iconBox;
|
||||||
this._sources[source.id] = source;
|
this._sources[source.id] = source;
|
||||||
|
|
||||||
|
source.connect('notify', Lang.bind(this, this._onNotify));
|
||||||
|
|
||||||
iconBox.connect('button-release-event', Lang.bind(this,
|
iconBox.connect('button-release-event', Lang.bind(this,
|
||||||
function () {
|
function () {
|
||||||
source.clicked();
|
source.clicked();
|
||||||
@ -169,6 +173,11 @@ MessageTray.prototype = {
|
|||||||
return this._sources[id];
|
return this._sources[id];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_onNotify: function(source) {
|
||||||
|
let notification = new Notification(source.createIcon(ICON_SIZE), source.text);
|
||||||
|
this.showNotification(notification);
|
||||||
|
},
|
||||||
|
|
||||||
_onMessageTrayEntered: function() {
|
_onMessageTrayEntered: function() {
|
||||||
// Don't hide the message tray after a timeout if the user has moved the mouse over it.
|
// Don't hide the message tray after a timeout if the user has moved the mouse over it.
|
||||||
// We might have a timeout in place if the user moved the mouse away from the message tray for a very short period of time
|
// We might have a timeout in place if the user moved the mouse away from the message tray for a very short period of time
|
||||||
|
Loading…
Reference in New Issue
Block a user