ente76 / guillotine

Guillotine is a gnome extension designed for efficiently carrying out executions of commands from a customizable menu. Simply speaking: it is a highly customizable menu that enables you to launch commands and toggle services.
GNU Affero General Public License v3.0
28 stars 0 forks source link

Switch not working on Ubuntu 21.10 #8

Closed fabricio-godoi closed 3 years ago

fabricio-godoi commented 3 years ago

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.

    {
      "type": "switch",
      "title": "Test",
      "start": "echo \"something\" > /tmp/test-switch",
      "stop": "echo '' > /tmp/test-switch",
      "check": "if [ ! -z $(cat /tmp/test-switch) ]; return true ; else return false ; fi",
      "icon": "audio-input-microphone-symbolic"
    },

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?

ente76 commented 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.

fabricio-godoi commented 3 years ago

@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

ente76 commented 2 years ago

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:

fabricio-godoi commented 2 years ago

@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!