diff --git a/js/chromium.js b/js/chromium.js index dfeb5201a..7a88f4724 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -122,6 +122,10 @@ 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) { if (chrome.app.window) { diff --git a/js/views/timestamp_view.js b/js/views/timestamp_view.js index a4f99eb8d..54b1a845b 100644 --- a/js/views/timestamp_view.js +++ b/js/views/timestamp_view.js @@ -6,8 +6,11 @@ window.Whisper = window.Whisper || {}; Whisper.MessageTimestampView = Whisper.View.extend({ + initialize: function() { + extension.windows.onClosed(this.clearTimeout.bind(this)); + }, update: function() { - clearTimeout(this.timeout); + this.clearTimeout(); var millis_now = Date.now(); var millis = this.$el.data('timestamp'); if (millis >= millis_now) { @@ -48,6 +51,9 @@ if (delay < 0) { delay = 0; } this.timeout = setTimeout(this.update.bind(this), delay); } + }, + clearTimeout: function() { + clearTimeout(this.timeout); } }); })();