diff --git a/js/background.js b/js/background.js index 2ddf42caaa..1e2a725537 100644 --- a/js/background.js +++ b/js/background.js @@ -22,7 +22,7 @@ localStorage.setItem('first_install_ran', 1); extension.navigator.tabs.create("options.html"); } else { - if (isRegistrationDone()) { + if (textsecure.registration.isDone()) { textsecure.subscribeToPush(function(message) { Whisper.Messages.addIncomingMessage(message).then(function() { console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice + @@ -36,6 +36,6 @@ } }; - addRegistrationListener(init); + textsecure.registration.addListener(init); init(); })(); diff --git a/js/chromium.js b/js/chromium.js index d5874cfd46..d03d08eb7f 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -35,21 +35,24 @@ // Random shared utilities that are used only by chromium things - function registrationDone() { - localStorage.setItem("chromiumRegistrationDone", ""); - chrome.runtime.sendMessage('registration_done'); - window.location = '/index.html'; - } + window.textsecure = window.textsecure || {}; + window.textsecure.registration = { + done: function () { + localStorage.setItem("chromiumRegistrationDone", ""); + chrome.runtime.sendMessage('registration_done'); + window.location = '/index.html'; + }, - function isRegistrationDone() { - return localStorage.getItem("chromiumRegistrationDone") !== null; - } + isDone: function () { + return localStorage.getItem("chromiumRegistrationDone") !== null; + }, - function addRegistrationListener(callback) { - chrome.runtime.onMessage.addListener(function(message) { - if (message === 'registration_done') { - callback(); - } - }); - } + addListener: function (callback) { + chrome.runtime.onMessage.addListener(function(message) { + if (message === 'registration_done') { + callback(); + } + }); + } + }; }()); diff --git a/js/options.js b/js/options.js index 490c261b5a..f097ac093e 100644 --- a/js/options.js +++ b/js/options.js @@ -45,7 +45,7 @@ }; $(function() { - if (isRegistrationDone()) { + if (textsecure.registration.isDone()) { $('#complete-number').text(textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]);//TODO: no $('#setup-complete').show().addClass('in'); } else { @@ -124,7 +124,7 @@ $('#verify').hide(); $('#init-setup').hide().removeClass('in'); $('#setup-complete').show().addClass('in'); - registrationDone(); + textsecure.registration.done(); } }).catch(function(error) { $('#verify *').hide(); @@ -192,7 +192,7 @@ case 5: $('#verify').hide(); $('#setup-complete').show().addClass('in'); - registrationDone(); + textsecure.registration.done(); } }); }