fix: try to fix service not started on linux

This commit is contained in:
huzibaca 2024-10-18 07:08:34 +08:00
parent 89ce497431
commit a013fe663c
2 changed files with 2 additions and 19 deletions

View File

@ -89,20 +89,18 @@ pub async fn reinstall_service() -> Result<()> {
let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ "); let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ ");
let uninstall_shell: String = uninstall_path.to_string_lossy().replace(" ", "\\ "); let uninstall_shell: String = uninstall_path.to_string_lossy().replace(" ", "\\ ");
let elevator = crate::utils::help::linux_elevator();
let _ = match get_effective_uid() { let _ = match get_effective_uid() {
0 => StdCommand::new(uninstall_path).status()?, 0 => StdCommand::new(uninstall_path).status()?,
_ => StdCommand::new(elevator) _ => StdCommand::new("sudo")
.arg("sh") .arg("sh")
.arg("-c") .arg("-c")
.arg(uninstall_shell) .arg(uninstall_shell)
.status()?, .status()?,
}; };
let elevator = crate::utils::help::linux_elevator();
let status = match get_effective_uid() { let status = match get_effective_uid() {
0 => StdCommand::new(install_shell).status()?, 0 => StdCommand::new(install_shell).status()?,
_ => StdCommand::new(elevator) _ => StdCommand::new("sudo")
.arg("sh") .arg("sh")
.arg("-c") .arg("-c")
.arg(install_shell) .arg(install_shell)

View File

@ -105,21 +105,6 @@ pub fn open_file(app: tauri::AppHandle, path: PathBuf) -> Result<()> {
Ok(()) Ok(())
} }
#[cfg(target_os = "linux")]
pub fn linux_elevator() -> &'static str {
use std::process::Command;
match Command::new("which").arg("pkexec").output() {
Ok(output) => {
if output.stdout.is_empty() {
"sudo"
} else {
"pkexec"
}
}
Err(_) => "sudo",
}
}
#[macro_export] #[macro_export]
macro_rules! error { macro_rules! error {
($result: expr) => { ($result: expr) => {