Skip to content

Commit 6790879

Browse files
Kevin Tamglorat
authored andcommitted
fix: pwa site refresh
1 parent 02daa7b commit 6790879

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

quasar.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = configure(function (/* ctx */) {
6060
node: 'node16'
6161
},
6262

63-
vueRouterMode: 'hash', // available values: 'hash', 'history'
63+
vueRouterMode: 'history', // available values: 'hash', 'history'
6464
// vueRouterBase,
6565
// vueDevtools,
6666
// vueOptionsAPI: false,

src-pwa/register-service-worker.ts

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { register } from 'register-service-worker';
2+
import {Notify} from 'quasar'
3+
import {mdiCached} from '@quasar/extras/mdi-v7';
4+
5+
6+
const forceNotify = false;
27

38
// The ready(), registered(), cached(), updatefound() and updated()
49
// events passes a ServiceWorkerRegistration instance in their arguments.
@@ -12,30 +17,62 @@ register(process.env.SERVICE_WORKER_FILE, {
1217
// registrationOptions: { scope: './' },
1318

1419
ready (/* registration */) {
15-
// console.log('Service worker is active.')
20+
if (forceNotify || process.env.DEV) {
21+
Notify.create('App is being served from cache by a service worker.')
22+
}
1623
},
1724

1825
registered (/* registration */) {
19-
// console.log('Service worker has been registered.')
26+
if (forceNotify || process.env.DEV) {
27+
Notify.create('Service worker has been registered.')
28+
}
2029
},
2130

2231
cached (/* registration */) {
23-
// console.log('Content has been cached for offline use.')
32+
if (forceNotify || process.env.DEV) {
33+
Notify.create('Content has been cached for offline use.')
34+
}
2435
},
2536

2637
updatefound (/* registration */) {
27-
// console.log('New content is downloading.')
38+
if (forceNotify || process.env.DEV) {
39+
Notify.create('An update to this app is downloading.')
40+
}
41+
console.log('An update to this app is downloading')
2842
},
2943

3044
updated (/* registration */) {
3145
// console.log('New content is available; please refresh.')
46+
Notify.create({
47+
color: 'negative',
48+
icon: mdiCached,
49+
message: 'App has been updated. Please refresh the page.',
50+
timeout: 0,
51+
multiLine: true,
52+
position: 'top',
53+
actions: [
54+
{
55+
label: 'Refresh',
56+
color: 'yellow',
57+
handler: () => {
58+
window.location.reload()
59+
}
60+
},
61+
{
62+
label: 'Dismiss',
63+
color: 'white',
64+
handler: () => {
65+
}
66+
}
67+
]
68+
})
3269
},
3370

3471
offline () {
35-
// console.log('No internet connection found. App is running in offline mode.')
72+
Notify.create('No internet connection found. App is running in offline mode.')
3673
},
3774

38-
error (/* err */) {
39-
// console.error('Error during service worker registration:', err)
75+
error ( err ) {
76+
Notify.create('Error during service worker registration:' + err)
4077
},
4178
});

0 commit comments

Comments
 (0)