From e626355e0c08b106a3261045b483f0450d133e64 Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 1 Sep 2015 12:57:02 -0700 Subject: [PATCH] Let background page instantiate AccountManagers Remove the need to expose the server url config as a global. // FREEBIE --- js/axolotl_store.js | 3 +-- js/background.js | 8 ++++++-- js/options.js | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/js/axolotl_store.js b/js/axolotl_store.js index b97e3f63e1..beb3c33125 100644 --- a/js/axolotl_store.js +++ b/js/axolotl_store.js @@ -123,8 +123,7 @@ var prekey = new PreKey({id: keyId}); new Promise(function(resolve) { - var accountManager = new textsecure.AccountManager(TEXT_SECURE_SERVER_URL); - accountManager.refreshPreKeys().then(resolve); + getAccountManager().refreshPreKeys().then(resolve); }); return new Promise(function(resolve) { diff --git a/js/background.js b/js/background.js index cadca6300d..fdbbe4d4dc 100644 --- a/js/background.js +++ b/js/background.js @@ -62,6 +62,12 @@ return -1; } }; + window.getAccountManager = function() { + var USERNAME = storage.get('number_id'); + var PASSWORD = storage.get('password'); + return new textsecure.AccountManager(SERVER_URL, USERNAME, PASSWORD); + }; + storage.fetch(); storage.onready(function() { setUnreadCount(storage.get("unreadCount", 0)); @@ -74,8 +80,6 @@ init(true); }); - window.TEXT_SECURE_SERVER_URL = 'https://textsecure-service-staging.whispersystems.org'; - if (open) { openInbox(); } diff --git a/js/options.js b/js/options.js index 20545e0402..2ebf569cac 100644 --- a/js/options.js +++ b/js/options.js @@ -65,7 +65,7 @@ $('#init-setup').show().addClass('in'); $('#status').text("Connecting..."); - var accountManager = new bg.textsecure.AccountManager(bg.TEXT_SECURE_SERVER_URL); + var accountManager = new bg.getAccountManager(); accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() { var launch = function() { bg.openInbox();