Newbie shell extension coder: how to I set the state of a switch created with PopupSwitchMenuItem()

I am working with a gnome extension which has a toggle switch on its panel popup menu. I have bound a keyboard shortcut to the same setting, so I want to change the state of the toggle to reflect what happens with the keyboard shortcut.

the toggle comes from code like this:

let toggle = new PopupSwitchMenuItem(desc, active);

and I can save a reference to toggle so that is known to the code that handles the keyboard short cut. But I don’t know how to change the state, and neither do I know how to bind the switch so that it can notice a change in state to the extension settings object.
I hoped toggle.set_state(true) might work, but whatever object toggle is, it does not support set_state()

It’s setToggleState(), see

1 Like

Thanks Florian. With some googling earlier I discovered that link and everything made a lot more sense once I could see the source code. I spent a few hours trying to find documentation and code examples, to no avail. There is nothing like the source code.
I actually implemented _switch.state = which was the first thing I saw which worked, I should have kept reading but I got very carried away with my ‘breakthrough’. I thought needing to use an underscore property was a bit dodgy. I will refactor to use your suggestion.

Thanks for replying, it’s good for confidence to know there is some help. I haven’t used javascript for a decade and needless to say I have never dabbled around with shell extensions. I think it is easy for people to give up at this stage of their journey. But I feel ‘launched’ now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.