hi Thunkable / Thunkers
Does anyone know if there are any plans to create a block that allows access to the time on the device?
I need to keep track of the time that a match has been running and the time needs to be displayed on screen in realtime. I know people suggested a workaround using a webapi call to timezonedb. While that works if time is needed occasionally, it is not workable for me to keep time of the match.
Here is what I did so far:
- when match starts, look up unix time in timezone db (=seconds since 1 jan 1970)
- store starttime
- set elapsed time to 0
- start timer with 1 sec interval, and when timer fires, increase elapsed time by 1
As long as the user stays on this screen, this works fine. But when a user leaves the screen (duh), or if app goes to the background or if screen locks, the timer does not fire anymore (which makes sense). So if this happens, the time goes out of sync. (as to be expected)
so, to work around this, i do the following:
- in screen open event, get time from timezonedb again
- get stored starttime
- calculate elapsed time by subtracting starttime from current time
- setup timer again, and increase elapsed time by 1 every time timer fires.
This works fine if a user navigates within the app and opens the stopwatch screen again.
HOWEVER: the open event does not fire when the app returns to foreground from background or when the device was locked and the user unlocks the device.
I found a dirty workaround for that, but I don’t find it really satisfying: although the timer component does not fire when the app is in the background, it does interrnally keep track of time. This means that for example if you set a timer with a 10 second interval, and the app goes to the background for more than 10 seconds, the timer will fire immediately if the app goes to the foreground again.
I used thin for the following workaround: I set a second timer with an interval of 15 secs (this is arbitrary). And every time that timer fires, I perform the same actions as in the open screen block. This way, if the app goes to the background and returns to the forground, at least the time is synced every 15 seconds.
It works, but is a dirty solution that involves a lot of api calls to timezonedb, so I am not happy with this solution.
So here comes my featurerequest:
please make the hardware clock available, because in that case the only action needed to keep the elapsed time is to subtract starttime from current time (no webapi calls).
Alternatively, i would also be helped if the elapsed time for a timer would be accessible. In that case you could just set a timer and see how many milliseconds are elapsed since the timer started.
Hope it is possble to include one. of these features in one of the next releases.
PS If you also need this kind of functionality, please leave a comment/reply to this post, so that the Thunkable team knows that more people need this. Hopefully it will get a higher priority then …