Wrap UI updates in try/catch so errors don't break the animation

This commit is contained in:
Richard Zink committed 2026-10-07 10:25:47 +02:00
1 parent 1ba84cb9df
commit 1de3c68fc6
1 file changed
+15 -2
+15 -2
View File
@@ -930,6 +930,7 @@ var weatherThemes = {
} }
function updateDebug(t, palette, vantaColors, themeName) { function updateDebug(t, palette, vantaColors, themeName) {
try {
var now = new Date(); var now = new Date();
var hh = now.getHours(), mm = now.getMinutes(), ss = now.getSeconds(); var hh = now.getHours(), mm = now.getMinutes(), ss = now.getSeconds();
document.getElementById('dbg-time').textContent = document.getElementById('dbg-time').textContent =
@@ -968,9 +969,13 @@ var weatherThemes = {
document.getElementById(hid).textContent = '#' + ('00000' + vc.toString(16)).slice(-6); document.getElementById(hid).textContent = '#' + ('00000' + vc.toString(16)).slice(-6);
} }
} }
} catch (e) {
console.log('updateDebug error:', e);
}
} }
function animate() { function animate() {
try {
var elapsed = (Date.now() - startTime) % CYCLE; var elapsed = (Date.now() - startTime) % CYCLE;
var t = elapsed / CYCLE; var t = elapsed / CYCLE;
var c = getColor(t); var c = getColor(t);
@@ -985,11 +990,18 @@ var weatherThemes = {
}); });
document.body.style.backgroundColor = '#' + ('00000' + c.sky.toString(16)).slice(-6); document.body.style.backgroundColor = '#' + ('00000' + c.sky.toString(16)).slice(-6);
updateDebug(t, null, c, currentWeatherThemeName); updateDebug(t, null, c, currentWeatherThemeName);
} catch (e) {
console.log('animate error:', e);
}
requestAnimationFrame(animate); requestAnimationFrame(animate);
} }
function tick() { function tick() {
try {
updateClockAndEvents(); updateClockAndEvents();
} catch (e) {
console.log('tick error:', e);
}
setTimeout(tick, 1000); setTimeout(tick, 1000);
} }
@@ -1168,10 +1180,11 @@ var weatherThemes = {
} }
// Update weather every 15 minutes // Update weather every 15 minutes
animate();
tick();
fetchWeather(); fetchWeather();
setInterval(fetchWeather, 15 * 60 * 1000); setInterval(fetchWeather, 15 * 60 * 1000);
animate();
tick(); tick();
</script> </script>
</body> </body>