08-10-2021 01:18
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-10-2021 01:18
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-10-2021 01:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

08-10-2021 06:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-10-2021 06:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-10-2021 10:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-10-2021 10:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-10-2021 13:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

