2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2014-05-04 06:34:13 +00:00
|
|
|
*/
|
2014-10-10 23:58:34 +00:00
|
|
|
;(function() {
|
2015-03-06 19:43:53 +00:00
|
|
|
'use strict';
|
2015-05-13 00:07:13 +00:00
|
|
|
extension.windows.getBackground(function(bg) {
|
|
|
|
$('.notifications .on button').click(function() {
|
|
|
|
bg.Whisper.Notifications.disable();
|
|
|
|
initOptions();
|
|
|
|
});
|
2015-03-17 22:06:21 +00:00
|
|
|
|
2015-05-13 00:07:13 +00:00
|
|
|
$('.notifications .off button').click(function() {
|
|
|
|
bg.Whisper.Notifications.enable(initOptions);
|
|
|
|
initOptions();
|
|
|
|
});
|
2015-03-17 22:06:21 +00:00
|
|
|
|
2015-05-13 00:07:13 +00:00
|
|
|
function initOptions() {
|
|
|
|
if (bg.Whisper.Notifications.isEnabled()) {
|
|
|
|
$('.notifications .on').show();
|
|
|
|
$('.notifications .off').hide();
|
|
|
|
} else {
|
|
|
|
$('.notifications .on').hide();
|
|
|
|
$('.notifications .off').show();
|
|
|
|
}
|
2015-03-17 22:06:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 00:07:13 +00:00
|
|
|
function setProvisioningUrl(url) {
|
|
|
|
$('#status').text('');
|
|
|
|
new QRCode($('#qr')[0]).makeCode(url);
|
|
|
|
}
|
2015-04-01 20:08:09 +00:00
|
|
|
|
2015-05-13 00:07:13 +00:00
|
|
|
function confirmNumber(number) {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
$('#qr').hide();
|
|
|
|
$('.confirmation-dialog .number').text(number);
|
|
|
|
$('.confirmation-dialog .cancel').click(function(e) {
|
|
|
|
localStorage.clear();
|
|
|
|
reject();
|
|
|
|
});
|
|
|
|
$('.confirmation-dialog .ok').click(function(e) {
|
|
|
|
e.stopPropagation();
|
2015-06-18 18:00:58 +00:00
|
|
|
var name = $('#device-name').val();
|
|
|
|
if (name.trim().length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-13 00:07:13 +00:00
|
|
|
$('.confirmation-dialog').hide();
|
|
|
|
$('.progress-dialog').show();
|
|
|
|
$('.progress-dialog .status').text('Generating Keys');
|
2015-06-18 18:00:58 +00:00
|
|
|
resolve(name);
|
2015-05-13 00:07:13 +00:00
|
|
|
});
|
|
|
|
$('.modal-container').show();
|
2015-04-01 20:08:09 +00:00
|
|
|
});
|
2015-05-13 00:07:13 +00:00
|
|
|
}
|
2015-04-01 20:08:09 +00:00
|
|
|
|
2015-05-13 00:07:13 +00:00
|
|
|
var counter = 0;
|
|
|
|
function incrementCounter() {
|
|
|
|
$('.progress-dialog .bar').css('width', (++counter * 100 / 100) + '%');
|
|
|
|
}
|
2015-04-01 20:08:09 +00:00
|
|
|
|
2015-05-13 00:07:13 +00:00
|
|
|
$('.modal-container .cancel').click(function() {
|
|
|
|
$('.modal-container').hide();
|
|
|
|
});
|
2015-03-26 22:19:46 +00:00
|
|
|
|
2015-05-13 00:07:13 +00:00
|
|
|
$(function() {
|
2015-06-19 22:32:25 +00:00
|
|
|
$('#init-setup').show().addClass('in');
|
|
|
|
$('#status').text("Connecting...");
|
2015-05-11 21:22:15 +00:00
|
|
|
|
2015-09-01 19:57:02 +00:00
|
|
|
var accountManager = new bg.getAccountManager();
|
2015-06-19 22:32:25 +00:00
|
|
|
accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() {
|
2015-08-06 19:30:51 +00:00
|
|
|
var launch = function() {
|
|
|
|
bg.openInbox();
|
|
|
|
bg.removeEventListener('textsecure:contactsync', launch);
|
|
|
|
clearTimeout(timeout);
|
|
|
|
window.close();
|
|
|
|
};
|
|
|
|
var timeout = setTimeout(launch, 60000);
|
|
|
|
bg.addEventListener('textsecure:contactsync', launch);
|
|
|
|
$('.progress-dialog .status').text('Syncing groups and contacts');
|
|
|
|
$('.progress-dialog .bar').addClass('progress-bar-striped active');
|
|
|
|
|
2015-06-19 22:32:25 +00:00
|
|
|
}).catch(function(e) {
|
2015-07-10 18:28:47 +00:00
|
|
|
if (e.name === 'HTTPError' && e.code == 411) {
|
2015-06-19 23:40:33 +00:00
|
|
|
$('.progress-dialog').hide();
|
|
|
|
$('.error-dialog').show();
|
2015-07-13 23:57:45 +00:00
|
|
|
$('.error-dialog .ok').click(function(e) {
|
|
|
|
chrome.runtime.reload();
|
|
|
|
});
|
2015-06-19 22:32:25 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
2015-05-11 21:22:15 +00:00
|
|
|
});
|
2014-10-10 23:58:34 +00:00
|
|
|
});
|
|
|
|
})();
|