android.js 2.7 KB

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