From 9fd4a6ab34e2cf5a4b320e5b5ce2abc632c9ed37 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 24 Jun 2021 13:29:57 +0200 Subject: [PATCH] stop polling widget content when document is hidden Signed-off-by: Julien Veyssier --- src/views/Dashboard.vue | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index 6254503..0deb3bb 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -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 {