fox-send/android/android.js

96 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-07-29 22:26:11 +00:00
import 'intl-pluralrules';
import choo from 'choo';
import html from 'choo/html';
import * as Sentry from '@sentry/browser';
import { setApiUrlPrefix, getConstants } from '../app/api';
2018-12-18 16:14:22 +00:00
//import assets from '../common/assets';
import Archive from '../app/archive';
import Header from '../app/ui/header';
import storage from '../app/storage';
import controller from '../app/controller';
import User from './user';
import intents from './stores/intents';
import home from './pages/home';
import upload from './pages/upload';
import share from './pages/share';
import preferences from './pages/preferences';
import error from './pages/error';
import { getTranslator } from '../app/locale';
2019-04-04 18:49:01 +00:00
import { setTranslate } from '../app/utils';
2019-03-08 18:17:10 +00:00
import { delay } from '../app/utils';
if (navigator.userAgent === 'Send Android') {
setApiUrlPrefix('https://send.firefox.com');
}
const app = choo();
//app.use(state);
app.use(controller);
app.use(intents);
2019-03-08 18:17:10 +00:00
window.finishLogin = async function(accountInfo) {
while (!(app.state && app.state.user)) {
await delay();
}
await app.state.user.finishLogin(accountInfo);
await app.state.user.syncFileList();
app.emitter.emit('replaceState', '/');
};
2018-11-02 22:51:27 +00:00
function body(main) {
return function(state, emit) {
2018-12-18 16:14:22 +00:00
/*
Disable the preferences menu for now since it is ugly and isn't
relevant to the beta
function clickPreferences(event) {
event.preventDefault();
emit('pushState', '/preferences');
}
const menu = html`<a
id="hamburger"
2019-06-14 18:30:43 +00:00
class="absolute top-0 right-0 z-50"
2018-12-18 16:14:22 +00:00
href="#"
onclick="${clickPreferences}"
>
<img src="${assets.get('preferences.png')}" />
</a>`;
*/
return html`
2019-09-09 17:34:55 +00:00
<body class="flex flex-col items-center font-sans bg-grey-10 h-screen">
${state.cache(Header, 'header').render()} ${main(state, emit)}
</body>
`;
2018-11-02 22:51:27 +00:00
};
}
(async function start() {
const translate = await getTranslator('en-US');
2019-04-04 18:49:01 +00:00
setTranslate(translate);
const { LIMITS, WEB_UI, DEFAULTS } = await getConstants();
2019-03-08 18:17:10 +00:00
app.use(state => {
state.LIMITS = LIMITS;
state.WEB_UI = WEB_UI;
state.DEFAULTS = DEFAULTS;
state.translate = translate;
state.capabilities = {
account: true
}; //TODO
state.archive = new Archive([], DEFAULTS.EXPIRE_SECONDS);
state.storage = storage;
2019-03-08 21:04:46 +00:00
state.user = new User(storage, LIMITS);
state.sentry = Sentry;
});
app.route('/', body(home));
app.route('/upload', upload);
app.route('/share/:id', share);
app.route('/preferences', preferences);
app.route('/error', error);
//app.route('/debugging', require('./pages/debugging').default);
// add /api/filelist
app.mount('body');
})();
2019-03-08 18:17:10 +00:00
window.app = app;