feat: Service Mode for Linux (#804)

This commit is contained in:
HZ is not Chatty
2024-03-31 16:16:23 +08:00
committed by GitHub
parent c5d7c29f3d
commit 3b06cf8a2a
12 changed files with 180 additions and 29 deletions

View File

@@ -92,12 +92,17 @@ pub fn clash_pid_path() -> Result<PathBuf> {
Ok(app_home_dir()?.join("clash.pid"))
}
#[cfg(target_os = "linux")]
pub fn service_path() -> Result<PathBuf> {
Ok(app_resources_dir()?.join("clash-verge-service"))
}
#[cfg(windows)]
pub fn service_path() -> Result<PathBuf> {
Ok(app_resources_dir()?.join("clash-verge-service.exe"))
}
#[cfg(windows)]
#[cfg(any(windows, target_os = "linux"))]
pub fn service_log_file() -> Result<PathBuf> {
use chrono::Local;

View File

@@ -4,3 +4,4 @@ pub mod init;
pub mod resolve;
pub mod server;
pub mod tmpl;
pub mod unix_helper;

View File

@@ -0,0 +1,15 @@
use std::process::Command;
#[cfg(target_os = "linux")]
pub fn linux_elevator() -> &'static str {
match Command::new("which").arg("pkexec").output() {
Ok(output) => {
if output.stdout.is_empty() {
"sudo"
} else {
"pkexec"
}
}
Err(_) => "sudo",
}
}