Refactor install view

Let install view manage the connection to the provisioning socket as
well as cleaning up the window on completion, simplifying options.js.
Call `remove` so that the view stops listening when the window closes.
Move view script and template to background page.
Adds ability to hide nav if this isn't our first run.

// FREEBIE
This commit is contained in:
lilia 2017-04-12 18:43:00 -07:00
parent df65585e71
commit 44a4ff3b52
5 changed files with 152 additions and 142 deletions

View file

@ -6,56 +6,19 @@
extension.windows.getBackground(function(bg) {
bg.storage.onready(function() {
$(function() {
var deviceName = bg.textsecure.storage.user.getDeviceName();
if (!deviceName) {
deviceName = 'Chrome';
if (navigator.userAgent.match('Mac OS')) {
deviceName += ' on Mac';
} else if (navigator.userAgent.match('Linux')) {
deviceName += ' on Linux';
} else if (navigator.userAgent.match('Windows')) {
deviceName += ' on Windows';
}
}
var view = new Whisper.InstallView({
el: $('#install'),
deviceName: deviceName
var Whisper = bg.Whisper;
var installView = new Whisper.InstallView({
el: $('#install')
});
if (bg.Whisper.Registration.everDone()) {
view.selectStep(3);
if (Whisper.Registration.everDone()) {
installView.selectStep(3);
installView.hideDots();
}
view.$el.show();
var accountManager = new bg.getAccountManager();
var init = function() {
view.clearQR();
accountManager.registerSecondDevice(
view.setProvisioningUrl.bind(view),
view.confirmNumber.bind(view),
view.incrementCounter.bind(view)
).then(function() {
var launch = function() {
bg.openInbox();
bg.removeEventListener('textsecure:contactsync', launch);
window.close();
};
bg.addEventListener('textsecure:contactsync', launch);
view.showSync();
}).catch(function(e) {
if (e.message === 'websocket closed') {
view.showConnectionError();
setTimeout(init, 10000);
} else if (e.name === 'HTTPError' && e.code == 411) {
view.showTooManyDevices();
}
else {
throw e;
}
});
};
$('.error-dialog .ok').click(init);
init();
installView.$el.show();
Whisper.events.on('contactsync', function() {
bg.openInbox();
window.close();
});
});
});
});