12-12-2017 10:27
12-12-2017 10:27
Hi,
Does anyone know how to determine whether the clockface is the 'active' / current application or not?
Many thanks.
Answered! Go to the Best Answer.
12-14-2017 08:06
12-14-2017 08:06
@Gondwana wrote:This matches my observations. You kinda get an on_start event because your code is completely re-run when the other app is closed. Plus, you only get ontick events while your clockface is running (but that doesn't help you with knowing when it's closing). I found it necessary to save any local state info as soon as the state was changed since you won't get notified when you need to do it. Then, that state info (if any) needs to be loaded when your clockface (re)starts.
I stumbled onto this snippet while searching -- might be a good place to save state instead of doing it every time state changes. I haven't tested it yet. Also, was trying to hook into load/ready events to help defer loading of things as they were slowing down load time, but the best I have now is a setInterval to a function with a bit of a delay to give the app time to load before being called.
import { me } from "appbit"; // register for the unload event me.onunload = () => { console.log("We're about to exit"); }
12-13-2017 06:23 - edited 12-13-2017 06:24
12-13-2017 06:23 - edited 12-13-2017 06:24
@SunsetRunner wrote:Hi,
Does anyone know how to determine whether the clockface is the 'active' / current application or not?
Many thanks.
The behavior I've been seeing while testing is that any time another app is opened, the clockface is closed. There might be an event you can hook to detect when closing -- maybe it's there and I'm missing it, but event/app lifecycle documentation would be helpful that detail all the events we can plug into.
The clockface doesn't seem to be closed when simply scrolling through the UI. Also, the clockface is relaunched when say exiting an app and going back to the menu, even if the clockface is not visible. (So, not exactly sure if there's a way to tell if it's visible, but if the clockface is running it seems another app is NOT.) Again, these are just observed behaviors.
12-13-2017 11:53
12-13-2017 11:53
This matches my observations. You kinda get an on_start event because your code is completely re-run when the other app is closed. Plus, you only get ontick events while your clockface is running (but that doesn't help you with knowing when it's closing). I found it necessary to save any local state info as soon as the state was changed since you won't get notified when you need to do it. Then, that state info (if any) needs to be loaded when your clockface (re)starts.
12-14-2017 08:06
12-14-2017 08:06
@Gondwana wrote:This matches my observations. You kinda get an on_start event because your code is completely re-run when the other app is closed. Plus, you only get ontick events while your clockface is running (but that doesn't help you with knowing when it's closing). I found it necessary to save any local state info as soon as the state was changed since you won't get notified when you need to do it. Then, that state info (if any) needs to be loaded when your clockface (re)starts.
I stumbled onto this snippet while searching -- might be a good place to save state instead of doing it every time state changes. I haven't tested it yet. Also, was trying to hook into load/ready events to help defer loading of things as they were slowing down load time, but the best I have now is a setInterval to a function with a bit of a delay to give the app time to load before being called.
import { me } from "appbit"; // register for the unload event me.onunload = () => { console.log("We're about to exit"); }