diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -42,6 +42,7 @@ import UpdateModalHandler from './modals/update-modal.react.js'; import SettingsSwitcher from './navigation-panels/settings-switcher.react.js'; import Topbar from './navigation-panels/topbar.react.js'; +import { PushNotificationsHandler } from './push-notif/push-notifs-handler.js'; import { updateNavInfoActionType } from './redux/action-types.js'; import DeviceIDUpdater from './redux/device-id-updater.js'; import DisconnectedBarVisibilityHandler from './redux/disconnected-bar-visibility-handler.js'; @@ -164,6 +165,7 @@ + {content} {this.props.modals} diff --git a/web/push-notif/push-notifs-handler.js b/web/push-notif/push-notifs-handler.js new file mode 100644 --- /dev/null +++ b/web/push-notif/push-notifs-handler.js @@ -0,0 +1,22 @@ +// @flow + +import * as React from 'React'; + +import electron from '../electron.js'; + +function PushNotificationsHandler(): React.Node { + React.useEffect(() => { + (async () => { + if (!navigator.serviceWorker || electron) { + return; + } + + await navigator.serviceWorker.register('/worker/notif', { scope: '/' }); + })(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return null; +} + +export { PushNotificationsHandler };