From f9ce27f2c8bf9e6b871ebd7c82f753b24db19af9 Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 1 Sep 2015 13:04:20 -0700 Subject: [PATCH] Refactor index.js There is no in-window navigation in the chrome app environment, so nix the first if-clause here. Also make it programmatically reloadable and fix indentation. // FREEBIE --- js/index.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/js/index.js b/js/index.js index 371c691648..f4dc54ba4b 100644 --- a/js/index.js +++ b/js/index.js @@ -3,17 +3,17 @@ * vim: ts=4:sw=4:expandtab */ (function () { - 'use strict'; + 'use strict'; - window.Whisper = window.Whisper || {}; + var view; - extension.windows.getBackground(function(bg) { - if (bg.textsecure.storage.user.getNumber() === undefined) { - window.location = '/options.html'; - } else { + function render() { + extension.windows.getBackground(function(bg) { extension.windows.getCurrent(function(appWindow) { - var view = new bg.Whisper.InboxView({appWindow: appWindow}); - view.$el.prependTo(bg.$('body',document)); + if (view) { view.remove(); } + var $body = bg.$('body',document).empty(); + view = new bg.Whisper.InboxView({appWindow: appWindow}); + view.$el.prependTo($body); window.openConversation = function(conversation) { if (conversation) { view.openConversation(null, conversation); @@ -21,6 +21,9 @@ }; openConversation(bg.getOpenConversation()); }); - } - }); + }); + } + + window.addEventListener('onreload', render); + render(); }());