Is there anyway to keep persistent, global variables? #7740
-
Lets say i want to count each touch across all apps. Is there a way to do this with a boot script and a "global variable"? Every time i open a new app, the "global" keyword and everything else is getting reset and the counter is set to 0. Is there something which is persistent across apps? Do i have to use storage for this or is there a more practical way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm afraid Storage is the only way, but you can store in RAM and then write to Storage in If you're going between apps that support 'fast load' then the JS instance won't be torn down between either - so for instance flipping between the default clock/launcher and then loading the first app your code will stay running - it's just when you exit that app (if it doesn't support fast load, which most don't) that you'd have to write to storage Persistent Storage is something that has been requested and it might get added at some point, but restarting from scratch for each app was a very deliberate choice - because anyone can submit apps, they tend to be of variable quality. Restarting from scratch for each app makes it far less likely that a bug in one app could cause Bangle.js as a whole to behave unreliably |
Beta Was this translation helpful? Give feedback.
I'm afraid Storage is the only way, but you can store in RAM and then write to Storage in
E.on("kill", function() { ... })
to reduce the file writes performed.If you're going between apps that support 'fast load' then the JS instance won't be torn down between either - so for instance flipping between the default clock/launcher and then loading the first app your code will stay running - it's just when you exit that app (if it doesn't support fast load, which most don't) that you'd have to write to storage
Persistent Storage is something that has been requested and it might get added at some point, but restarting from scratch for each app was a very deliberate choice - because anyone can…