08-10-2021 01:18
08-10-2021 01:18
Is there a way that I can trigger a routine on the watch face one every 24 hours, the first time the user opens up the watch after midnight? It only needs to be run once per day.
08-10-2021 01:28
08-10-2021 01:28
Yes. Keep track of the date at which the routine last ran, and compare the current date with that. When they're different, run the routine again and update the last-run date.
For efficiency, it might be best not to do this every second if you can conveniently avoid it.
Also be careful to consider what happens when your app starts.
08-10-2021 06:32
08-10-2021 06:32
@jaystarkey Yon can use setInterval() to trigger an event in 24 hours time from a specific time.
Author | ch, passion for improvement.
08-10-2021 10:47
08-10-2021 10:47
This makes sense - what is the best way to store the date last ran value? I'm new to development and not sure what persists/how to access persistent data.
08-10-2021 10:49
08-10-2021 10:49
Put it in app/index.js?
How would I get this to trigger only at 00:00 every day?
//run once every x hours
let numHours = 24;
setInterval(function(){ doStuff(); }, 1000 * 60 * 60 * numHours);
08-10-2021 13:16
08-10-2021 13:16
You can use the fs API to keep track of dateLastRun.
Be careful using setTimeout for this. Timers will be killed whenever the user starts another app (eg, Settings), so your special function may never run.
Also be careful about checking for an exact time. Your clockface might not be running at that exact time.