Closed fabricio-godoi closed 3 years ago
I can confirm the example provided does not work on latest Arch Linux and 40.5. While the switching process seems to finish successfully (although no change is performed on the file???), the test process triggered, seems to fail before first attempt of logging. So parsing the "check" command or initializing the check seems to crash the process.
Your check command requires bash, doesn't it? Why is it, you assume bash be available? If I replace the check command by "grep -q something /tmp/test-switch", the extension works correct. The command to paste "something" into "/tmp/test-switch" succeeds but the subsequent check fails and thus the switch is reset.
I will have another look one of the next few days.
@ente76 Thank you for the reply.
I'm not expecting to have bash loaded, but I assumed that the shell commands would work. I got a lot confused on how the check mechanism works, the example you provided does not seem to have any return, since it is used the '--quiet' argument. Can you explain how this works?
With your grep example I managed to get it working properly.
{
"type": "switch",
"title": "Test",
"start": "sh -c 'echo \"something\" > /tmp/test-switch'",
"stop": "sh -c 'echo \"\" > /tmp/test-switch'",
"check": "grep -q something /tmp/test-switch",
"icon": "audio-input-microphone-symbolic"
},
I have to tweak it a little to work with my desired functionality, but it seems to work properly. I wanted to be able to switch my Bluetooth headphone mode:
{
"type": "switch",
"title": "Enable bluetooth mic",
"start": "sh -c 'pactl set-card-profile bluez_card.{MASK} headset-head-unit'",
"stop": "sh -c 'pactl set-card-profile bluez_card.{MASK} a2dp-sink'",
"check": "sh -c 'pactl list short sinks | grep bluez | grep -q headset'",
"icon": "audio-input-microphone-symbolic",
"interval": 10000
},
Again, thank you for the help! =D
Its been some busy days. You triggered some heavy refactoring of the extension as you can see on the release notes for the new version. :smiley:
I consider your report a defect (now fixed) in the extension: there was an exception raised by your malformed command that wasn't handled. I added some exception handling and improved the overall logging. I also agree that the documentation on how the switch is working was lacking plenty of detail. Please review the new version and let me know if that would have been helpful back then.
For your bluetooth switch: check the first command of my example. It performs the switch from a2dp to headset. The start
and the stop
command are as boring as a command
: their return code does not matter to the switch. They both trigger immediately a check
. The return code for the check
command is what matters most on the switch. Simple examples below:
"check": "sh -c 'exit 0'"
will keep the switch always turned on, no matter how often you press the switch"check": "sh -c 'exit 1'"
will keep the switch always turned off, no matter how often you press the switch"check": "sh -c 'sleep 10;exit 0'"
will make the switch disabled for 10 seconds after switching manually from on to off and then it puts it back to on and enables it again
I hope that helps a bit. If you have more questions or examples that don't work, feel free to come back here. That would help improve the documentation.@ente76 Thank you very much for the feedback! I read the new documentation, and it helped me understand a lot better the behavior of the check command. I think you cover all questions that I had back when implementing the feature.
Thank you very much for the effort put into this thread.
Best regards!
I could not manage to get the switch working in Ubuntu 21.10 with GNOME 40.4.0.
I tried the example and even the following script without success.
The UI change the state of the switch, but the start process does not execute and the is not able to properly detect it state.
Someone could give me a hint what I'm missing?