forked from MapComplete/MapComplete
Feature: add online indicator
This commit is contained in:
parent
efeb5ae1d9
commit
76dbf50db1
3 changed files with 44 additions and 0 deletions
21
scripts/prepareServiceWorker.ts
Normal file
21
scripts/prepareServiceWorker.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import Script from "./Script"
|
||||||
|
import Constants from "../src/Models/Constants"
|
||||||
|
import { writeFileSync } from "fs"
|
||||||
|
|
||||||
|
class PrepareServiceWorker extends Script {
|
||||||
|
constructor() {
|
||||||
|
super("Super various little jobs to help the service worker")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async main() {
|
||||||
|
const v = Constants.vNumber
|
||||||
|
writeFileSync("./src/service-worker/SWGenerated.ts",
|
||||||
|
["export class SWGenerated {",
|
||||||
|
"// generated by scripts/prepareServiceWorker.ts",
|
||||||
|
"static vNumber = " + JSON.stringify(v), "}"].join("\n")
|
||||||
|
, "utf8")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new PrepareServiceWorker().run()
|
19
src/Logic/Web/IsOnline.ts
Normal file
19
src/Logic/Web/IsOnline.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { Store, UIEventSource } from "../UIEventSource"
|
||||||
|
|
||||||
|
export class IsOnline {
|
||||||
|
private static readonly _isOnline: UIEventSource<boolean> = new UIEventSource(navigator.onLine)
|
||||||
|
static {
|
||||||
|
|
||||||
|
window.addEventListener("online", () => {
|
||||||
|
IsOnline._isOnline.set(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
window.addEventListener("offline", () => {
|
||||||
|
IsOnline._isOnline.set(false)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly isOnline: Store<boolean> = IsOnline._isOnline
|
||||||
|
|
||||||
|
}
|
4
src/service-worker/SWGenerated.ts
Normal file
4
src/service-worker/SWGenerated.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export class SWGenerated {
|
||||||
|
// generated by scripts/prepareServiceWorker.ts
|
||||||
|
static vNumber = "0.54.4"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue