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
+30 -17
+30 -17
View File
@@ -930,6 +930,7 @@ var weatherThemes = {
}
function updateDebug(t, palette, vantaColors, themeName) {
try {
var now = new Date();
var hh = now.getHours(), mm = now.getMinutes(), ss = now.getSeconds();
document.getElementById('dbg-time').textContent =
@@ -968,28 +969,39 @@ var weatherThemes = {
document.getElementById(hid).textContent = '#' + ('00000' + vc.toString(16)).slice(-6);
}
}
} catch (e) {
console.log('updateDebug error:', e);
}
}
function animate() {
var elapsed = (Date.now() - startTime) % CYCLE;
var t = elapsed / CYCLE;
var c = getColor(t);
c = applyWeatherTheme(c);
effect.setOptions({
skyColor: c.sky,
cloudColor: c.cloud,
lightColor: c.light,
backgroundColor: c.bg,
backgroundAlpha: 0,
speed: currentThemeSpeed
});
document.body.style.backgroundColor = '#' + ('00000' + c.sky.toString(16)).slice(-6);
updateDebug(t, null, c, currentWeatherThemeName);
try {
var elapsed = (Date.now() - startTime) % CYCLE;
var t = elapsed / CYCLE;
var c = getColor(t);
c = applyWeatherTheme(c);
effect.setOptions({
skyColor: c.sky,
cloudColor: c.cloud,
lightColor: c.light,
backgroundColor: c.bg,
backgroundAlpha: 0,
speed: currentThemeSpeed
});
document.body.style.backgroundColor = '#' + ('00000' + c.sky.toString(16)).slice(-6);
updateDebug(t, null, c, currentWeatherThemeName);
} catch (e) {
console.log('animate error:', e);
}
requestAnimationFrame(animate);
}
function tick() {
updateClockAndEvents();
try {
updateClockAndEvents();
} catch (e) {
console.log('tick error:', e);
}
setTimeout(tick, 1000);
}
@@ -1168,10 +1180,11 @@ var weatherThemes = {
}
// Update weather every 15 minutes
animate();
tick();
fetchWeather();
setInterval(fetchWeather, 15 * 60 * 1000);
animate();
tick();
</script>
</body>