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 = { window.SleepTimer = {
timeoutId: null, timeoutId: null,
endTime: null, endTime: null,
onExpiry: null, // Callback-Funktion, die bei Ablauf gerufen wird onExpiry: null,
init(onExpiryCallback) { init(onExpiryCallback) {
this.onExpiry = onExpiryCallback; this.onExpiry = onExpiryCallback;
}, },
start(minutes) { setTimer(minutes) {
this.clear(); this.clear();
const durationMs = minutes * 60000; const durationMs = minutes * 60000;
this.endTime = Date.now() + durationMs; this.endTime = Date.now() + durationMs;
@ -36,22 +36,22 @@ window.SleepTimer = {
if (this.endTime) { if (this.endTime) {
const remaining = Math.max(0, Math.ceil((this.endTime - Date.now()) / 60000)); 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`; btn.innerHTML = `<i class="fas fa-hourglass-half"></i> ${remaining} Min`;
// Alle 10 Sekunden die Anzeige aktualisieren // Selbst-Aktualisierung alle 10 Sekunden (nur wenn Timer aktiv)
if (this.timeoutId) {
setTimeout(() => this.updateButtonUI(), 10000); setTimeout(() => this.updateButtonUI(), 10000);
}
} else { } 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'); const offBtn = document.getElementById('off-sleep-timer-modal');
if (offBtn) { if (offBtn) {
offBtn.style.display = this.timeoutId ? 'inline-block' : 'none'; offBtn.style.display = this.timeoutId ? 'inline-block' : 'none';
} }
},
isActive() {
return this.timeoutId !== null;
} }
}; };