Namespace registration helpers

This commit is contained in:
lilia 2014-11-13 15:38:09 -08:00
parent 28290477f4
commit 5a0e199fc5
3 changed files with 23 additions and 20 deletions

View file

@ -22,7 +22,7 @@
localStorage.setItem('first_install_ran', 1); localStorage.setItem('first_install_ran', 1);
extension.navigator.tabs.create("options.html"); extension.navigator.tabs.create("options.html");
} else { } else {
if (isRegistrationDone()) { if (textsecure.registration.isDone()) {
textsecure.subscribeToPush(function(message) { textsecure.subscribeToPush(function(message) {
Whisper.Messages.addIncomingMessage(message).then(function() { Whisper.Messages.addIncomingMessage(message).then(function() {
console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice + console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice +
@ -36,6 +36,6 @@
} }
}; };
addRegistrationListener(init); textsecure.registration.addListener(init);
init(); init();
})(); })();

View file

@ -35,21 +35,24 @@
// Random shared utilities that are used only by chromium things // Random shared utilities that are used only by chromium things
function registrationDone() { window.textsecure = window.textsecure || {};
window.textsecure.registration = {
done: function () {
localStorage.setItem("chromiumRegistrationDone", ""); localStorage.setItem("chromiumRegistrationDone", "");
chrome.runtime.sendMessage('registration_done'); chrome.runtime.sendMessage('registration_done');
window.location = '/index.html'; window.location = '/index.html';
} },
function isRegistrationDone() { isDone: function () {
return localStorage.getItem("chromiumRegistrationDone") !== null; return localStorage.getItem("chromiumRegistrationDone") !== null;
} },
function addRegistrationListener(callback) { addListener: function (callback) {
chrome.runtime.onMessage.addListener(function(message) { chrome.runtime.onMessage.addListener(function(message) {
if (message === 'registration_done') { if (message === 'registration_done') {
callback(); callback();
} }
}); });
} }
};
}()); }());

View file

@ -45,7 +45,7 @@
}; };
$(function() { $(function() {
if (isRegistrationDone()) { if (textsecure.registration.isDone()) {
$('#complete-number').text(textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]);//TODO: no $('#complete-number').text(textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]);//TODO: no
$('#setup-complete').show().addClass('in'); $('#setup-complete').show().addClass('in');
} else { } else {
@ -124,7 +124,7 @@
$('#verify').hide(); $('#verify').hide();
$('#init-setup').hide().removeClass('in'); $('#init-setup').hide().removeClass('in');
$('#setup-complete').show().addClass('in'); $('#setup-complete').show().addClass('in');
registrationDone(); textsecure.registration.done();
} }
}).catch(function(error) { }).catch(function(error) {
$('#verify *').hide(); $('#verify *').hide();
@ -192,7 +192,7 @@
case 5: case 5:
$('#verify').hide(); $('#verify').hide();
$('#setup-complete').show().addClass('in'); $('#setup-complete').show().addClass('in');
registrationDone(); textsecure.registration.done();
} }
}); });
} }