diff --git a/js/background.js b/js/background.js index 33779699..2ddf42ca 100644 --- a/js/background.js +++ b/js/background.js @@ -17,20 +17,25 @@ ;(function() { 'use strict'; - if (!localStorage.getItem('first_install_ran')) { - localStorage.setItem('first_install_ran', 1); - extension.navigator.tabs.create("options.html"); - } else { - if (isRegistrationDone()) { - textsecure.subscribeToPush(function(message) { - Whisper.Messages.addIncomingMessage(message).then(function() { - console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice + - ': "' + getString(message.message.body) + '"'); - var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount", 0) + 1; - textsecure.storage.putUnencrypted("unreadCount", newUnreadCount); - extension.navigator.setBadgeText(newUnreadCount); + function init() { + if (!localStorage.getItem('first_install_ran')) { + localStorage.setItem('first_install_ran', 1); + extension.navigator.tabs.create("options.html"); + } else { + if (isRegistrationDone()) { + textsecure.subscribeToPush(function(message) { + Whisper.Messages.addIncomingMessage(message).then(function() { + console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice + + ': "' + getString(message.message.body) + '"'); + var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount", 0) + 1; + textsecure.storage.putUnencrypted("unreadCount", newUnreadCount); + extension.navigator.setBadgeText(newUnreadCount); + }); }); - }); + } } - } + }; + + addRegistrationListener(init); + init(); })(); diff --git a/js/chromium.js b/js/chromium.js index cbd9c087..66c73bee 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -36,10 +36,18 @@ window.extension.navigator = function() { function registrationDone() { localStorage.setItem("chromiumRegistrationDone", ""); - //TODO: Fix dirty hack: - chrome.runtime.reload(); + chrome.runtime.sendMessage('registration_done'); + window.location = '/index.html'; } function isRegistrationDone() { return localStorage.getItem("chromiumRegistrationDone") !== null; } + +function addRegistrationListener(callback) { + chrome.runtime.onMessage.addListener(function(message) { + if (message === 'registration_done') { + callback(); + } + }); +}; diff --git a/js/index.js b/js/index.js index 65d28f36..e28921c3 100644 --- a/js/index.js +++ b/js/index.js @@ -63,7 +63,7 @@ Whisper.Layout = new (Backbone.View.extend({ }))({el: document}); if (textsecure.storage.getUnencrypted("number_id") === undefined) { - extension.navigator.tabs.create("options.html"); + window.location = '/options.html'; } else { textsecure.storage.putUnencrypted("unreadCount", 0); extension.navigator.setBadgeText("");