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