mirror of https://github.com/coder/code-server.git
refactor: create registerServiceWorker fn
This commit is contained in:
parent
28b440a4ba
commit
72b05cacac
|
@ -1,18 +1,23 @@
|
||||||
import { getOptions, normalize } from "../common/util"
|
import { getOptions, Options, normalize } from "../common/util"
|
||||||
|
|
||||||
const options = getOptions()
|
|
||||||
|
|
||||||
import "./pages/error.css"
|
import "./pages/error.css"
|
||||||
import "./pages/global.css"
|
import "./pages/global.css"
|
||||||
import "./pages/login.css"
|
import "./pages/login.css"
|
||||||
|
|
||||||
if ("serviceWorker" in navigator) {
|
export async function registerServiceWorker(navigator: Navigator, path: string, options: Options): Promise<void> {
|
||||||
const path = normalize(`${options.csStaticBase}/dist/serviceWorker.js`)
|
try {
|
||||||
navigator.serviceWorker
|
await navigator.serviceWorker.register(path, {
|
||||||
.register(path, {
|
|
||||||
scope: (options.base ?? "") + "/",
|
scope: (options.base ?? "") + "/",
|
||||||
})
|
})
|
||||||
.then(() => {
|
console.log("[Service Worker] registered")
|
||||||
console.log("[Service Worker] registered")
|
} catch (error) {
|
||||||
})
|
console.error(`[Service Worker] failed to register: ${error.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof navigator !== "undefined" && "serviceWorker" in navigator) {
|
||||||
|
const options = getOptions()
|
||||||
|
const path = normalize(`${options.csStaticBase}/dist/serviceWorker.js`)
|
||||||
|
registerServiceWorker(navigator, path, options)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue