BUGFIX: clear interval on exit

This commit is contained in:
Jeroen De Meerleer 2021-05-05 13:39:13 +02:00
parent 6f1a98f65a
commit 9514e4b9fb

View File

@ -66,7 +66,6 @@
</template> </template>
<script> <script>
var Interval;
export default { export default {
name: "Timer", name: "Timer",
props: { props: {
@ -79,6 +78,7 @@ export default {
warning: true, warning: true,
danger: false, danger: false,
wakeLock: null, wakeLock: null,
interval: null,
sfxTimeout: this.playsound ? new Audio('sfx/timeout.wav') : null, sfxTimeout: this.playsound ? new Audio('sfx/timeout.wav') : null,
sfxWarning: this.playsound ? new Audio('sfx/warning.wav') : null, sfxWarning: this.playsound ? new Audio('sfx/warning.wav') : null,
sfxNext: this.playsound ? new Audio('sfx/next.wav') : null, sfxNext: this.playsound ? new Audio('sfx/next.wav') : null,
@ -86,6 +86,7 @@ export default {
}, },
methods: { methods: {
resetTime: function() { resetTime: function() {
clearInterval(this.interval);
this.$emit('set-time', 0); this.$emit('set-time', 0);
}, },
timeleft: function(){ timeleft: function(){
@ -128,7 +129,7 @@ export default {
if(this.playsound) { if(this.playsound) {
this.sfxTimeout.play(); this.sfxTimeout.play();
} }
clearInterval(Interval); clearInterval(this.interval);
break; break;
} }
}, },
@ -142,8 +143,8 @@ export default {
this.countDown = this.time; this.countDown = this.time;
this.warning = false; this.warning = false;
this.danger = false; this.danger = false;
clearInterval(Interval); clearInterval(this.interval);
Interval = setInterval(() => { this.interval = setInterval(() => {
this.timeleft() this.timeleft()
}, 1000); }, 1000);
}, },