So I thought I had finished the code for my Pomodoro Clock until I realised that if you don’t have the window focussed then it doesn’t continue counting. I’m currently using p5.js which periodically updates within draw() (I’ve also used setInterval).
I’ve experimented by using Date.now() and calculating the difference, all sorts. But they all have the same issue that when you alt-tab away from the page then it stops.
I thought that if I could capture the event of the user changing window then I could just count the time between it and update it when they return, but that would mean the alarm still wouldn’t activate if you don’t focus the window.
Is this really that complicated to do? It feels like it shouldn’t be!
(Please open the link, the preview doesn’t seem to work :))
SOLVED, solution here:
I fixed the setInterval issue. Firefox and Chrome set intervals to a limit of 1000ms for when the window is not in focus. Therefore, if you adjust your code to work in 1000ms intervals (mine was 100ms) then it should be fine. For example I was -= 0.01 at 100ms, but changing it to 0.1 at 1000ms means the code now works just fine. (I think that was it, anyway :))