Update sleeptimer.js

This commit is contained in:
simonpipe 2025-12-18 22:19:00 +01:00
parent ba79b2429a
commit ace00afe19

View file

@ -1,14 +1,14 @@
// sleeptimer.js - Verwaltet die automatische Abschaltung
// sleeptimer.js - Verwaltet die automatische Abschaltung und Restzeitanzeige
window.SleepTimer = {
timeoutId: null,
endTime: null,
onExpiry: null, // Callback-Funktion, die bei Ablauf gerufen wird
onExpiry: null,
init(onExpiryCallback) {
this.onExpiry = onExpiryCallback;
},
start(minutes) {
setTimer(minutes) {
this.clear();
const durationMs = minutes * 60000;
this.endTime = Date.now() + durationMs;
@ -36,22 +36,22 @@ window.SleepTimer = {
if (this.endTime) {
const remaining = Math.max(0, Math.ceil((this.endTime - Date.now()) / 60000));
// Anzeige mit Icon und Restzeit
btn.innerHTML = `<i class="fas fa-hourglass-half"></i> ${remaining} Min`;
// Alle 10 Sekunden die Anzeige aktualisieren
setTimeout(() => this.updateButtonUI(), 10000);
// Selbst-Aktualisierung alle 10 Sekunden (nur wenn Timer aktiv)
if (this.timeoutId) {
setTimeout(() => this.updateButtonUI(), 10000);
}
} else {
btn.textContent = 'Sleep Timer';
// Standard-Text wenn kein Timer läuft
btn.textContent = 'Sleeptimer';
}
// Den "Aus"-Button im Modal steuern
// Den "Timer aus"-Button im Modal zeigen/verstecken
const offBtn = document.getElementById('off-sleep-timer-modal');
if (offBtn) {
offBtn.style.display = this.timeoutId ? 'inline-block' : 'none';
}
},
isActive() {
return this.timeoutId !== null;
}
};