From c34f8e330d9a9c05828c7ff7e992b2a530cdcfd0 Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 6 Nov 2015 16:47:30 -0800 Subject: [PATCH] Clear timestamp timeouts if the window closes // FREEBIE --- js/chromium.js | 4 ++++ js/views/timestamp_view.js | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/js/chromium.js b/js/chromium.js index dfeb5201..7a88f472 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 a4f99eb8..54b1a845 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); } }); })();