You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
7 years ago
|
import React from 'react';
|
||
|
import ReactDOM from 'react-dom';
|
||
2 years ago
|
import { setupBrowserNotifications } from 'mastodon/actions/notifications';
|
||
|
import Mastodon, { store } from 'mastodon/containers/mastodon';
|
||
2 years ago
|
import { me } from 'mastodon/initial_state';
|
||
2 years ago
|
import ready from 'mastodon/ready';
|
||
8 years ago
|
|
||
2 years ago
|
const perf = require('mastodon/performance');
|
||
8 years ago
|
|
||
2 years ago
|
/**
|
||
|
* @returns {Promise<void>}
|
||
|
*/
|
||
8 years ago
|
function main() {
|
||
8 years ago
|
perf.start('main()');
|
||
8 years ago
|
|
||
2 years ago
|
return ready(async () => {
|
||
8 years ago
|
const mountNode = document.getElementById('mastodon');
|
||
|
const props = JSON.parse(mountNode.getAttribute('data-props'));
|
||
|
|
||
|
ReactDOM.render(<Mastodon {...props} />, mountNode);
|
||
4 years ago
|
store.dispatch(setupBrowserNotifications());
|
||
2 years ago
|
|
||
2 years ago
|
if (process.env.NODE_ENV === 'production' && me && 'serviceWorker' in navigator) {
|
||
|
const { Workbox } = await import('workbox-window');
|
||
|
const wb = new Workbox('/sw.js');
|
||
|
/** @type {ServiceWorkerRegistration} */
|
||
|
let registration;
|
||
2 years ago
|
|
||
2 years ago
|
try {
|
||
|
registration = await wb.register();
|
||
|
} catch (err) {
|
||
|
console.error(err);
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
if (registration) {
|
||
2 years ago
|
const registerPushNotifications = await import('mastodon/actions/push_notifications');
|
||
|
|
||
|
store.dispatch(registerPushNotifications.register());
|
||
|
}
|
||
7 years ago
|
}
|
||
2 years ago
|
|
||
8 years ago
|
perf.stop('main()');
|
||
8 years ago
|
});
|
||
|
}
|
||
|
|
||
8 years ago
|
export default main;
|