@@ -11,13 +11,17 @@ export default function registerServiceWorker(router: Router) {
1111 // Display a message while updating the service worker
1212 const { displaySnackbar } = useSnackbarStore ( )
1313 displaySnackbar ( 'Posodabljanje ...' )
14+
15+ // Mark that we need to update the service worker
1416 immediatelyUpdate = true
1517 }
1618
1719 if ( searchParams . has ( 'updating' ) ) {
1820 // Display a success message if the app was updated
1921 const { displaySnackbar } = useSnackbarStore ( )
2022 displaySnackbar ( 'Aplikacija posodobljena' )
23+
24+ // Hide the parameter after the app was updated
2125 router . replace ( location . pathname )
2226 }
2327
@@ -40,20 +44,29 @@ export default function registerServiceWorker(router: Router) {
4044
4145 onNeedRefresh ( ) {
4246 if ( immediatelyUpdate ) {
43- // Update the service worker immediately if requested
4447 console . log ( 'Update parameter detected, updating the service worker...' )
48+
49+ // Update the service worker immediately if requested
4550 performUpdate ( )
4651 } else {
47- // Prompt the user to update the service worker
4852 console . log ( 'New content is available, prompting the user to refresh...' )
53+
54+ // Prompt the user to update the service worker
4955 const { displaySnackbar } = useSnackbarStore ( )
5056 displaySnackbar ( 'Na voljo je posodobitev' , 'Posodobi' , performUpdate , - 1 )
5157 }
5258 } ,
5359 } )
5460
5561 const performUpdate = async ( ) => {
56- await router . replace ( { path : location . pathname , query : { updating : 1 } } )
62+ // Display a message while updating the service worker
63+ const { displaySnackbar } = useSnackbarStore ( )
64+ displaySnackbar ( 'Posodabljanje ...' )
65+
66+ // Add query parameter so we know the app was updated
67+ history . replaceState ( history . state , '' , location . pathname + '?updating=1' )
68+
69+ // Update the service worker
5770 await updateSW ( )
5871 }
5972}
0 commit comments