send/app/main.js

77 lines
2.1 KiB
JavaScript
Raw Normal View History

/* global DEFAULTS LIMITS WEB_UI PREFS */
import 'core-js';
import 'fast-text-encoding'; // MS Edge support
2019-07-29 22:26:11 +00:00
import 'intl-pluralrules';
import choo from 'choo';
import nanotiming from 'nanotiming';
import routes from './routes';
2018-12-13 19:12:06 +00:00
import getCapabilities 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 * as Sentry from '@sentry/browser';
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';
import Archive from './archive';
2019-04-26 20:30:33 +00:00
import { setTranslate, locale } from './utils';
if (navigator.doNotTrack !== '1' && window.SENTRY_CONFIG) {
Sentry.init(window.SENTRY_CONFIG);
}
if (process.env.NODE_ENV === 'production') {
nanotiming.disabled = true;
}
2018-07-31 18:29:26 +00:00
(async function start() {
2018-12-13 19:12:06 +00:00
const capabilities = await getCapabilities();
if (
!capabilities.crypto &&
window.location.pathname !== '/unsupported/crypto'
) {
2018-12-18 20:27:43 +00:00
return window.location.assign('/unsupported/crypto');
}
2018-12-13 19:12:06 +00:00
if (capabilities.serviceWorker) {
try {
await navigator.serviceWorker.register('/serviceWorker.js');
await navigator.serviceWorker.ready;
} catch (e) {
// continue but disable streaming downloads
capabilities.streamDownload = false;
}
2018-07-31 18:29:26 +00:00
}
2019-04-26 20:30:33 +00:00
const translate = await getTranslator(locale());
2019-03-12 02:28:22 +00:00
setTranslate(translate);
2019-07-29 22:26:11 +00:00
// eslint-disable-next-line require-atomic-updates
2018-12-13 19:12:06 +00:00
window.initialState = {
LIMITS,
DEFAULTS,
WEB_UI,
2019-04-26 20:30:33 +00:00
PREFS,
archive: new Archive([], DEFAULTS.EXPIRE_SECONDS),
2018-12-13 19:12:06 +00:00
capabilities,
translate,
storage,
sentry: Sentry,
user: new User(storage, LIMITS, window.AUTH_CONFIG),
2018-12-13 19:12:06 +00:00
transfer: null,
2020-03-24 19:58:02 +00:00
fileInfo: null,
locale: locale()
2018-12-13 19:12:06 +00:00
};
2019-08-26 15:58:34 +00:00
const app = routes(choo({ hash: true }));
2019-07-29 22:26:11 +00:00
// eslint-disable-next-line require-atomic-updates
2019-02-19 22:14:28 +00:00
window.app = app;
app.use(experiments);
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(pasteManager);
app.mount('body');
})();