-
Notifications
You must be signed in to change notification settings - Fork 138
Inconsistant state of controls / onlaunch not working. #188
Description
On my remote I have a label above some buttons. Tapping the label toggles its text and colour, and sets a boolean that alters what the following buttons do. If the label says "Surround With" the following buttons, If, Foreach, While etc send codes to my IDE to surround the highlighted text with the appropriate code. If the label says "Code Block" the following buttons just insert the corresponding code block. The colour of the label changes along with the text to make it obvious what the state of the remote is.
All works fine. But if I press the back button, to use a different remote, and then later come back to my remote, the boolean value is as it was left, the colour is as it was left, but the text is always what is in the layout file, and not what it was left as. This can lead to an inconsistent
text / colour combination.
I thought an onlaunch callback would solve this, but onlaunch is not being triggered when I start the remote. I put a log statement in, and nothing shows.
There is a bug in that the text is being reset, but more importantly onlaunch is not working.
local swmode = true;
actions.launch = function ()
local log = require("log");
log.info("launched");
-- text of label is reset when resumed, but colour isn't. But to future proof do both.
layout.togglesw.text = "Surround With";
layout.togglesw.color = "#5f9ea0";
swmode = true;
end
actions.togglesw = function()
swmode = not swmode;
if swmode then
layout.togglesw.text = "Surround With";
layout.togglesw.color = "#5f9ea0";
else
layout.togglesw.text = "Code block";
layout.togglesw.color = "#89cff0";
end
end
actions.sw = function(shortcut, template)
if swmode then
<layout orientation="portrait" onlaunch="launch">
<tabs>
<tab text="General" color="#3682b3">
<row weight="1"><label id="togglesw" text="Surround With" ontap="togglesw" color="#5f9ea0"/></row>
<row weight="3">
<button text="if" ontap="sw,i,if" />
<button text="unless" ontap="sw,u,unl" />
<space />
<space />
</row>
Correct when the label has been tapped:

Inconsistent state after using back button and then restarting the remote again:

