mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-09-13 22:32:26 +03:00
pull service worker code out of the index.ts and refer to its setup method
This commit is contained in:
parent
ab4c662b2f
commit
ffa6a9c6aa
1 changed files with 5 additions and 27 deletions
|
@ -5,38 +5,16 @@ import { enableMapSet } from 'immer';
|
||||||
import '@fontsource/inter/variable.css';
|
import '@fontsource/inter/variable.css';
|
||||||
import 'folds/dist/style.css';
|
import 'folds/dist/style.css';
|
||||||
import { configClass, varsClass } from 'folds';
|
import { configClass, varsClass } from 'folds';
|
||||||
|
import './index.scss';
|
||||||
|
import App from './app/pages/App';
|
||||||
|
import './app/i18n';
|
||||||
|
import { readyServiceWorker } from './serviceWorkerBridge';
|
||||||
|
|
||||||
enableMapSet();
|
enableMapSet();
|
||||||
|
|
||||||
import './index.scss';
|
|
||||||
|
|
||||||
import { trimTrailingSlash } from './app/utils/common';
|
|
||||||
import App from './app/pages/App';
|
|
||||||
|
|
||||||
// import i18n (needs to be bundled ;))
|
|
||||||
import './app/i18n';
|
|
||||||
|
|
||||||
document.body.classList.add(configClass, varsClass);
|
document.body.classList.add(configClass, varsClass);
|
||||||
|
|
||||||
// Register Service Worker
|
readyServiceWorker();
|
||||||
if ('serviceWorker' in navigator) {
|
|
||||||
const swUrl =
|
|
||||||
import.meta.env.MODE === 'production'
|
|
||||||
? `${trimTrailingSlash(import.meta.env.BASE_URL)}/sw.js`
|
|
||||||
: `/dev-sw.js?dev-sw`;
|
|
||||||
|
|
||||||
navigator.serviceWorker.register(swUrl);
|
|
||||||
navigator.serviceWorker.addEventListener('message', (event) => {
|
|
||||||
if (event.data?.type === 'token' && event.data?.responseKey) {
|
|
||||||
// Get the token for SW.
|
|
||||||
const token = localStorage.getItem('cinny_access_token') ?? undefined;
|
|
||||||
event.source!.postMessage({
|
|
||||||
responseKey: event.data.responseKey,
|
|
||||||
token,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const mountApp = () => {
|
const mountApp = () => {
|
||||||
const rootContainer = document.getElementById('root');
|
const rootContainer = document.getElementById('root');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue