From c844101d7d31e83f7b70b0d53a5afe828eb27680 Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Mon, 16 Mar 2020 12:05:16 +0100 Subject: [PATCH] improve countdown time handling #1 --- app/src/App.vue | 9 ++++++++- app/src/components/ScreenCard.vue | 30 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/src/App.vue b/app/src/App.vue index 6d06c2d..9993820 100644 --- a/app/src/App.vue +++ b/app/src/App.vue @@ -116,11 +116,18 @@ methods: { autoReloadStats () { apiDevice.getStats(stats => { + // give esp some extra time befor fetch new data + stats.playlist.remaining += 2 + + // reset old so reactive watcher can detect a change + if (this.$root._data.stats) { + this.$root._data.stats.playlist.remaining = 0 + } this.$root._data.stats = stats setTimeout(() => { this.autoReloadStats() - }, (stats.playlist.remaining + 2) * 1000) + }, stats.playlist.remaining * 1000) }) } } diff --git a/app/src/components/ScreenCard.vue b/app/src/components/ScreenCard.vue index e4d0aad..94f3dca 100644 --- a/app/src/components/ScreenCard.vue +++ b/app/src/components/ScreenCard.vue @@ -32,23 +32,23 @@ - - + + --> - - $settings - + + $settings + { + if (this.playlistRemainingCountdown > 0) { + this.playlistRemainingCountdown--; + } + }, 1000); }, computed: { playlistProgress() { @@ -84,15 +90,9 @@ export default { }, watch: { playlistRemaining(val) { - this.playlistRemainingCountdown = val; - this.device_screen_src = "/current-image?" + Date.now(); - }, - - playlistRemainingCountdown(val) { if (val > 0) { - setTimeout(() => { - this.playlistRemainingCountdown--; - }, 1000); + this.playlistRemainingCountdown = val; + this.device_screen_src = "/current-image?" + Date.now(); } } }