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-03-17 23:06:21 +01:00
|
|
|
$('.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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 22:08:09 +02:00
|
|
|
function setProvisioningUrl(url) {
|
|
|
|
$('#status').text('');
|
|
|
|
new QRCode($('#qr')[0]).makeCode(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
$('.confirmation-dialog').hide();
|
|
|
|
$('.progress-dialog').show();
|
2015-04-30 02:00:30 +02:00
|
|
|
$('.progress-dialog .status').text('Generating Keys');
|
2015-04-01 22:08:09 +02:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
$('.modal-container').show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var counter = 0;
|
|
|
|
function incrementCounter() {
|
|
|
|
$('.progress-dialog .bar').css('width', (++counter * 100 / 100) + '%');
|
|
|
|
}
|
|
|
|
|
2015-03-26 23:19:46 +01:00
|
|
|
$('.modal-container .cancel').click(function() {
|
|
|
|
$('.modal-container').hide();
|
|
|
|
});
|
|
|
|
|
Finish abstracting native client
Firstly, don't initialize textsecure.nativclient unless the browser
supports it. The mimetype-check trick is hewn from nacl-common.js.
Secondly, nativeclient crypto functions will all automatically wait for
the module to load before sending messages, so we needn't register any
onload callbacks outside nativeclient.js. (Previously, if you wanted to
do crypto with native client, you would have to register a call back and
wait for the module to load.) Now that the native client crypto is
encapsulated behind a nice interface, it can handle all that
onload-callback jazz internally: if the module isn't loaded when you
call a nativeclient function, return a promise that waits for the load
callback, and eventually resolves with the result of the requested
command. This removes the need for textsecure.registerOnLoadCallback.
Finally, although native client has its quirks, it's significantly
faster than the alternative (emscripten compiled js), so this commit
also lets the crypto backend use native client opportunistically, if
it's available, falling back to js if not, which should make us
compatible with older versions of chrome and chromium.
2014-11-09 02:26:20 +01:00
|
|
|
$(function() {
|
2015-04-01 22:08:09 +02:00
|
|
|
var bg = extension.windows.getBackground();
|
|
|
|
if (bg.textsecure.registration.isDone()) {
|
|
|
|
$('#complete-number').text(bg.textsecure.storage.user.getNumber());
|
Finish abstracting native client
Firstly, don't initialize textsecure.nativclient unless the browser
supports it. The mimetype-check trick is hewn from nacl-common.js.
Secondly, nativeclient crypto functions will all automatically wait for
the module to load before sending messages, so we needn't register any
onload callbacks outside nativeclient.js. (Previously, if you wanted to
do crypto with native client, you would have to register a call back and
wait for the module to load.) Now that the native client crypto is
encapsulated behind a nice interface, it can handle all that
onload-callback jazz internally: if the module isn't loaded when you
call a nativeclient function, return a promise that waits for the load
callback, and eventually resolves with the result of the requested
command. This removes the need for textsecure.registerOnLoadCallback.
Finally, although native client has its quirks, it's significantly
faster than the alternative (emscripten compiled js), so this commit
also lets the crypto backend use native client opportunistically, if
it's available, falling back to js if not, which should make us
compatible with older versions of chrome and chromium.
2014-11-09 02:26:20 +01:00
|
|
|
$('#setup-complete').show().addClass('in');
|
2015-03-17 23:06:21 +01:00
|
|
|
initOptions();
|
Finish abstracting native client
Firstly, don't initialize textsecure.nativclient unless the browser
supports it. The mimetype-check trick is hewn from nacl-common.js.
Secondly, nativeclient crypto functions will all automatically wait for
the module to load before sending messages, so we needn't register any
onload callbacks outside nativeclient.js. (Previously, if you wanted to
do crypto with native client, you would have to register a call back and
wait for the module to load.) Now that the native client crypto is
encapsulated behind a nice interface, it can handle all that
onload-callback jazz internally: if the module isn't loaded when you
call a nativeclient function, return a promise that waits for the load
callback, and eventually resolves with the result of the requested
command. This removes the need for textsecure.registerOnLoadCallback.
Finally, although native client has its quirks, it's significantly
faster than the alternative (emscripten compiled js), so this commit
also lets the crypto backend use native client opportunistically, if
it's available, falling back to js if not, which should make us
compatible with older versions of chrome and chromium.
2014-11-09 02:26:20 +01:00
|
|
|
} else {
|
2015-03-06 20:43:53 +01:00
|
|
|
$('#init-setup').show().addClass('in');
|
|
|
|
$('#status').text("Connecting...");
|
2015-04-01 22:08:09 +02:00
|
|
|
|
2015-04-30 02:00:30 +02:00
|
|
|
var accountManager = new bg.textsecure.AccountManager();
|
|
|
|
accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() {
|
2015-04-01 22:08:09 +02:00
|
|
|
$('.modal-container').hide();
|
|
|
|
$('#init-setup').hide();
|
|
|
|
$('#setup-complete').show().addClass('in');
|
|
|
|
initOptions();
|
Finish abstracting native client
Firstly, don't initialize textsecure.nativclient unless the browser
supports it. The mimetype-check trick is hewn from nacl-common.js.
Secondly, nativeclient crypto functions will all automatically wait for
the module to load before sending messages, so we needn't register any
onload callbacks outside nativeclient.js. (Previously, if you wanted to
do crypto with native client, you would have to register a call back and
wait for the module to load.) Now that the native client crypto is
encapsulated behind a nice interface, it can handle all that
onload-callback jazz internally: if the module isn't loaded when you
call a nativeclient function, return a promise that waits for the load
callback, and eventually resolves with the result of the requested
command. This removes the need for textsecure.registerOnLoadCallback.
Finally, although native client has its quirks, it's significantly
faster than the alternative (emscripten compiled js), so this commit
also lets the crypto backend use native client opportunistically, if
it's available, falling back to js if not, which should make us
compatible with older versions of chrome and chromium.
2014-11-09 02:26:20 +01:00
|
|
|
});
|
|
|
|
}
|
2014-10-11 01:58:34 +02:00
|
|
|
});
|
|
|
|
})();
|