Signal-Desktop/js/options.js

89 lines
3.7 KiB
JavaScript
Raw Normal View History

/* vim: ts=4:sw=4
*
* 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 07:58:34 +08:00
;(function() {
'use strict';
$('.notifications .on button').click(function() {
Whisper.Notifications.disable();
initOptions();
});
$('.notifications .off button').click(function() {
Whisper.Notifications.enable(initOptions);
initOptions();
});
function initOptions() {
if (Whisper.Notifications.isEnabled()) {
$('.notifications .on').show();
$('.notifications .off').hide();
} else {
$('.notifications .on').hide();
$('.notifications .off').show();
}
}
$(function() {
2014-11-14 07:38:09 +08:00
if (textsecure.registration.isDone()) {
$('#complete-number').text(
textsecure.utils.unencodeNumber(
textsecure.storage.getUnencrypted("number_id")
)[0]
);//TODO: no
$('#setup-complete').show().addClass('in');
initOptions();
} else {
$('#init-setup').show().addClass('in');
$('#status').text("Connecting...");
2015-03-18 05:31:33 +08:00
textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
var qrCode = new QRCode(document.getElementById('qr'));
var socket = textsecure.api.getTempWebsocket();
new WebSocketResource(socket, function(request) {
if (request.path == "/v1/address" && request.verb == "PUT") {
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
var url = [ 'tsdevice:/', '?uuid=', proto.uuid, '&pub_key=',
encodeURIComponent(btoa(getString(cryptoInfo.pubKey))) ].join('');
$('#status').text('');
qrCode.makeCode(url);
request.respond(200, 'OK');
} else if (request.path == "/v1/message" && request.verb == "PUT") {
$('#qr').hide();
textsecure.registerSecondDevice(request.body, cryptoInfo, function(step) {
switch(step) {
case 1:
$('#status').text('Registering new device...');
break;
case 2:
$('#status').text('Generating keys...');
break;
case 3:
$('#status').text('Uploading keys...');
break;
case 4:
$('#status').text('All done!');
2014-11-14 07:38:09 +08:00
textsecure.registration.done();
$('#init-setup').hide();
$('#setup-complete').show().addClass('in');
initOptions();
}
});
} else
console.log(request.path);
2014-10-11 07:58:34 +08:00
});
});
}
2014-10-11 07:58:34 +08:00
});
})();