2017-07-18 08:19:02 +10:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2022-08-26 04:10:01 +10:00
|
|
|
import { setupBrowserNotifications } from 'mastodon/actions/notifications';
|
|
|
|
import Mastodon, { store } from 'mastodon/containers/mastodon';
|
|
|
|
import ready from 'mastodon/ready';
|
2017-05-25 22:09:55 +10:00
|
|
|
|
2022-10-04 03:15:47 +11:00
|
|
|
const perf = require('mastodon/performance');
|
2017-05-11 19:26:06 +10:00
|
|
|
|
2022-10-04 03:15:47 +11:00
|
|
|
/**
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
2017-05-11 19:26:06 +10:00
|
|
|
function main() {
|
2017-05-25 22:09:55 +10:00
|
|
|
perf.start('main()');
|
2017-05-11 19:26:06 +10:00
|
|
|
|
2017-06-30 13:37:41 +10:00
|
|
|
if (window.history && history.replaceState) {
|
|
|
|
const { pathname, search, hash } = window.location;
|
|
|
|
const path = pathname + search + hash;
|
2020-02-22 11:27:34 +11:00
|
|
|
if (!(/^\/web($|\/)/).test(path)) {
|
2017-06-30 13:37:41 +10:00
|
|
|
history.replaceState(null, document.title, `/web${path}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:15:47 +11:00
|
|
|
return ready(async () => {
|
2017-05-11 19:26:06 +10:00
|
|
|
const mountNode = document.getElementById('mastodon');
|
|
|
|
const props = JSON.parse(mountNode.getAttribute('data-props'));
|
|
|
|
|
|
|
|
ReactDOM.render(<Mastodon {...props} />, mountNode);
|
2020-10-13 09:37:21 +11:00
|
|
|
store.dispatch(setupBrowserNotifications());
|
2022-08-26 04:10:01 +10:00
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
2022-10-04 03:15:47 +11:00
|
|
|
const [{ Workbox }, { me }] = await Promise.all([
|
|
|
|
import('workbox-window'),
|
|
|
|
import('mastodon/initial_state'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const wb = new Workbox('/sw.js');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await wb.register();
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (me) {
|
|
|
|
const registerPushNotifications = await import('mastodon/actions/push_notifications');
|
|
|
|
|
|
|
|
store.dispatch(registerPushNotifications.register());
|
|
|
|
}
|
2017-07-14 06:15:32 +10:00
|
|
|
}
|
2022-10-04 03:15:47 +11:00
|
|
|
|
2017-05-25 22:09:55 +10:00
|
|
|
perf.stop('main()');
|
2017-05-11 19:26:06 +10:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-21 01:31:47 +10:00
|
|
|
export default main;
|