diff --git a/index.html b/index.html index 58befd87da..af87db3562 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@ - + diff --git a/js/background.js b/js/background.js index 63356fd945..730617f3c2 100644 --- a/js/background.js +++ b/js/background.js @@ -120,6 +120,9 @@ window.textsecure.messaging = new textsecure.MessageSender( SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD ); + + deferredInit.resolve(owsDesktopApp); + if (firstRun === true && textsecure.storage.user.getDeviceId() != '1') { if (!storage.get('theme-setting') && textsecure.storage.get('userAgent') === 'OWI') { storage.put('theme-setting', 'ios'); @@ -293,4 +296,38 @@ timestamp: timestamp, source: pushMessage.source }); } + + var App = Backbone.Model.extend({ + initialize: function(opts) { + this.inboxView = null; + }, + getAppView: function(destWindow) { + + var self = this; + + return ConversationController.updateInbox().then(function() { + try { + if (self.inboxView) { self.inboxView.remove(); } + self.inboxView = new Whisper.InboxView({model: self, window: destWindow}); + destWindow.openConversation = function(conversation) { + if (conversation) { + self.inboxView.openConversation(null, conversation); + } + }; + destWindow.openConversation(getOpenConversation()); + + return self.inboxView; + + } catch (e) { + console.log(e); + } + }); + } + }); + + window.owsDesktopApp = new App(); + + var deferredInit = $.Deferred(); + window.initLoading = deferredInit.promise(); + })(); diff --git a/js/index.js b/js/index.js index 621abe2a4f..e94a468fee 100644 --- a/js/index.js +++ b/js/index.js @@ -15,25 +15,15 @@ logError(error); }; - var view; - function render() { extension.windows.getBackground(function(bg) { - bg.ConversationController.updateInbox().then(function() { - try { - if (view) { view.remove(); } - var $body = bg.$('body',document).empty(); - view = new bg.Whisper.InboxView({window: window}); - view.$el.prependTo($body); - window.openConversation = function(conversation) { - if (conversation) { - view.openConversation(null, conversation); - } - }; - openConversation(bg.getOpenConversation()); - } catch (e) { - logError(e); - } + + var inboxPromise = bg.initLoading.done(function(owsDesktopApp) { + owsDesktopApp.getAppView(window).then(function(appView) { + var bodyEl = document.getElementById('signal-container'); + bodyEl.innerHTML = ""; + bodyEl.append(appView.el); + }); }); }); }