Skip to content

Commit

Permalink
chore: uninstall old service
Browse files Browse the repository at this point in the history
  • Loading branch information
huzibaca committed Dec 29, 2024
1 parent 4afa3a5 commit 7f8ad08
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use anyhow::Error;

#[cfg(target_os = "macos")]
fn main() -> Result<(), Error> {
use clash_verge_service::utils::run_command;
use clash_verge_service::utils::{run_command, uninstall_old_service};
use std::fs::File;
use std::io::Write;
use std::path::Path;

let debug = env::args().any(|arg| arg == "--debug");
let _ = uninstall_old_service();

let service_binary_path = env::current_exe()
.unwrap()
Expand Down
3 changes: 2 additions & 1 deletion src/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use anyhow::Error;

#[cfg(target_os = "macos")]
fn main() -> Result<(), Error> {
use clash_verge_service::utils::run_command;
use clash_verge_service::utils::{run_command, uninstall_old_service};
use std::env;
use std::path::Path;

let debug = env::args().any(|arg| arg == "--debug");

let _ = uninstall_old_service();
// 定义路径
let bundle_path =
"/Library/PrivilegedHelperTools/io.github.clash-verge-rev.clash-verge-rev.service.bundle";
Expand Down
30 changes: 30 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,33 @@ pub fn run_command(cmd: &str, args: &[&str], debug: bool) -> Result<(), Error> {

Ok(())
}

#[cfg(target_os = "macos")]
pub fn uninstall_old_service() -> Result<(), Error> {
use std::path::Path;

let target_binary_path = "/Library/PrivilegedHelperTools/io.github.clashverge.helper";
let plist_file = "/Library/LaunchDaemons/io.github.clashverge.helper.plist";

// Stop and unload service
let _ = run_command("launchctl", &["stop", "io.github.clashverge.helper"], false);
let _ = run_command("launchctl", &["bootout", "system", plist_file], false);
let _ = run_command(
"launchctl",
&["disable", "system/io.github.clashverge.helper"],
false,
)?;

// Remove files
if Path::new(plist_file).exists() {
std::fs::remove_file(plist_file)
.map_err(|e| anyhow::anyhow!("Failed to remove plist file: {}", e))?;
}

if Path::new(target_binary_path).exists() {
std::fs::remove_file(target_binary_path)
.map_err(|e| anyhow::anyhow!("Failed to remove service binary: {}", e))?;
}

Ok(())
}

0 comments on commit 7f8ad08

Please sign in to comment.