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