11import { 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