From df65585e71ba4e8f79481255b82cafb36d11bec4 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 12 Apr 2017 14:11:51 -0700 Subject: [PATCH] Network status listens to some global events Listen for reconnectTimer to display reconnection info. Listen for unauthorized to update network status immediately after a failed login, rather than waiting for the normal 5s interval to time out. // FREEBIE --- js/background.js | 5 ++--- js/views/network_status_view.js | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/js/background.js b/js/background.js index 509f831010..8f5c67f9bd 100644 --- a/js/background.js +++ b/js/background.js @@ -221,6 +221,7 @@ if (e.name === 'HTTPError' && (e.code == 401 || e.code == 403)) { Whisper.Registration.remove(); + Whisper.events.trigger('unauthorized'); extension.install(); return; } @@ -231,9 +232,7 @@ console.log('retrying in 1 minute'); setTimeout(init, 60000); - if (owsDesktopApp.inboxView) { - owsDesktopApp.inboxView.networkStatusView.setSocketReconnectInterval(60000); - } + Whisper.events.trigger('reconnectTimer'); } else { console.log('offline'); messageReceiver.close(); diff --git a/js/views/network_status_view.js b/js/views/network_status_view.js index 9513295404..93e4fb851a 100644 --- a/js/views/network_status_view.js +++ b/js/views/network_status_view.js @@ -19,6 +19,8 @@ window.addEventListener('online', this.update.bind(this)); window.addEventListener('offline', this.update.bind(this)); + Whisper.events.on('unauthorized', this.update, this); + Whisper.events.on('reconnectTimer', this.onReconnectTimer, this); this.model = new Backbone.Model(); this.listenTo(this.model, 'change', this.onChange); @@ -26,6 +28,9 @@ events: { 'click .openInstaller': extension.install }, + onReconnectTimer: function() { + this.setSocketReconnectInterval(60000); + }, finishConnectingGracePeriod: function() { this.withinConnectingGracePeriod = false; },