options.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * vim: ts=4:sw=4:expandtab
  3. */
  4. ;(function() {
  5. 'use strict';
  6. extension.windows.getBackground(function(bg) {
  7. bg.storage.onready(function() {
  8. $(function() {
  9. var deviceName = bg.textsecure.storage.user.getDeviceName();
  10. if (!deviceName) {
  11. deviceName = 'Chrome';
  12. if (navigator.userAgent.match('Mac OS')) {
  13. deviceName += ' on Mac';
  14. } else if (navigator.userAgent.match('Linux')) {
  15. deviceName += ' on Linux';
  16. } else if (navigator.userAgent.match('Windows')) {
  17. deviceName += ' on Windows';
  18. }
  19. }
  20. var view = new Whisper.InstallView({
  21. el: $('#install'),
  22. deviceName: deviceName
  23. });
  24. if (bg.Whisper.Registration.everDone()) {
  25. view.selectStep(3);
  26. }
  27. view.$el.show();
  28. var accountManager = new bg.getAccountManager();
  29. var init = function() {
  30. view.clearQR();
  31. accountManager.registerSecondDevice(
  32. view.setProvisioningUrl.bind(view),
  33. view.confirmNumber.bind(view),
  34. view.incrementCounter.bind(view)
  35. ).then(function() {
  36. var launch = function() {
  37. bg.openInbox();
  38. bg.removeEventListener('textsecure:contactsync', launch);
  39. window.close();
  40. };
  41. bg.addEventListener('textsecure:contactsync', launch);
  42. view.showSync();
  43. }).catch(function(e) {
  44. if (e.message === 'websocket closed') {
  45. view.showConnectionError();
  46. setTimeout(init, 10000);
  47. } else if (e.name === 'HTTPError' && e.code == 411) {
  48. view.showTooManyDevices();
  49. }
  50. else {
  51. throw e;
  52. }
  53. });
  54. };
  55. $('.error-dialog .ok').click(init);
  56. init();
  57. });
  58. });
  59. });
  60. })();