fyne icon indicating copy to clipboard operation
fyne copied to clipboard

How to let mac open a windows ask for administrator privileges

Open JackySmith opened this issue 5 years ago • 8 comments

Hi, I have a new question by package app on mac

After fyne package -icon xxx.png , I get a mac os app,but this app don't have the sudo privileges my func() in button need sudo privileges How to let this app open a window ask for sudo privileges when user click a fyne button on mac? Or when open app ,it ask for privileges like on windows Then User can enter the sudo's password and give app privileges Thank you image

JackySmith avatar Aug 27 '20 09:08 JackySmith

Fyne does not support privelege escallation. What sort of app needs to run as system administrator?

andydotxyz avatar Aug 27 '20 10:08 andydotxyz

I have many needs on that , for example, I want my app can exec a command line like " sudo mount disk..." by click a button ,or restart mac , which need sudo privileges . Is there a easy way to achieve that ?

JackySmith avatar Aug 27 '20 15:08 JackySmith

I'd head to the macOS documentation, you can always call out to their APIs with CGo. https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/AccessControl.html

andydotxyz avatar Aug 27 '20 15:08 andydotxyz

Thank you so much I only use golang but not familiar with C I will study that document , I hope fyne can support that one day

JackySmith avatar Aug 27 '20 16:08 JackySmith

@JackySmith I found a library that can support windows and MAC, which is very useful https://github.com/getlantern/elevate

zhangxianweihebei avatar Mar 08 '22 14:03 zhangxianweihebei

However, I still hope Fyne native support

zhangxianweihebei avatar Mar 08 '22 14:03 zhangxianweihebei

I know this issue is not directly related to fyne. However, I found that https://github.com/getlantern/elevate does not work if you are trying to issue a sudo command on MAC. I addition, the repository: https://git.zx2c4.com/wireguard-windows does not have a method to file a bug. Hopefully I will be able to find another solution that actually works.

brucealthompson avatar Jun 24 '23 15:06 brucealthompson

One potential way to run a sudo command: Use a https://github.com/fyne-io/terminal widget and its term.Write() method to write the sudo command to the terminal (followed by "; exit $?\n"). The user will see the actual command and be able to enter the password (or even just use TouchID for the purpose, if enabled [1]). term.ExitCode() could be used to verify success. This works for me on macOS and Linux - on Windows I currently right-click the .exe to "Run as Administrator". Sooner or later, sudo might also become an option for that [2], maybe.

[1] https://apple.stackexchange.com/questions/259093/can-touch-id-on-mac-authenticate-sudo-in-terminal [2] https://devblogs.microsoft.com/commandline/introducing-sudo-for-windows/

schnoddelbotz avatar Apr 04 '24 10:04 schnoddelbotz