2424 :timeout =" -1"
2525 >
2626 <span :class =" [settingsDarkMode && 'black--text']" >
27- {{ $t('settings.pwa.updateAvailable') }}
27+ {{
28+ $t(
29+ `settings.pwa.${
30+ updatePending ? 'updatePending' : 'updateAvailable'
31+ }`
32+ )
33+ }}
2834 </span >
2935 <template #action >
3036 <v-btn
37+ v-if =" !updatePending"
3138 small
3239 depressed
3340 block
3441 :color =" settingsDarkMode ? null : 'primary'"
35- @click =" $store.dispatch('app/ installUpdate') "
42+ @click =" installUpdate"
3643 >
3744 {{ $t('settings.pwa.installUpdate') }}
3845 </v-btn >
3946 </template >
4047 </v-snackbar >
48+ <script async defer data-website-id =" 4007fee1-66a9-4b46-92e7-8fed4a802139" data-domains =" www.transittracker.ca,transittracker.ca" data-cache =" true" src =" https://stats.felixinx.me/umami.js" ></script >
4149 </v-app >
4250</template >
4351
@@ -63,6 +71,7 @@ export default {
6371 mdiMenuDown,
6472 mdiTable,
6573 mdiViewGrid,
74+ workbox: null ,
6675 }),
6776 head () {
6877 return this .$nuxtI18nHead ({ addSeoAttributes: true })
@@ -141,6 +150,9 @@ export default {
141150 this .$store .commit (' app/set' , { key: ' openDownloadAssistant' , value })
142151 },
143152 },
153+ updatePending () {
154+ return this .$store .state .app .updatePending
155+ },
144156 },
145157 mounted () {
146158 this .checkForOldSettings ()
@@ -153,7 +165,7 @@ export default {
153165 // Set language only if defined
154166 if (this .settingsLang ) this .$i18n .setLocale (this .settingsLang )
155167
156- this .handleWorkboxEvents ()
168+ // this.handleWorkboxEvents()
157169
158170 // Install prompt
159171 window .addEventListener (' beforeinstallprompt' , (event ) => {
@@ -222,23 +234,36 @@ export default {
222234 },
223235 async handleWorkboxEvents () {
224236 // Workbox update
225- const workbox = await window .$workbox
237+ this . workbox = await window .$workbox
226238
227- if (! workbox) {
239+ if (! this . workbox ) {
228240 return
229241 }
230242
231- workbox .addEventListener (' installed' , (event ) => {
232- if (! event .isUpdate ) {
233- return
234- }
243+ // Occurs when the user accepts the update and the new SW is ready to take control
244+ this .workbox .addEventListener (' controlling' , () => {
245+ console .log (' WB Controlling' )
246+ window .location .reload ()
247+ })
235248
249+ // The new SW is installing but is waiting for activation
250+ this .workbox .addEventListener (' waiting' , (event ) => {
251+ console .log (' WB Waiting' )
236252 this .$store .commit (' app/set' , {
237253 key: ' updateAvailable' ,
238254 value: true ,
239255 })
240256 })
241257 },
258+ installUpdate () {
259+ console .log (' WB skip waiting' )
260+ this .$store .commit (' app/set' , {
261+ key: ' updatePending' ,
262+ value: true ,
263+ })
264+
265+ this .workbox .messageSkipWaiting ()
266+ },
242267 async verifyNotificationSubscriptionStatus () {
243268 try {
244269 await Notification .requestPermission ()
0 commit comments