fox-send/app/main.js

75 lines
2.0 KiB
JavaScript
Raw Normal View History

/* global LOCALE */
import 'core-js';
import 'fast-text-encoding'; // MS Edge support
2017-11-30 21:41:09 +00:00
import 'fluent-intl-polyfill';
import choo from 'choo';
import nanotiming from 'nanotiming';
import routes from './routes';
2018-07-31 18:29:26 +00:00
import capabilities from './capabilities';
import controller from './controller';
import dragManager from './dragManager';
2018-06-06 04:39:26 +00:00
import pasteManager from './pasteManager';
import storage from './storage';
import metrics from './metrics';
2017-09-12 00:09:29 +00:00
import experiments from './experiments';
import Raven from 'raven-js';
2018-07-12 20:13:49 +00:00
import './main.css';
2018-08-07 22:40:17 +00:00
import User from './user';
import { getTranslator } from './locale';
if (navigator.doNotTrack !== '1' && window.RAVEN_CONFIG) {
Raven.config(window.SENTRY_ID, window.RAVEN_CONFIG).install();
}
if (process.env.NODE_ENV === 'production') {
nanotiming.disabled = true;
}
2018-07-31 18:29:26 +00:00
(async function start() {
const app = routes(choo());
2018-07-31 18:29:26 +00:00
const capa = await capabilities();
if (capa.serviceWorker) {
await navigator.serviceWorker.register('/serviceWorker.js');
await navigator.serviceWorker.ready;
2018-07-31 18:29:26 +00:00
}
const translate = await getTranslator(LOCALE);
2018-07-31 18:29:26 +00:00
app.use((state, emitter) => {
state.capabilities = capa;
state.transfer = null;
state.fileInfo = null;
state.translate = translate;
2018-07-31 18:29:26 +00:00
state.storage = storage;
state.raven = Raven;
state.user = new User(storage);
2018-07-31 18:29:26 +00:00
window.appState = state;
2018-09-07 17:53:40 +00:00
window.appEmit = emitter.emit.bind(emitter);
2018-01-24 18:23:13 +00:00
let unsupportedReason = null;
2018-10-25 02:07:10 +00:00
2017-09-13 19:01:55 +00:00
if (
2018-01-24 18:23:13 +00:00
// Firefox < 50
2017-09-13 19:01:55 +00:00
/firefox/i.test(navigator.userAgent) &&
2018-01-24 18:23:13 +00:00
parseInt(navigator.userAgent.match(/firefox\/*([^\n\r]*)\./i)[1], 10) < 50
2017-09-13 19:01:55 +00:00
) {
2018-01-24 18:23:13 +00:00
unsupportedReason = 'outdated';
2017-09-13 19:01:55 +00:00
}
2018-07-31 18:29:26 +00:00
if (!state.capabilities.crypto) {
2018-01-24 18:23:13 +00:00
unsupportedReason = /firefox/i.test(navigator.userAgent)
? 'outdated'
: 'gcm';
2017-11-06 22:09:15 +00:00
}
2018-01-24 18:23:13 +00:00
if (unsupportedReason) {
setTimeout(() =>
emitter.emit('replaceState', `/unsupported/${unsupportedReason}`)
);
}
});
2018-07-31 18:29:26 +00:00
app.use(metrics);
app.use(controller);
2018-07-31 18:29:26 +00:00
app.use(dragManager);
app.use(experiments);
app.use(pasteManager);
app.mount('body');
})();