Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check exit code and running commands with pkexec #7

Open
jeroenwtf opened this issue Dec 19, 2024 · 8 comments
Open

Check exit code and running commands with pkexec #7

jeroenwtf opened this issue Dec 19, 2024 · 8 comments

Comments

@jeroenwtf
Copy link

Hello there! 👋🏻

First of all, thanks for the extension. I thought I would have to do it myself but found yours and it's perfect!

I'm using it to enable and disable the keyboard of my laptop, since I use an external one and I place it on top of the other one. I used to run the script manually but with this extension is way easier and neat. I have two questions:

Would it be possible to tie the toggle status changing to the exit code of the command run? I'm not sure if it makes sense, but in case the command doesn't run successfully, no not toggle the status. It would be cool also for cases where you need to authenticate and you cancel it (I think it's exit code 127). Again, not sure if we can have that info from the extension.

The other question is about authentication. I have to run the scripts with sudo. Instead of opening a terminal, I'm just running them with pkexec (as pkexec /path/to/the/script.sh). It prompts for the password from GNOME itself without terminals involved, which looks nicer. Do you think is a better approach?

I could check about the exit code part if you don't have time and open a PR, if you are up for it :) Thanks again!

@luguenth
Copy link

Hey there, had a little bit of a similar Issue. Maybe you can find some Inspiration in #8
I'm checking the exit code to figure out if my button should currently be highlighted or not.

@StorageB
Copy link
Owner

StorageB commented Dec 22, 2024

@jeroenwtf I'm happy to hear you've found this extension useful. I think this is a good idea that others would benefit from as well.

And I appreciate the feedback- it's always good to hear how people are using the extension!

@StorageB StorageB reopened this Dec 22, 2024
@StorageB
Copy link
Owner

As for the sudo commands, I would have to think about this a bit more. My approach has been to run
gnome-terminal -- /path/to/the/script.sh to run the command in a terminal to enter the password, but your approach sounds better. Also, in Linux there is a method to disable the need to enter a password for a single command requiring sudo. This may not be the preferred method (or something I'd recommend for beginners), but I have used it and it seems to work fine with this extension.

@StorageB
Copy link
Owner

StorageB commented Dec 22, 2024

@luguenth
I appreciate the pull request to address this issue. Unfortunately I will be away from my computer until after the new year, so I won't be able to review until then. But looking through your code, I think this is a good approach and something I'd like to incorporate. I will review and get back to you in a few weeks. Thanks again!

@StorageB
Copy link
Owner

@jeroenwtf
Could you give me an example of the Toggle On and Toggle Off commands that you are using that you want to check the exit code of?
If I understand correctly, you want option for the extension to follow this workflow:

  1. Toggle is off
  2. Click toggle button to turn on
  3. The Toggle On command runs, but the toggle is only switched to the on position if the exit code for the Toggle On command is zero. If the exit code is something else, the toggle should remain off.

Should this be the same for turning the toggle off? So it only turns off if the exit code for the Toggle Off command is 0?

Let me know if this is correct.

@Jules-Bertholet
Copy link

Should this be the same for turning the toggle off? So it only turns off if the exit code for the Toggle Off command is 0?

For my own use-case, this is accurate. (Like OP, I run commands with pkexec—if I cancel the authentication, I don’t want the button to be toggled.)

@StorageB
Copy link
Owner

Thinking to just make this an option that can be turned on or off in that case. And this should only show up when the Button Click Action is set to Toggle? Meaning it wouldn't apply to an always on or off button.

Screenshot from 2025-01-10 13-36-55-2

@Jules-Bertholet
Copy link

Maybe it should also interact with the “close menu” option (menu only closes on success).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants