stop polling widget content when document is hidden

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Julien Veyssier 2021-06-24 13:29:57 +02:00
parent d4f1abe3e2
commit 9fd4a6ab34
No known key found for this signature in database
GPG key ID: 4141FEE162030638

View file

@ -54,6 +54,7 @@ export default {
state: 'loading',
settingsUrl: generateUrl('/settings/user/connected-accounts'),
themingColor: OCA.Theming ? OCA.Theming.color.replace('#', '') : '0082C9',
windowVisibility: true,
}
},
@ -112,14 +113,35 @@ export default {
},
},
watch: {
windowVisibility(newValue) {
if (newValue) {
this.launchLoop()
} else {
this.stopLoop()
}
},
},
beforeDestroy() {
document.removeEventListener('visibilitychange', this.changeWindowVisibility)
},
beforeMount() {
this.launchLoop()
document.addEventListener('visibilitychange', this.changeWindowVisibility)
},
mounted() {
},
methods: {
changeWindowVisibility() {
this.windowVisibility = !document.hidden
},
stopLoop() {
clearInterval(this.loop)
},
async launchLoop() {
// get moodle URL first
try {