2022-04-05 12:43:29 -07:00
|
|
|
import * as OfflinePluginRuntime from '@lcdp/offline-plugin/runtime';
|
2020-03-27 13:59:38 -07:00
|
|
|
import React from 'react';
|
2023-01-09 15:27:19 -08:00
|
|
|
import 'react-datepicker/dist/react-datepicker.css';
|
2023-01-05 14:42:18 -08:00
|
|
|
import { createRoot } from 'react-dom/client';
|
2022-06-23 15:53:04 -07:00
|
|
|
import { defineMessages } from 'react-intl';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-06-24 09:52:57 -07:00
|
|
|
import { setSwUpdating } from 'soapbox/actions/sw';
|
2022-11-15 12:48:54 -08:00
|
|
|
import * as BuildConfig from 'soapbox/build-config';
|
2022-06-23 13:20:41 -07:00
|
|
|
import { store } from 'soapbox/store';
|
2022-04-21 09:21:09 -07:00
|
|
|
import { printConsoleWarning } from 'soapbox/utils/console';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2023-01-09 15:27:19 -08:00
|
|
|
import '../soapbox/iframe';
|
|
|
|
import '../styles/application.scss';
|
|
|
|
|
|
|
|
import './precheck';
|
2022-01-10 14:01:24 -08:00
|
|
|
import { default as Soapbox } from './containers/soapbox';
|
2021-09-08 13:45:44 -07:00
|
|
|
import * as monitoring from './monitoring';
|
2022-01-10 14:17:52 -08:00
|
|
|
import * as perf from './performance';
|
2020-03-27 13:59:38 -07:00
|
|
|
import ready from './ready';
|
2022-12-20 09:12:08 -08:00
|
|
|
import toast from './toast';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-23 15:53:04 -07:00
|
|
|
const messages = defineMessages({
|
|
|
|
update: { id: 'sw.update', defaultMessage: 'Update' },
|
|
|
|
updateText: { id: 'sw.update_text', defaultMessage: 'An update is available.' },
|
|
|
|
});
|
|
|
|
|
2023-01-09 15:27:19 -08:00
|
|
|
perf.start('main()');
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2023-01-09 15:27:19 -08:00
|
|
|
// Sentry
|
|
|
|
monitoring.start();
|
2021-09-08 13:45:44 -07:00
|
|
|
|
2023-01-09 15:27:19 -08:00
|
|
|
// Print console warning
|
|
|
|
if (BuildConfig.NODE_ENV === 'production') {
|
|
|
|
printConsoleWarning();
|
|
|
|
}
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2023-01-09 15:27:19 -08:00
|
|
|
ready(() => {
|
2023-01-10 07:30:42 -08:00
|
|
|
const container = document.getElementById('soapbox') as HTMLElement;
|
|
|
|
const root = createRoot(container);
|
2021-09-05 14:42:48 -07:00
|
|
|
|
2023-01-10 07:30:42 -08:00
|
|
|
root.render(<Soapbox />);
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2023-01-09 15:27:19 -08:00
|
|
|
if (BuildConfig.NODE_ENV === 'production') {
|
|
|
|
// avoid offline in dev mode because it's harder to debug
|
|
|
|
// https://github.com/NekR/offline-plugin/pull/201#issuecomment-285133572
|
|
|
|
OfflinePluginRuntime.install({
|
|
|
|
onUpdateReady: function() {
|
|
|
|
toast.info(messages.updateText, {
|
|
|
|
actionLabel: messages.update,
|
|
|
|
action: () => {
|
|
|
|
store.dispatch(setSwUpdating(true));
|
|
|
|
OfflinePluginRuntime.applyUpdate();
|
|
|
|
},
|
|
|
|
duration: Infinity,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onUpdated: function() {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
perf.stop('main()');
|
|
|
|
});
|