-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path_intro.js
More file actions
63 lines (54 loc) · 1.71 KB
/
_intro.js
File metadata and controls
63 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*global */
const IS_LOCALHOST = window.location.href.indexOf("localhost") > -1
const USE_SW = !IS_LOCALHOST
const contentEl = document.querySelector(".content-skeleton")
let isFirstInstall = navigator.serviceWorker.controller == null
let modal = null
function showReloadModal() {
if (modal == null) {
modal = document.createElement("div")
document.body.appendChild(modal)
modal.style.position = "absolute"
modal.style.outline = "1px solid black"
modal.style.right = "10px"
modal.style.bottom = "10px"
modal.style.padding = "10px"
modal.style.backgroundColor = "#fff"
}
modal.innerHTML = `
<div style='width: 230px; height: 20px; font-family: Georgia;'>
New version available! <button onclick="location.reload()">Reload</button>
</div>
`
}
;(async () => {
try {
// SW
if (USE_SW) {
contentEl.innerHTML = "Checking service-worker..."
console.time("loading:sw")
// start sw handling
navigator.serviceWorker.addEventListener("controllerchange", () => {
if (isFirstInstall) {
isFirstInstall = false
} else {
showReloadModal()
}
})
const reg = await navigator.serviceWorker.register("/sw.js")
await navigator.serviceWorker.ready
// start sw check
setInterval(() => reg.update(), IS_LOCALHOST ? 3 * 1000 : 5 * 60 * 1000)
console.timeEnd("loading:sw")
contentEl.innerHTML = ""
}
// Plugin namespace
window.NEPlugins = {}
console.time("loading:main")
await import(/* webpackIgnore: true */ "./main.js")
console.timeEnd("loading:main")
} catch (e) {
// TODO: Show restore guide
contentEl.textContent = "Something wrong: " + e.message
}
})()