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) { 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,28 +969,39 @@ 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() {
var elapsed = (Date.now() - startTime) % CYCLE; try {
var t = elapsed / CYCLE; var elapsed = (Date.now() - startTime) % CYCLE;
var c = getColor(t); var t = elapsed / CYCLE;
c = applyWeatherTheme(c); var c = getColor(t);
effect.setOptions({ c = applyWeatherTheme(c);
skyColor: c.sky, effect.setOptions({
cloudColor: c.cloud, skyColor: c.sky,
lightColor: c.light, cloudColor: c.cloud,
backgroundColor: c.bg, lightColor: c.light,
backgroundAlpha: 0, backgroundColor: c.bg,
speed: currentThemeSpeed backgroundAlpha: 0,
}); speed: currentThemeSpeed
document.body.style.backgroundColor = '#' + ('00000' + c.sky.toString(16)).slice(-6); });
updateDebug(t, null, c, currentWeatherThemeName); 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); requestAnimationFrame(animate);
} }
function tick() { function tick() {
updateClockAndEvents(); try {
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>