From 5a0e199fc583ca1ffef878194780f71e6e684e65 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 13 Nov 2014 15:38:09 -0800 Subject: [PATCH] Namespace registration helpers --- js/background.js | 4 ++-- js/chromium.js | 33 ++++++++++++++++++--------------- js/options.js | 6 +++--- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/js/background.js b/js/background.js index 2ddf42caa..1e2a72553 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 d5874cfd4..d03d08eb7 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 490c261b5..f097ac093 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(); } }); }