Skip to content

Commit

Permalink
Merge pull request #9 from moomoolive/pwaBugFixes
Browse files Browse the repository at this point in the history
fixed service worker registration issue
  • Loading branch information
moomoolive authored Mar 21, 2021
2 parents 240487f + 1d14219 commit 8a0b11b
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion code/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint",
"pwa": "npm run build && serve dist -l 1239"
"pwa": "npm run build && serve dist -l 1240"
},
"dependencies": {
"@ivanv/vue-collapse-transition": "^1.0.0",
Expand Down
1 change: 1 addition & 0 deletions code/client/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Vue from 'vue'
import Main from './Main.vue'
import router from './router'
import store from './store'
import './registerServiceWorker.js'

import API from '@/libraries/requests/index.js'
import funcs from '@/libraries/globalUtilities.js'
Expand Down
Binary file added code/client/src/assets/gifs/confusedDino.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion code/client/src/components/footer/popup/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default {
methods: {
close() {
this.$store.commit('footerPopup/close')
},
closeAfter(seconds=4) {
const milliSecondsInASecond = 1_000
window.setTimeout(() => this.close() , seconds * milliSecondsInASecond)
}
},
computed: {
Expand All @@ -35,7 +39,11 @@ export default {
},
backgroundColor() {
return this.componentsInfo.componentsProps.color || 'blue'
}
},
},
created() {
if (this.componentsInfo.componentsProps.closeAfter)
this.closeAfter(this.componentsInfo.componentsProps.closeAfter)
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ p {
&:hover {
background-color: lighten(themeRGBA("darkBlue", 1), 20%);
}
&.profile-info {
background-color: getColor("silver");
font-size: 13px;
}
}
@media screen and (max-width: $phoneWidth) {
Expand Down
16 changes: 15 additions & 1 deletion code/client/src/libraries/footerPopup/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ const appWillUpdateMessage = () => {
)
}

const youAreOffline = () => {
helpers.createFooterPopup(
'statusUpdate',
{
gif: 'confusedDino',
color: 'blue',
topMessage: "You're offline",
bottomMessage: "Some features are unavailable" ,
closeAfter: 4
}
)
}

export default {
appWillUpdateMessage
appWillUpdateMessage,
youAreOffline
}
18 changes: 9 additions & 9 deletions code/client/src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ if (process.env.NODE_ENV === 'production') {
'For more details, visit https://goo.gl/AFskqB'
)
},
registered () {
console.log('Service worker has been registered.')
registered() {
console.log('New service worker has been registered.')
},
cached () {
cached() {
console.log('Content has been cached for offline use.')
},
updatefound () {
updatefound() {
console.log('New content is downloading.')
},
updated (registration) {
console.log('New content is available; please refresh.')
updated(registration) {
footerPopups.appWillUpdateMessage()
const threeSecondsInMilliseconds = 3_000
window.setTimeout(() => registration.waiting.postMessage({ action: 'skipWaiting' }) , threeSecondsInMilliseconds)
},
offline () {
offline() {
console.log('No internet connection found. App is running in offline mode.')
footerPopups.youAreOffline()
},
error (error) {
error(error) {
console.error('Error during service worker registration:', error)
}
})
Expand All @@ -41,4 +41,4 @@ if (process.env.NODE_ENV === 'production') {
refreshing = true
window.location.reload()
})
}
}
10 changes: 2 additions & 8 deletions code/client/src/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
console.log('service-worker registered')

workbox.core.setCacheNameDetails({prefix: "khateebRemind"});
workbox.core.setCacheNameDetails({ prefix: "khateebRemind" });

self.__precacheManifest = [].concat(self.__precacheManifest || [])
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
Expand All @@ -10,8 +8,4 @@ self.addEventListener("message", msg => {
if (msg.data.action === 'skipWaiting') {
self.skipWaiting()
}
})



//self.clientsClaim();
})
3 changes: 3 additions & 0 deletions code/client/src/store/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export default {
const decodedPayload = window.atob(tokenPayload)
return JSON.parse(decodedPayload)
},
fullName(state, { allInfo }) {
return `${allInfo.firstName} ${allInfo.lastName}`
},
validAuthentication(state, { isLoggedIn, allInfo: { exp: tokenExpirationInSeconds } }) {
if (!isLoggedIn)
return false
Expand Down
10 changes: 7 additions & 3 deletions code/client/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ module.exports = {
},
pwa: {
name: 'Khateeb Remind',
themeColor: "#4DBA87",
msTileColor: "#4DBA87",
appleMobileWebAppCache: "no",
manifestOptions: {
background_color: "#000000"
},
workboxPluginMode: 'InjectManifest',
workboxOptions: {
//skipWaiting: true,
//clientsClaim: true
swSrc: 'src/service-worker.js',
//swDest: 'service-worker.js'
swDest: "service-worker.js"
}
}
}

0 comments on commit 8a0b11b

Please sign in to comment.