From f0dcf44b9fadc6a397abb33c1c22314eea5d79b9 Mon Sep 17 00:00:00 2001 From: lilia Date: Sun, 8 Nov 2015 10:40:37 -0800 Subject: [PATCH] Use onClosed instead of onSuspend Renames extension.windows.beforeUnload to onSuspend, to match the underlying chrome api call. onClosed fires when the frontend app window is closed, while onSuspend fires when the background page is closed or refreshed (which amounts to an app restart). Frontend views are initialized iff the inbox window is opened, and so should always be listening to onClosed in order to know when they are no longer needed. // FREEBIE --- js/chromium.js | 2 +- js/panel_controller.js | 4 ++-- js/views/conversation_list_item_view.js | 4 +--- js/views/inbox_view.js | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/js/chromium.js b/js/chromium.js index 98001fdc0..58860b1b2 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -115,7 +115,7 @@ } }, - beforeUnload: function(callback) { + onSuspend: function(callback) { if (chrome.runtime) { chrome.runtime.onSuspend.addListener(callback); } else { diff --git a/js/panel_controller.js b/js/panel_controller.js index 3e58bccc8..d1f9239b1 100644 --- a/js/panel_controller.js +++ b/js/panel_controller.js @@ -63,8 +63,8 @@ inboxFocused = true; }); - // close the panel if background.html is refreshed - extension.windows.beforeUnload(function() { + // close the inbox if background.html is refreshed + extension.windows.onSuspend(function() { // TODO: reattach after reload instead of closing. extension.windows.remove(inboxWindowId); }); diff --git a/js/views/conversation_list_item_view.js b/js/views/conversation_list_item_view.js index 3597a86e4..c501625c5 100644 --- a/js/views/conversation_list_item_view.js +++ b/js/views/conversation_list_item_view.js @@ -19,9 +19,7 @@ this.listenTo(this.model, 'change', this.render); // auto update this.listenTo(this.model, 'destroy', this.remove); // auto update this.listenTo(this.model, 'opened', this.markSelected); // auto update - extension.windows.beforeUnload(function() { - this.stopListening(); - }.bind(this)); + extension.windows.onClosed(this.stopListening.bind(this)); }, markSelected: function() { diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index 90e4c4a38..55d710fa0 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -116,7 +116,7 @@ new SocketView().render().$el.appendTo(this.$('.socket-status')); - extension.windows.beforeUnload(function() { + extension.windows.onClosed(function() { this.inboxListView.stopListening(); }.bind(this)); },