-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsugar.js
38 lines (36 loc) · 1.26 KB
/
sugar.js
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
/*!
* Sugar v0.1.0- Rapid web UI prototyping with no server
* https://github.com/calogxro/sugar
* Copyright (C) 2021 Calogero Miraglia <[email protected]>
* Licensed under GNU General Public License v3.0
* See file https://github.com/calogxro/sugar/LICENSE
*/
// Register the service worker
function sugar(callback) {
if ('serviceWorker' in navigator) {
if (navigator.serviceWorker.controller) {
//console.log("controller")
callback()
} else {
navigator.serviceWorker.oncontrollerchange = function() {
this.controller.onstatechange = function() {
if (this.state === 'activated') {
//console.log("onstatechange: activated")
callback()
}
}
}
navigator.serviceWorker.register('sweetness.js', {
scope: '/'
})
.then(function(reg) {
// registration worked
//console.log('Registration succeeded. Scope is ' + reg.scope)
})
.catch(function(error) {
// registration failed
//console.log('Registration failed with ' + error)
})
}
}
}