chore: update

This commit is contained in:
huzibaca 2024-10-10 23:34:55 +08:00
parent b4180b5b48
commit 25e25c2285
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302

View File

@ -30,7 +30,7 @@ pub struct JsonResponse {
/// 该函数应该在协程或者线程中执行避免UAC弹窗阻塞主线程
///
#[cfg(target_os = "windows")]
pub async fn reinstall_service(_passwd: String) -> Result<()> {
pub async fn reinstall_service() -> Result<()> {
use deelevate::{PrivilegeLevel, Token};
use runas::Command as RunasCommand;
use std::os::windows::process::CommandExt;
@ -81,7 +81,7 @@ pub async fn reinstall_service(_passwd: String) -> Result<()> {
}
#[cfg(target_os = "linux")]
pub async fn reinstall_service(passwd: String) -> Result<()> {
pub async fn reinstall_service() -> Result<()> {
use users::get_effective_uid;
let binary_path = dirs::service_path()?;
@ -165,40 +165,6 @@ pub async fn reinstall_service() -> Result<()> {
}
Ok(())
}
/// Uninstall the Clash Verge Service
/// 该函数应该在协程或者线程中执行避免UAC弹窗阻塞主线程
#[cfg(target_os = "windows")]
pub async fn uninstall_service(_passwd: String) -> Result<()> {
use deelevate::{PrivilegeLevel, Token};
use runas::Command as RunasCommand;
use std::os::windows::process::CommandExt;
let binary_path = dirs::service_path()?;
let uninstall_path = binary_path.with_file_name("uninstall-service.exe");
if !uninstall_path.exists() {
bail!("uninstaller exe not found");
}
let token = Token::with_current_process()?;
let level = token.privilege_level()?;
let status = match level {
PrivilegeLevel::NotPrivileged => RunasCommand::new(uninstall_path).show(false).status()?,
_ => StdCommand::new(uninstall_path)
.creation_flags(0x08000000)
.status()?,
};
if !status.success() {
bail!(
"failed to uninstall service with status {}",
status.code().unwrap()
);
}
Ok(())
}
/// check the windows service status
pub async fn check_service() -> Result<JsonResponse> {