diff --git a/background.html b/background.html
index 893976ae..d394b459 100644
--- a/background.html
+++ b/background.html
@@ -482,6 +482,7 @@
+
diff --git a/js/background.js b/js/background.js
index 637c99d6..2eb48c04 100644
--- a/js/background.js
+++ b/js/background.js
@@ -24,10 +24,10 @@
extension.onLaunched(function() {
console.log('extension launched');
storage.onready(function() {
- if (textsecure.registration.everDone()) {
+ if (Whisper.Registration.everDone()) {
openInbox();
}
- if (!textsecure.registration.isDone()) {
+ if (!Whisper.Registration.isDone()) {
extension.install();
}
});
@@ -47,7 +47,14 @@
window.getAccountManager = function() {
var USERNAME = storage.get('number_id');
var PASSWORD = storage.get('password');
- return new textsecure.AccountManager(SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD);
+ var accountManager = new textsecure.AccountManager(
+ SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD
+ );
+ accountManager.addEventListener('registration', function() {
+ Whisper.Registration.markDone();
+ extension.trigger('registration_done');
+ });
+ return accountManager;
};
storage.fetch();
@@ -55,7 +62,7 @@
window.dispatchEvent(new Event('storage_ready'));
setUnreadCount(storage.get("unreadCount", 0));
- if (textsecure.registration.isDone()) {
+ if (Whisper.Registration.isDone()) {
extension.keepAwake();
init();
}
@@ -76,7 +83,7 @@
function init(firstRun) {
window.removeEventListener('online', init);
- if (!textsecure.registration.isDone()) { return; }
+ if (!Whisper.Registration.isDone()) { return; }
if (messageReceiver) { messageReceiver.close(); }
@@ -189,7 +196,7 @@
console.log(e.stack);
if (e.name === 'HTTPError' && (e.code == 401 || e.code == 403)) {
- textsecure.registration.remove();
+ Whisper.Registration.remove();
extension.install();
return;
}
diff --git a/js/libtextsecure.js b/js/libtextsecure.js
index 10c649da..3f459c86 100644
--- a/js/libtextsecure.js
+++ b/js/libtextsecure.js
@@ -37886,7 +37886,8 @@ var TextSecureServer = (function() {
this.server = new TextSecureServer(url, ports, username, password);
}
- AccountManager.prototype = {
+ AccountManager.prototype = new textsecure.EventTarget();
+ AccountManager.prototype.extend({
constructor: AccountManager,
requestVoiceVerification: function(number) {
return this.server.requestVerificationVoice(number);
@@ -37898,16 +37899,18 @@ var TextSecureServer = (function() {
var registerKeys = this.server.registerKeys.bind(this.server);
var createAccount = this.createAccount.bind(this);
var generateKeys = this.generateKeys.bind(this, 100);
+ var registrationDone = this.registrationDone.bind(this);
return libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKeyPair) {
return createAccount(number, verificationCode, identityKeyPair).
then(generateKeys).
then(registerKeys).
- then(textsecure.registration.done);
+ then(registrationDone);
}.bind(this));
},
registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) {
var createAccount = this.createAccount.bind(this);
var generateKeys = this.generateKeys.bind(this, 100, progressCallback);
+ var registrationDone = this.registrationDone.bind(this);
var registerKeys = this.server.registerKeys.bind(this.server);
var getSocket = this.server.getProvisioningSocket.bind(this.server);
var provisioningCipher = new libsignal.ProvisioningCipher();
@@ -37954,7 +37957,7 @@ var TextSecureServer = (function() {
});
}).then(generateKeys).
then(registerKeys).
- then(textsecure.registration.done);
+ then(registrationDone);
},
refreshPreKeys: function() {
var generateKeys = this.generateKeys.bind(this, 100);
@@ -38057,8 +38060,11 @@ var TextSecureServer = (function() {
return result;
});
});
+ },
+ registrationDone: function() {
+ this.dispatchEvent(new Event('registration'));
}
- };
+ });
textsecure.AccountManager = AccountManager;
}());
diff --git a/js/options.js b/js/options.js
index 49eaec39..9f256e7b 100644
--- a/js/options.js
+++ b/js/options.js
@@ -21,7 +21,7 @@
el: $('#install'),
deviceName: deviceName
});
- if (bg.textsecure.registration.everDone()) {
+ if (bg.Whisper.Registration.everDone()) {
view.selectStep(3);
}
view.$el.show();
diff --git a/js/registration.js b/js/registration.js
new file mode 100644
index 00000000..8e3aadb9
--- /dev/null
+++ b/js/registration.js
@@ -0,0 +1,22 @@
+/*
+ * vim: ts=4:sw=4:expandtab
+ */
+(function () {
+ 'use strict';
+ Whisper.Registration = {
+ markDone: function () {
+ storage.put('chromiumRegistrationDoneEver', '');
+ storage.put('chromiumRegistrationDone', '');
+ },
+ isDone: function () {
+ return storage.get('chromiumRegistrationDone') === '';
+ },
+ everDone: function() {
+ return storage.get('chromiumRegistrationDoneEver') === '' ||
+ storage.get('chromiumRegistrationDone') === '';
+ },
+ remove: function() {
+ storage.remove('chromiumRegistrationDone');
+ }
+ };
+}());
diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js
index 91b7068d..99b08342 100644
--- a/libtextsecure/account_manager.js
+++ b/libtextsecure/account_manager.js
@@ -11,7 +11,8 @@
this.server = new TextSecureServer(url, ports, username, password);
}
- AccountManager.prototype = {
+ AccountManager.prototype = new textsecure.EventTarget();
+ AccountManager.prototype.extend({
constructor: AccountManager,
requestVoiceVerification: function(number) {
return this.server.requestVerificationVoice(number);
@@ -23,16 +24,18 @@
var registerKeys = this.server.registerKeys.bind(this.server);
var createAccount = this.createAccount.bind(this);
var generateKeys = this.generateKeys.bind(this, 100);
+ var registrationDone = this.registrationDone.bind(this);
return libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKeyPair) {
return createAccount(number, verificationCode, identityKeyPair).
then(generateKeys).
then(registerKeys).
- then(textsecure.registration.done);
+ then(registrationDone);
}.bind(this));
},
registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) {
var createAccount = this.createAccount.bind(this);
var generateKeys = this.generateKeys.bind(this, 100, progressCallback);
+ var registrationDone = this.registrationDone.bind(this);
var registerKeys = this.server.registerKeys.bind(this.server);
var getSocket = this.server.getProvisioningSocket.bind(this.server);
var provisioningCipher = new libsignal.ProvisioningCipher();
@@ -79,7 +82,7 @@
});
}).then(generateKeys).
then(registerKeys).
- then(textsecure.registration.done);
+ then(registrationDone);
},
refreshPreKeys: function() {
var generateKeys = this.generateKeys.bind(this, 100);
@@ -182,8 +185,11 @@
return result;
});
});
+ },
+ registrationDone: function() {
+ this.dispatchEvent(new Event('registration'));
}
- };
+ });
textsecure.AccountManager = AccountManager;
}());