diff --git a/frontend/src/views/DiaryView.vue b/frontend/src/views/DiaryView.vue index 2ccc7da8..3779e5a7 100644 --- a/frontend/src/views/DiaryView.vue +++ b/frontend/src/views/DiaryView.vue @@ -2335,50 +2335,37 @@ export default { startCheckingTime() { if (this.timeChecker) clearInterval(this.timeChecker); + this.playedActivityMarks = []; this.timeChecker = setInterval(() => { - const currentTime = new Date().toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit', second: '2-digit' }); - // Zeit-Check Tick + const now = new Date(); + const currentTime = now.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit', second: '2-digit' }); + const currentHHMM = currentTime.slice(0, 5); if (!this.trainingStart || !this.trainingEnd) { return; } - let startCheckTime = this.trainingStart; - let endCheckTime = this.trainingEnd; - const startCheckTimeBlocks = startCheckTime.split(':'); - if (startCheckTimeBlocks.length < 3) { - startCheckTime = `${startCheckTime}:00`; - } - const endCheckTimeBlocks = endCheckTime.split(':'); - if (endCheckTimeBlocks.length < 3) { - endCheckTime = `${endCheckTime}:00`; - } - if (startCheckTime && currentTime === startCheckTime) { - this.playBellSound(); - } else if (endCheckTime && currentTime === endCheckTime) { - this.playBellSound(); - } else { - // Nach letzter Aktivität (Ende) nochmal Glocke - try { this.calculateAllItemTimes(); } catch (e) { } - const items = Array.isArray(this.trainingPlan) ? this.trainingPlan : []; - const lastItem = items.length ? items[items.length - 1] : null; - const lastEnd = lastItem && lastItem.endTime ? lastItem.endTime : null; - const lastEndSS = lastEnd ? (lastEnd.length === 5 ? lastEnd + ':00' : lastEnd) : null; - const lastEndMM = lastEndSS ? lastEndSS.slice(0, 5) : null; - const currentHHMM = currentTime.slice(0, 5); - if (lastEndSS && (currentTime === lastEndSS || (currentTime.endsWith(':00') && currentHHMM === lastEndMM))) { + + const bellTimes = [this.trainingStart, this.trainingEnd].filter(Boolean); + for (const bellTime of bellTimes) { + const key = `bell:${bellTime}`; + if (currentHHMM === bellTime && !this.playedActivityMarks.includes(key)) { this.playBellSound(); + this.playedActivityMarks.push(key); } } - // Aktivitätszeiten (Startzeiten) aus Trainingsplan prüfen + try { this.calculateAllItemTimes(); } catch (e) { } const items = Array.isArray(this.trainingPlan) ? this.trainingPlan : []; - const startTimesSS = items - .map(it => (it && it.startTime ? (it.startTime.length === 5 ? it.startTime + ':00' : it.startTime) : null)) + const startTimes = items + .map(it => (it && it.startTime ? it.startTime.slice(0, 5) : null)) .filter(Boolean); - const startTimesMM = startTimesSS.map(t => t.slice(0, 5)); - const currentHHMM = currentTime.slice(0, 5); - const isMatch = startTimesSS.includes(currentTime) || (currentTime.endsWith(':00') && startTimesMM.includes(currentHHMM)); - if (isMatch) { - this.playThumbSound(); + + for (const startTime of startTimes) { + if (startTime === this.trainingStart) continue; + const key = `thumb:${startTime}`; + if (currentHHMM === startTime && !this.playedActivityMarks.includes(key)) { + this.playThumbSound(); + this.playedActivityMarks.push(key); + } } }, 1000); }, @@ -2386,7 +2373,11 @@ export default { playBellSound() { if (!this.soundEnabled) return; try { - this.bellSound && this.bellSound.play(); + if (this.bellSound) { + this.bellSound.pause(); + this.bellSound.currentTime = 0; + this.bellSound.play(); + } } catch (e) { // ignore } @@ -2395,7 +2386,11 @@ export default { playThumbSound() { if (!this.soundEnabled) return; try { - this.thumbSound && this.thumbSound.play(); + if (this.thumbSound) { + this.thumbSound.pause(); + this.thumbSound.currentTime = 0; + this.thumbSound.play(); + } } catch (e) { // ignore }