Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: installed pwa does not pick up new version, closes #298 #324

Merged
merged 2 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/AppFrame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@
</v-container>
</v-content>

<v-footer app>
<!-- -->
<v-footer
app
inset
>
<update-notification class="mx-auto" />
</v-footer>
</v-app>
</template>
Expand All @@ -178,10 +181,12 @@ import { mapState } from 'vuex'
import {
PEER_CONNECTED
} from '@/store/mutation-types'
import UpdateNotification from './UpdateNotification'

export default {
name: 'AppFrame',
components: {
UpdateNotification
},
props: {
},
Expand Down
43 changes: 43 additions & 0 deletions src/components/UpdateNotification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<v-alert
v-if="updateToBeInstalled"
dense
type="info"
>
<v-row align="center">
<v-col class="grow">
A new version is available
</v-col>
<v-col class="shrink">
<v-btn @click="refresh">
refresh
</v-btn>
</v-col>
</v-row>
</v-alert>
</template>

<script>
import { mapState } from 'vuex'

export default {
name: 'UpdateNotification',
computed: {
...mapState({
updateToBeInstalled: state => state.updateToBeInstalled
})
},
methods: {
refresh () {
this.updateToBeInstalled.postMessage(
{ type: 'SKIP_WAITING' }
)
window.location.reload()
}
}
}
</script>

<style scoped>

</style>
6 changes: 5 additions & 1 deletion src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import { register } from 'register-service-worker'

import store from './store/index'
import { UPDATE_AVAILABLE } from './store/mutation-types'

if (process.env.NODE_ENV === 'production') {
register(`${process.env.BASE_URL}service-worker.js`, {
ready () {
Expand All @@ -13,7 +16,8 @@ if (process.env.NODE_ENV === 'production') {
cached () {
console.log('Content has been cached for offline use.')
},
updated () {
updated (reg) {
store.commit(UPDATE_AVAILABLE, reg.waiting)
console.log('New content is available; please refresh.')
},
offline () {
Expand Down
5 changes: 5 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import Vue from 'vue'
import Vuex from 'vuex'
import PNPStore from './pnp.js'
import { INITIALIZE_PNP } from './action-types.js'
import { UPDATE_AVAILABLE } from './mutation-types'

Vue.use(Vuex)

const store = new Vuex.Store({
state: {
updateToBeInstalled: undefined,
version: require('@/../package.json').version
},
mutations: {
[UPDATE_AVAILABLE] (state, updateToBeInstalled) {
state.updateToBeInstalled = updateToBeInstalled
}
},
actions: {
},
Expand Down
2 changes: 2 additions & 0 deletions src/store/mutation-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export const NEW_PEER_ID = 'NEW_PEER_ID'
export const NEW_REMOTE_PEER_ID = 'NEW_REMOTE_PEER_ID'
export const REMOTE_PEER_ID_REMOVED = 'REMOTE_PEER_ID_REMOVED'
export const PEER_FETCH = 'PEER_FETCH'

export const UPDATE_AVAILABLE = 'UPDATE_AVAILABLE'
14 changes: 14 additions & 0 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@
</v-card-actions>
</v-card>
</v-row>
<v-row class="mt-4">
<update-notification class="mx-auto" />
</v-row>
</v-container>
</v-content>
</v-app>
</template>

<script>
import UpdateNotification from '../components/UpdateNotification'

export default {
name: 'Home',
components: {
UpdateNotification
}
}
</script>