Clear timestamp timeouts if the window closes
// FREEBIE
This commit is contained in:
parent
2ce890b845
commit
c34f8e330d
2 changed files with 11 additions and 1 deletions
|
@ -122,6 +122,10 @@
|
||||||
window.addEventListener('beforeunload', callback);
|
window.addEventListener('beforeunload', callback);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onClosed: function(callback) {
|
||||||
|
// assumes only one front end window
|
||||||
|
return chrome.app.window.getAll()[0].onClosed.addListener(callback);
|
||||||
|
},
|
||||||
|
|
||||||
drawAttention: function(window_id) {
|
drawAttention: function(window_id) {
|
||||||
if (chrome.app.window) {
|
if (chrome.app.window) {
|
||||||
|
|
|
@ -6,8 +6,11 @@
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
|
||||||
Whisper.MessageTimestampView = Whisper.View.extend({
|
Whisper.MessageTimestampView = Whisper.View.extend({
|
||||||
|
initialize: function() {
|
||||||
|
extension.windows.onClosed(this.clearTimeout.bind(this));
|
||||||
|
},
|
||||||
update: function() {
|
update: function() {
|
||||||
clearTimeout(this.timeout);
|
this.clearTimeout();
|
||||||
var millis_now = Date.now();
|
var millis_now = Date.now();
|
||||||
var millis = this.$el.data('timestamp');
|
var millis = this.$el.data('timestamp');
|
||||||
if (millis >= millis_now) {
|
if (millis >= millis_now) {
|
||||||
|
@ -48,6 +51,9 @@
|
||||||
if (delay < 0) { delay = 0; }
|
if (delay < 0) { delay = 0; }
|
||||||
this.timeout = setTimeout(this.update.bind(this), delay);
|
this.timeout = setTimeout(this.update.bind(this), delay);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
clearTimeout: function() {
|
||||||
|
clearTimeout(this.timeout);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue