Skip to content

Commit

Permalink
feat: support to call pkexec-like on *nix
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticLampyrid committed Mar 18, 2024
1 parent aa54092 commit 6247fac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ portable-pty = "0.8.1"
strip-ansi-escapes = "0.2.0"
once_cell = "1.18.0"
native-dialog = "0.7"
which = "6.0"
libc = "0.2"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.51", features = [
Expand Down
17 changes: 16 additions & 1 deletion gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,22 @@ fn do_env_up(ui_handle: &Weak<AppWindow>) {
std::process::exit(0);
}

let mut cmd = CommandBuilder::new(PATH_OF_CLI.as_os_str());
let mut cmd: CommandBuilder = 'b: {
#[cfg(unix)]
if unsafe { libc::getuid() } != 0 {
if which::which("lxqt-sudo").is_ok() {
let mut cmd = CommandBuilder::new("lxqt-sudo");
cmd.arg(PATH_OF_CLI.as_os_str());
break 'b cmd;
}
if which::which("pkexec").is_ok() {
let mut cmd = CommandBuilder::new("pkexec");
cmd.arg(PATH_OF_CLI.as_os_str());
break 'b cmd;
}
}
break 'b CommandBuilder::new(PATH_OF_CLI.as_os_str());
};
cmd.arg("env");
cmd.arg("up");
let ui_handle_2 = ui_handle.clone();
Expand Down

0 comments on commit 6247fac

Please sign in to comment.