2018-11-08 22:35:19 +01:00
|
|
|
/* global window, navigator */
|
2019-03-08 22:04:46 +01:00
|
|
|
import 'fluent-intl-polyfill';
|
2018-11-14 20:20:32 +01:00
|
|
|
import choo from 'choo';
|
|
|
|
import html from 'choo/html';
|
|
|
|
import Raven from 'raven-js';
|
|
|
|
|
2019-02-26 19:39:50 +01:00
|
|
|
import { setApiUrlPrefix, getConstants } from '../app/api';
|
2018-12-17 22:40:17 +01:00
|
|
|
import metrics from '../app/metrics';
|
2018-12-18 17:14:22 +01:00
|
|
|
//import assets from '../common/assets';
|
2019-01-08 21:46:16 +01:00
|
|
|
import Archive from '../app/archive';
|
2018-11-12 20:13:31 +01:00
|
|
|
import Header from '../app/ui/header';
|
2018-11-14 20:20:32 +01:00
|
|
|
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';
|
2018-11-20 15:50:59 +01:00
|
|
|
import { getTranslator } from '../app/locale';
|
2019-04-04 20:49:01 +02:00
|
|
|
import { setTranslate } from '../app/utils';
|
|
|
|
|
2019-03-08 19:17:10 +01:00
|
|
|
import { delay } from '../app/utils';
|
2018-07-27 15:11:46 +02:00
|
|
|
|
2018-11-08 22:35:19 +01:00
|
|
|
if (navigator.userAgent === 'Send Android') {
|
2019-03-12 17:35:45 +01:00
|
|
|
setApiUrlPrefix('https://send.firefox.com');
|
2018-11-08 22:35:19 +01:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:20:32 +01:00
|
|
|
const app = choo();
|
|
|
|
//app.use(state);
|
|
|
|
app.use(controller);
|
|
|
|
app.use(intents);
|
|
|
|
|
2019-03-08 19:17:10 +01: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 23:51:27 +01:00
|
|
|
function body(main) {
|
|
|
|
return function(state, emit) {
|
2018-12-18 17:14:22 +01: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 20:30:43 +02:00
|
|
|
class="absolute top-0 right-0 z-50"
|
2018-12-18 17:14:22 +01:00
|
|
|
href="#"
|
|
|
|
onclick="${clickPreferences}"
|
|
|
|
>
|
|
|
|
<img src="${assets.get('preferences.png')}" />
|
|
|
|
</a>`;
|
|
|
|
*/
|
2018-11-09 00:12:07 +01:00
|
|
|
return html`
|
|
|
|
<body
|
2019-02-11 22:48:06 +01:00
|
|
|
class="flex flex-col items-center font-sans bg-grey-lightest h-screen"
|
2018-11-09 00:12:07 +01:00
|
|
|
>
|
2018-11-12 20:13:31 +01:00
|
|
|
${state.cache(Header, 'header').render()} ${main(state, emit)}
|
2018-11-09 00:12:07 +01:00
|
|
|
</body>
|
|
|
|
`;
|
2018-11-02 23:51:27 +01:00
|
|
|
};
|
|
|
|
}
|
2018-11-20 15:50:59 +01:00
|
|
|
(async function start() {
|
|
|
|
const translate = await getTranslator('en-US');
|
2019-04-04 20:49:01 +02:00
|
|
|
setTranslate(translate);
|
2019-02-26 19:39:50 +01:00
|
|
|
const { LIMITS, DEFAULTS } = await getConstants();
|
2019-03-08 19:17:10 +01:00
|
|
|
app.use(state => {
|
2019-02-26 19:39:50 +01:00
|
|
|
state.LIMITS = LIMITS;
|
|
|
|
state.DEFAULTS = DEFAULTS;
|
2018-11-20 15:50:59 +01:00
|
|
|
state.translate = translate;
|
|
|
|
state.capabilities = {
|
|
|
|
account: true
|
|
|
|
}; //TODO
|
2019-02-26 19:39:50 +01:00
|
|
|
state.archive = new Archive([], DEFAULTS.EXPIRE_SECONDS);
|
2018-11-20 15:50:59 +01:00
|
|
|
state.storage = storage;
|
2019-03-08 22:04:46 +01:00
|
|
|
state.user = new User(storage, LIMITS);
|
2018-11-20 15:50:59 +01:00
|
|
|
state.raven = Raven;
|
|
|
|
});
|
2019-02-12 21:21:18 +01:00
|
|
|
app.use(metrics);
|
2018-11-20 15:50:59 +01:00
|
|
|
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 19:17:10 +01:00
|
|
|
|
|
|
|
window.app = app;
|