2014-05-14 18:58:12 +00:00
|
|
|
/* vim: ts=4:sw=4
|
|
|
|
*
|
2014-05-04 06:34:13 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
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-06-19 22:32:25 +00:00
|
|
|
var accountManager = new bg.textsecure.AccountManager();
|
|
|
|
accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() {
|
|
|
|
bg.openInbox();
|
|
|
|
window.close();
|
|
|
|
}).catch(function(e) {
|
|
|
|
if (e.name === 'HTTPError' && e.message == 411) {
|
2015-06-19 23:40:33 +00:00
|
|
|
$('.progress-dialog').hide();
|
|
|
|
$('.error-dialog').show();
|
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
|
|
|
});
|
|
|
|
})();
|