android.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'intl-pluralrules';
  2. import choo from 'choo';
  3. import html from 'choo/html';
  4. import * as Sentry from '@sentry/browser';
  5. import { setApiUrlPrefix, getConstants } from '../app/api';
  6. //import assets from '../common/assets';
  7. import Archive from '../app/archive';
  8. import Header from '../app/ui/header';
  9. import storage from '../app/storage';
  10. import controller from '../app/controller';
  11. import User from './user';
  12. import intents from './stores/intents';
  13. import home from './pages/home';
  14. import upload from './pages/upload';
  15. import share from './pages/share';
  16. import preferences from './pages/preferences';
  17. import error from './pages/error';
  18. import { getTranslator } from '../app/locale';
  19. import { setTranslate } from '../app/utils';
  20. import { delay } from '../app/utils';
  21. if (navigator.userAgent === 'Send Android') {
  22. setApiUrlPrefix('https://send.firefox.com');
  23. }
  24. const app = choo();
  25. //app.use(state);
  26. app.use(controller);
  27. app.use(intents);
  28. window.finishLogin = async function(accountInfo) {
  29. while (!(app.state && app.state.user)) {
  30. await delay();
  31. }
  32. await app.state.user.finishLogin(accountInfo);
  33. await app.state.user.syncFileList();
  34. app.emitter.emit('replaceState', '/');
  35. };
  36. function body(main) {
  37. return function(state, emit) {
  38. /*
  39. Disable the preferences menu for now since it is ugly and isn't
  40. relevant to the beta
  41. function clickPreferences(event) {
  42. event.preventDefault();
  43. emit('pushState', '/preferences');
  44. }
  45. const menu = html`<a
  46. id="hamburger"
  47. class="absolute top-0 right-0 z-50"
  48. href="#"
  49. onclick="${clickPreferences}"
  50. >
  51. <img src="${assets.get('preferences.png')}" />
  52. </a>`;
  53. */
  54. return html`
  55. <body class="flex flex-col items-center font-sans bg-grey-10 h-screen">
  56. ${state.cache(Header, 'header').render()} ${main(state, emit)}
  57. </body>
  58. `;
  59. };
  60. }
  61. (async function start() {
  62. const translate = await getTranslator('en-US');
  63. setTranslate(translate);
  64. const { LIMITS, WEB_UI, DEFAULTS } = await getConstants();
  65. app.use(state => {
  66. state.LIMITS = LIMITS;
  67. state.WEB_UI = WEB_UI;
  68. state.DEFAULTS = DEFAULTS;
  69. state.translate = translate;
  70. state.capabilities = {
  71. account: true
  72. }; //TODO
  73. state.archive = new Archive(
  74. [],
  75. DEFAULTS.EXPIRE_SECONDS,
  76. DEFAULTS.DOWNLOADS
  77. );
  78. state.storage = storage;
  79. state.user = new User(storage, LIMITS);
  80. state.sentry = Sentry;
  81. });
  82. app.route('/', body(home));
  83. app.route('/upload', upload);
  84. app.route('/share/:id', share);
  85. app.route('/preferences', preferences);
  86. app.route('/error', error);
  87. //app.route('/debugging', require('./pages/debugging').default);
  88. // add /api/filelist
  89. app.mount('body');
  90. })();
  91. window.app = app;