2025-03-25 23:05:09 +08:00
|
|
|
|
use crate::{
|
|
|
|
|
|
config::Config,
|
2025-09-17 22:59:02 +08:00
|
|
|
|
logging, logging_error,
|
2025-10-11 23:40:37 +08:00
|
|
|
|
utils::{dirs, init::service_writer_config, logging::Type},
|
2025-03-25 23:05:09 +08:00
|
|
|
|
};
|
edition 2024 (#4702)
* feat: update Cargo.toml for 2024 edition and optimize release profiles
* feat: refactor environment variable settings for Linux and improve code organization
* Refactor conditional statements to use `&&` for improved readability
- Updated multiple files to combine nested `if let` statements using `&&` for better clarity and conciseness.
- This change enhances the readability of the code by reducing indentation levels and making the conditions more straightforward.
- Affected files include: media_unlock_checker.rs, profile.rs, clash.rs, profiles.rs, async_proxy_query.rs, core.rs, handle.rs, hotkey.rs, service.rs, timer.rs, tray/mod.rs, merge.rs, seq.rs, config.rs, proxy.rs, window.rs, general.rs, dirs.rs, i18n.rs, init.rs, network.rs, and window.rs in the resolve module.
* refactor: streamline conditional checks using `&&` for improved readability
* fix: update release profile settings for panic behavior and optimization
* fix: adjust optimization level in Cargo.toml and reorder imports in lightweight.rs
2025-09-10 09:49:06 +08:00
|
|
|
|
use anyhow::{Context, Result, bail};
|
2025-10-11 23:40:37 +08:00
|
|
|
|
use clash_verge_service_ipc::CoreConfig;
|
2025-10-13 11:38:54 +08:00
|
|
|
|
use compact_str::CompactString;
|
2025-09-17 22:59:02 +08:00
|
|
|
|
use once_cell::sync::Lazy;
|
2025-10-11 23:40:37 +08:00
|
|
|
|
use std::{
|
|
|
|
|
|
env::current_exe,
|
|
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
|
|
process::Command as StdCommand,
|
|
|
|
|
|
time::Duration,
|
|
|
|
|
|
};
|
2025-09-17 22:59:02 +08:00
|
|
|
|
use tokio::sync::Mutex;
|
2022-11-17 20:19:40 +08:00
|
|
|
|
|
2025-09-17 22:59:02 +08:00
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
|
pub enum ServiceStatus {
|
|
|
|
|
|
Ready,
|
|
|
|
|
|
NeedsReinstall,
|
|
|
|
|
|
InstallRequired,
|
|
|
|
|
|
UninstallRequired,
|
|
|
|
|
|
ReinstallRequired,
|
|
|
|
|
|
ForceReinstallRequired,
|
|
|
|
|
|
Unavailable(String),
|
2025-03-25 00:51:26 +08:00
|
|
|
|
}
|
2022-11-17 20:19:40 +08:00
|
|
|
|
|
2025-09-17 22:59:02 +08:00
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
|
pub struct ServiceManager(ServiceStatus);
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(clippy::unused_async)]
|
2024-03-31 16:16:23 +08:00
|
|
|
|
#[cfg(target_os = "windows")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn uninstall_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "uninstall service");
|
2025-03-25 00:51:26 +08:00
|
|
|
|
|
2024-03-31 16:16:23 +08:00
|
|
|
|
use deelevate::{PrivilegeLevel, Token};
|
|
|
|
|
|
use runas::Command as RunasCommand;
|
|
|
|
|
|
use std::os::windows::process::CommandExt;
|
|
|
|
|
|
|
2022-11-18 20:15:34 +08:00
|
|
|
|
let binary_path = dirs::service_path()?;
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let uninstall_path = binary_path.with_file_name("clash-verge-service-uninstall.exe");
|
2022-11-17 20:19:40 +08:00
|
|
|
|
|
2024-10-10 00:34:36 +08:00
|
|
|
|
if !uninstall_path.exists() {
|
2024-10-18 22:30:29 +08:00
|
|
|
|
bail!(format!("uninstaller not found: {uninstall_path:?}"));
|
2024-10-10 00:34:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-17 20:19:40 +08:00
|
|
|
|
let token = Token::with_current_process()?;
|
|
|
|
|
|
let level = token.privilege_level()?;
|
2025-03-26 04:31:38 +08:00
|
|
|
|
let status = match level {
|
2025-10-08 07:47:05 +08:00
|
|
|
|
PrivilegeLevel::NotPrivileged => RunasCommand::new(uninstall_path).show(false).status()?,
|
2024-10-10 00:34:36 +08:00
|
|
|
|
_ => StdCommand::new(uninstall_path)
|
|
|
|
|
|
.creation_flags(0x08000000)
|
|
|
|
|
|
.status()?,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-26 04:31:38 +08:00
|
|
|
|
if !status.success() {
|
|
|
|
|
|
bail!(
|
|
|
|
|
|
"failed to uninstall service with status {}",
|
2025-08-18 02:02:25 +08:00
|
|
|
|
status.code().unwrap_or(-1)
|
2025-03-26 04:31:38 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 22:59:02 +08:00
|
|
|
|
#[allow(clippy::unused_async)]
|
2025-03-26 04:31:38 +08:00
|
|
|
|
#[cfg(target_os = "windows")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn install_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "install service");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
use deelevate::{PrivilegeLevel, Token};
|
|
|
|
|
|
use runas::Command as RunasCommand;
|
|
|
|
|
|
use std::os::windows::process::CommandExt;
|
|
|
|
|
|
|
|
|
|
|
|
let binary_path = dirs::service_path()?;
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let install_path = binary_path.with_file_name("clash-verge-service-install.exe");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
if !install_path.exists() {
|
|
|
|
|
|
bail!(format!("installer not found: {install_path:?}"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let token = Token::with_current_process()?;
|
|
|
|
|
|
let level = token.privilege_level()?;
|
2022-11-17 20:19:40 +08:00
|
|
|
|
let status = match level {
|
2025-10-08 07:47:05 +08:00
|
|
|
|
PrivilegeLevel::NotPrivileged => RunasCommand::new(install_path).show(false).status()?,
|
2022-11-17 20:19:40 +08:00
|
|
|
|
_ => StdCommand::new(install_path)
|
|
|
|
|
|
.creation_flags(0x08000000)
|
|
|
|
|
|
.status()?,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if !status.success() {
|
2025-03-26 04:31:38 +08:00
|
|
|
|
bail!(
|
2022-11-17 20:19:40 +08:00
|
|
|
|
"failed to install service with status {}",
|
2025-08-18 02:02:25 +08:00
|
|
|
|
status.code().unwrap_or(-1)
|
2022-11-17 20:19:40 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-26 04:31:38 +08:00
|
|
|
|
#[cfg(target_os = "windows")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn reinstall_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "reinstall service");
|
2024-03-31 16:16:23 +08:00
|
|
|
|
|
2025-03-26 04:31:38 +08:00
|
|
|
|
// 先卸载服务
|
2025-08-26 01:49:51 +08:00
|
|
|
|
if let Err(err) = uninstall_service().await {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(warn, Type::Service, "failed to uninstall service: {}", err);
|
2025-03-26 04:31:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 再安装服务
|
2025-08-26 01:49:51 +08:00
|
|
|
|
match install_service().await {
|
2025-09-17 22:59:02 +08:00
|
|
|
|
Ok(_) => Ok(()),
|
2025-03-26 04:31:38 +08:00
|
|
|
|
Err(err) => {
|
2025-09-17 22:59:02 +08:00
|
|
|
|
bail!(format!("failed to install service: {err}"))
|
2025-03-26 04:31:38 +08:00
|
|
|
|
}
|
2024-03-31 16:16:23 +08:00
|
|
|
|
}
|
2025-03-26 04:31:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-26 01:49:51 +08:00
|
|
|
|
#[allow(clippy::unused_async)]
|
2025-03-26 04:31:38 +08:00
|
|
|
|
#[cfg(target_os = "linux")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn uninstall_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "uninstall service");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
use users::get_effective_uid;
|
|
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let uninstall_path =
|
|
|
|
|
|
tauri::utils::platform::current_exe()?.with_file_name("clash-verge-service-uninstall");
|
2024-03-31 16:16:23 +08:00
|
|
|
|
|
2024-10-15 02:35:50 +08:00
|
|
|
|
if !uninstall_path.exists() {
|
2024-10-18 22:30:29 +08:00
|
|
|
|
bail!(format!("uninstaller not found: {uninstall_path:?}"));
|
2024-10-10 00:34:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-15 02:35:50 +08:00
|
|
|
|
let uninstall_shell: String = uninstall_path.to_string_lossy().replace(" ", "\\ ");
|
|
|
|
|
|
|
2024-10-18 22:30:29 +08:00
|
|
|
|
let elevator = crate::utils::help::linux_elevator();
|
|
|
|
|
|
let status = match get_effective_uid() {
|
|
|
|
|
|
0 => StdCommand::new(uninstall_shell).status()?,
|
2024-10-21 04:35:21 +08:00
|
|
|
|
_ => StdCommand::new(elevator.clone())
|
2024-10-10 00:34:36 +08:00
|
|
|
|
.arg("sh")
|
|
|
|
|
|
.arg("-c")
|
2024-10-15 02:35:50 +08:00
|
|
|
|
.arg(uninstall_shell)
|
2024-10-10 00:34:36 +08:00
|
|
|
|
.status()?,
|
2024-03-31 16:16:23 +08:00
|
|
|
|
};
|
2025-03-26 04:31:38 +08:00
|
|
|
|
logging!(
|
|
|
|
|
|
info,
|
|
|
|
|
|
Type::Service,
|
|
|
|
|
|
"uninstall status code:{}",
|
2025-08-18 02:02:25 +08:00
|
|
|
|
status.code().unwrap_or(-1)
|
2025-03-26 04:31:38 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if !status.success() {
|
|
|
|
|
|
bail!(
|
|
|
|
|
|
"failed to uninstall service with status {}",
|
2025-08-18 02:02:25 +08:00
|
|
|
|
status.code().unwrap_or(-1)
|
2025-03-26 04:31:38 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
#[allow(clippy::unused_async)]
|
|
|
|
|
|
async fn install_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "install service");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
use users::get_effective_uid;
|
|
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let install_path =
|
|
|
|
|
|
tauri::utils::platform::current_exe()?.with_file_name("clash-verge-service-install");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
if !install_path.exists() {
|
|
|
|
|
|
bail!(format!("installer not found: {install_path:?}"));
|
|
|
|
|
|
}
|
2024-10-10 00:34:36 +08:00
|
|
|
|
|
2025-03-26 04:31:38 +08:00
|
|
|
|
let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ ");
|
|
|
|
|
|
|
|
|
|
|
|
let elevator = crate::utils::help::linux_elevator();
|
2024-10-10 00:34:36 +08:00
|
|
|
|
let status = match get_effective_uid() {
|
2024-10-15 02:35:50 +08:00
|
|
|
|
0 => StdCommand::new(install_shell).status()?,
|
2024-10-21 04:35:21 +08:00
|
|
|
|
_ => StdCommand::new(elevator.clone())
|
2024-10-10 00:34:36 +08:00
|
|
|
|
.arg("sh")
|
|
|
|
|
|
.arg("-c")
|
2024-10-15 02:35:50 +08:00
|
|
|
|
.arg(install_shell)
|
2024-10-10 00:34:36 +08:00
|
|
|
|
.status()?,
|
|
|
|
|
|
};
|
2025-03-26 04:31:38 +08:00
|
|
|
|
logging!(
|
|
|
|
|
|
info,
|
|
|
|
|
|
Type::Service,
|
|
|
|
|
|
"install status code:{}",
|
2025-08-18 02:02:25 +08:00
|
|
|
|
status.code().unwrap_or(-1)
|
2025-03-26 04:31:38 +08:00
|
|
|
|
);
|
2024-10-10 00:34:36 +08:00
|
|
|
|
|
|
|
|
|
|
if !status.success() {
|
|
|
|
|
|
bail!(
|
|
|
|
|
|
"failed to install service with status {}",
|
2025-08-18 02:02:25 +08:00
|
|
|
|
status.code().unwrap_or(-1)
|
2024-03-31 16:16:23 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-26 04:31:38 +08:00
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn reinstall_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "reinstall service");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
// 先卸载服务
|
2025-08-26 01:49:51 +08:00
|
|
|
|
if let Err(err) = uninstall_service().await {
|
2025-10-10 13:46:26 +08:00
|
|
|
|
logging!(warn, Type::Service, "failed to uninstall service: {}", err);
|
2025-03-26 04:31:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 再安装服务
|
2025-08-26 01:49:51 +08:00
|
|
|
|
match install_service().await {
|
2025-09-17 22:59:02 +08:00
|
|
|
|
Ok(_) => Ok(()),
|
2025-03-26 04:31:38 +08:00
|
|
|
|
Err(err) => {
|
2025-09-17 22:59:02 +08:00
|
|
|
|
bail!(format!("failed to install service: {err}"))
|
2025-03-26 04:31:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn uninstall_service() -> Result<()> {
|
2025-03-26 04:31:38 +08:00
|
|
|
|
use crate::utils::i18n::t;
|
|
|
|
|
|
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "uninstall service");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
let binary_path = dirs::service_path()?;
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let uninstall_path = binary_path.with_file_name("clash-verge-service-uninstall");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
if !uninstall_path.exists() {
|
|
|
|
|
|
bail!(format!("uninstaller not found: {uninstall_path:?}"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let uninstall_shell: String = uninstall_path.to_string_lossy().into_owned();
|
|
|
|
|
|
|
2025-08-26 01:49:51 +08:00
|
|
|
|
let prompt = t("Service Administrator Prompt").await;
|
2025-03-26 04:31:38 +08:00
|
|
|
|
let command = format!(
|
|
|
|
|
|
r#"do shell script "sudo '{uninstall_shell}'" with administrator privileges with prompt "{prompt}""#
|
|
|
|
|
|
);
|
|
|
|
|
|
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
// logging!(debug, Type::Service, "uninstall command: {}", command);
|
2025-03-26 04:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
let status = StdCommand::new("osascript")
|
|
|
|
|
|
.args(vec!["-e", &command])
|
|
|
|
|
|
.status()?;
|
|
|
|
|
|
|
|
|
|
|
|
if !status.success() {
|
|
|
|
|
|
bail!(
|
|
|
|
|
|
"failed to uninstall service with status {}",
|
2025-08-18 02:02:25 +08:00
|
|
|
|
status.code().unwrap_or(-1)
|
2025-03-26 04:31:38 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-03-25 06:41:00 +08:00
|
|
|
|
|
2024-03-31 16:16:23 +08:00
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-31 21:44:34 +08:00
|
|
|
|
#[cfg(target_os = "macos")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn install_service() -> Result<()> {
|
2025-03-26 03:44:30 +08:00
|
|
|
|
use crate::utils::i18n::t;
|
|
|
|
|
|
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "install service");
|
2024-10-18 22:30:29 +08:00
|
|
|
|
|
2024-03-31 21:44:34 +08:00
|
|
|
|
let binary_path = dirs::service_path()?;
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let install_path = binary_path.with_file_name("clash-verge-service-install");
|
2024-03-31 21:44:34 +08:00
|
|
|
|
|
2024-10-15 02:35:50 +08:00
|
|
|
|
if !install_path.exists() {
|
2024-10-18 22:30:29 +08:00
|
|
|
|
bail!(format!("installer not found: {install_path:?}"));
|
2024-03-31 21:44:34 +08:00
|
|
|
|
}
|
2024-07-12 20:46:38 +08:00
|
|
|
|
|
2024-10-23 04:46:47 +08:00
|
|
|
|
let install_shell: String = install_path.to_string_lossy().into_owned();
|
2025-03-13 12:51:20 +08:00
|
|
|
|
|
2025-08-26 01:49:51 +08:00
|
|
|
|
let prompt = t("Service Administrator Prompt").await;
|
2024-10-10 00:34:36 +08:00
|
|
|
|
let command = format!(
|
2025-03-26 04:31:38 +08:00
|
|
|
|
r#"do shell script "sudo '{install_shell}'" with administrator privileges with prompt "{prompt}""#
|
2024-10-10 00:34:36 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
// logging!(debug, Type::Service, "install command: {}", command);
|
2024-10-23 04:46:47 +08:00
|
|
|
|
|
2024-10-10 00:34:36 +08:00
|
|
|
|
let status = StdCommand::new("osascript")
|
|
|
|
|
|
.args(vec!["-e", &command])
|
|
|
|
|
|
.status()?;
|
|
|
|
|
|
|
|
|
|
|
|
if !status.success() {
|
2024-03-31 21:44:34 +08:00
|
|
|
|
bail!(
|
2024-10-10 00:34:36 +08:00
|
|
|
|
"failed to install service with status {}",
|
2025-08-18 02:02:25 +08:00
|
|
|
|
status.code().unwrap_or(-1)
|
2024-03-31 21:44:34 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-03-25 06:41:00 +08:00
|
|
|
|
|
2025-03-26 04:31:38 +08:00
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn reinstall_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "reinstall service");
|
2025-03-26 04:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
// 先卸载服务
|
2025-08-26 01:49:51 +08:00
|
|
|
|
if let Err(err) = uninstall_service().await {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(warn, Type::Service, "failed to uninstall service: {}", err);
|
2025-03-26 04:31:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 再安装服务
|
2025-08-26 01:49:51 +08:00
|
|
|
|
match install_service().await {
|
2025-09-17 22:59:02 +08:00
|
|
|
|
Ok(_) => Ok(()),
|
2025-03-26 04:31:38 +08:00
|
|
|
|
Err(err) => {
|
2025-09-17 22:59:02 +08:00
|
|
|
|
bail!(format!("failed to install service: {err}"))
|
2025-03-26 04:31:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-31 21:44:34 +08:00
|
|
|
|
}
|
2022-11-17 20:19:40 +08:00
|
|
|
|
|
2025-09-17 22:59:02 +08:00
|
|
|
|
/// 强制重装服务(UI修复按钮)
|
|
|
|
|
|
pub async fn force_reinstall_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "用户请求强制重装服务");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
reinstall_service().await.map_err(|err| {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(error, Type::Service, "强制重装服务失败: {}", err);
|
2025-09-17 22:59:02 +08:00
|
|
|
|
err
|
|
|
|
|
|
})
|
2022-11-17 20:19:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 00:14:58 +08:00
|
|
|
|
/// 检查服务版本 - 使用IPC通信
|
2025-09-17 22:59:02 +08:00
|
|
|
|
async fn check_service_version() -> Result<String> {
|
2025-10-08 12:32:40 +08:00
|
|
|
|
let version_arc: Result<String> = {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "开始检查服务版本 (IPC)");
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let response = clash_verge_service_ipc::get_version()
|
|
|
|
|
|
.await
|
|
|
|
|
|
.context("无法连接到Clash Verge Service")?;
|
|
|
|
|
|
if response.code > 0 {
|
|
|
|
|
|
let err_msg = response.message;
|
|
|
|
|
|
logging!(error, Type::Service, "获取服务版本失败: {}", err_msg);
|
|
|
|
|
|
return Err(anyhow::anyhow!(err_msg));
|
2025-10-08 12:32:40 +08:00
|
|
|
|
}
|
2025-10-11 23:40:37 +08:00
|
|
|
|
|
2025-10-22 17:33:55 +08:00
|
|
|
|
let version = response.data.unwrap_or_else(|| "unknown".into());
|
2025-10-11 23:40:37 +08:00
|
|
|
|
Ok(version)
|
2025-10-08 12:32:40 +08:00
|
|
|
|
};
|
2025-09-17 22:59:02 +08:00
|
|
|
|
|
|
|
|
|
|
match version_arc.as_ref() {
|
|
|
|
|
|
Ok(v) => Ok(v.clone()),
|
|
|
|
|
|
Err(e) => Err(anyhow::Error::msg(e.to_string())),
|
2025-02-28 06:45:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 00:14:58 +08:00
|
|
|
|
/// 检查服务是否需要重装
|
2025-02-28 06:45:30 +08:00
|
|
|
|
pub async fn check_service_needs_reinstall() -> bool {
|
|
|
|
|
|
match check_service_version().await {
|
2025-10-11 23:40:37 +08:00
|
|
|
|
Ok(version) => version != clash_verge_service_ipc::VERSION,
|
2025-09-17 22:59:02 +08:00
|
|
|
|
Err(_) => false,
|
2025-02-28 06:45:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 00:14:58 +08:00
|
|
|
|
/// 尝试使用服务启动core
|
2025-03-25 00:51:26 +08:00
|
|
|
|
pub(super) async fn start_with_existing_service(config_file: &PathBuf) -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "尝试使用现有服务启动核心");
|
2025-02-28 06:45:30 +08:00
|
|
|
|
|
2025-09-17 22:59:02 +08:00
|
|
|
|
let verge_config = Config::verge().await;
|
|
|
|
|
|
let clash_core = verge_config.latest_ref().get_valid_clash_core();
|
|
|
|
|
|
drop(verge_config);
|
2022-11-17 20:19:40 +08:00
|
|
|
|
|
2024-03-31 21:44:34 +08:00
|
|
|
|
let bin_ext = if cfg!(windows) { ".exe" } else { "" };
|
2025-09-17 22:59:02 +08:00
|
|
|
|
let bin_path = current_exe()?.with_file_name(format!("{clash_core}{bin_ext}"));
|
2022-11-17 20:19:40 +08:00
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let payload = clash_verge_service_ipc::ClashConfig {
|
|
|
|
|
|
core_config: CoreConfig {
|
2025-10-14 09:24:39 +08:00
|
|
|
|
config_path: dirs::path_to_str(config_file)?.into(),
|
|
|
|
|
|
core_path: dirs::path_to_str(&bin_path)?.into(),
|
|
|
|
|
|
config_dir: dirs::path_to_str(&dirs::app_home_dir()?)?.into(),
|
2025-10-11 23:40:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
log_config: service_writer_config().await?,
|
|
|
|
|
|
};
|
2025-05-08 00:14:58 +08:00
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let response = clash_verge_service_ipc::start_clash(&payload)
|
2025-09-17 22:59:02 +08:00
|
|
|
|
.await
|
|
|
|
|
|
.context("无法连接到Clash Verge Service")?;
|
2025-04-30 21:30:28 +08:00
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
if response.code > 0 {
|
|
|
|
|
|
let err_msg = response.message;
|
|
|
|
|
|
logging!(error, Type::Service, "启动核心失败: {}", err_msg);
|
2025-09-17 22:59:02 +08:00
|
|
|
|
bail!(err_msg);
|
|
|
|
|
|
}
|
2022-11-17 20:19:40 +08:00
|
|
|
|
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务成功启动核心");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
Ok(())
|
2022-11-17 20:19:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 00:14:58 +08:00
|
|
|
|
// 以服务启动core
|
2025-03-25 00:51:26 +08:00
|
|
|
|
pub(super) async fn run_core_by_service(config_file: &PathBuf) -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "正在尝试通过服务启动核心");
|
2025-03-25 23:05:09 +08:00
|
|
|
|
|
2025-03-25 00:51:26 +08:00
|
|
|
|
if check_service_needs_reinstall().await {
|
2025-09-17 22:59:02 +08:00
|
|
|
|
reinstall_service().await?;
|
2025-03-25 00:51:26 +08:00
|
|
|
|
}
|
2025-09-17 22:59:02 +08:00
|
|
|
|
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务已运行且版本匹配,直接使用");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
start_with_existing_service(config_file).await
|
2025-03-25 00:51:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 17:58:02 +08:00
|
|
|
|
pub(super) async fn get_clash_logs_by_service() -> Result<Vec<CompactString>> {
|
2025-10-12 23:54:48 +08:00
|
|
|
|
logging!(info, Type::Service, "正在获取服务模式下的 Clash 日志");
|
|
|
|
|
|
|
|
|
|
|
|
let response = clash_verge_service_ipc::get_clash_logs()
|
|
|
|
|
|
.await
|
|
|
|
|
|
.context("无法连接到Clash Verge Service")?;
|
|
|
|
|
|
|
|
|
|
|
|
if response.code > 0 {
|
|
|
|
|
|
let err_msg = response.message;
|
|
|
|
|
|
logging!(
|
|
|
|
|
|
error,
|
|
|
|
|
|
Type::Service,
|
|
|
|
|
|
"获取服务模式下的 Clash 日志失败: {}",
|
|
|
|
|
|
err_msg
|
|
|
|
|
|
);
|
|
|
|
|
|
bail!(err_msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logging!(info, Type::Service, "成功获取服务模式下的 Clash 日志");
|
|
|
|
|
|
Ok(response.data.unwrap_or_default())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 00:14:58 +08:00
|
|
|
|
/// 通过服务停止core
|
2022-11-17 20:19:40 +08:00
|
|
|
|
pub(super) async fn stop_core_by_service() -> Result<()> {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "通过服务停止核心 (IPC)");
|
2025-04-30 21:30:28 +08:00
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
let response = clash_verge_service_ipc::stop_clash()
|
2025-02-15 05:51:46 +08:00
|
|
|
|
.await
|
2025-05-08 00:14:58 +08:00
|
|
|
|
.context("无法连接到Clash Verge Service")?;
|
|
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
if response.code > 0 {
|
|
|
|
|
|
let err_msg = response.message;
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(error, Type::Service, "停止核心失败: {}", err_msg);
|
2025-09-17 22:59:02 +08:00
|
|
|
|
bail!(err_msg);
|
2025-05-08 00:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务成功停止核心");
|
2025-02-15 05:51:46 +08:00
|
|
|
|
Ok(())
|
2022-11-17 20:19:40 +08:00
|
|
|
|
}
|
2025-03-03 14:42:31 +08:00
|
|
|
|
|
|
|
|
|
|
/// 检查服务是否正在运行
|
2025-05-26 16:08:16 +08:00
|
|
|
|
pub async fn is_service_available() -> Result<()> {
|
2025-10-11 23:40:37 +08:00
|
|
|
|
clash_verge_service_ipc::connect().await?;
|
2025-09-17 22:59:02 +08:00
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
2025-03-03 14:42:31 +08:00
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
pub fn is_service_ipc_path_exists() -> bool {
|
|
|
|
|
|
Path::new(clash_verge_service_ipc::IPC_PATH).exists()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 22:59:02 +08:00
|
|
|
|
impl ServiceManager {
|
|
|
|
|
|
pub fn default() -> Self {
|
|
|
|
|
|
Self(ServiceStatus::Unavailable("Need Checks".into()))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-11 23:40:37 +08:00
|
|
|
|
pub fn config() -> Option<clash_verge_service_ipc::IpcConfig> {
|
|
|
|
|
|
Some(clash_verge_service_ipc::IpcConfig {
|
|
|
|
|
|
default_timeout: Duration::from_millis(30),
|
|
|
|
|
|
retry_delay: Duration::from_millis(250),
|
|
|
|
|
|
max_retries: 6,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn init(&mut self) -> Result<()> {
|
|
|
|
|
|
if let Err(e) = clash_verge_service_ipc::connect().await {
|
|
|
|
|
|
self.0 = ServiceStatus::Unavailable("服务连接失败: {e}".to_string());
|
|
|
|
|
|
return Err(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 22:59:02 +08:00
|
|
|
|
pub fn current(&self) -> ServiceStatus {
|
|
|
|
|
|
self.0.clone()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn refresh(&mut self) -> Result<()> {
|
|
|
|
|
|
let status = self.check_service_comprehensive().await;
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging_error!(Type::Service, self.handle_service_status(&status).await);
|
2025-09-17 22:59:02 +08:00
|
|
|
|
self.0 = status;
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 综合服务状态检查(一次性完成所有检查)
|
|
|
|
|
|
pub async fn check_service_comprehensive(&self) -> ServiceStatus {
|
|
|
|
|
|
match is_service_available().await {
|
|
|
|
|
|
Ok(_) => {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务当前可用,检查是否需要重装");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
if check_service_needs_reinstall().await {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务需要重装且允许重装");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
ServiceStatus::NeedsReinstall
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ServiceStatus::Ready
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(err) => {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(warn, Type::Service, "服务不可用,检查安装状态");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
ServiceStatus::Unavailable(err.to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 根据服务状态执行相应操作
|
|
|
|
|
|
pub async fn handle_service_status(&mut self, status: &ServiceStatus) -> Result<()> {
|
|
|
|
|
|
match status {
|
|
|
|
|
|
ServiceStatus::Ready => {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务就绪,直接启动");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
ServiceStatus::NeedsReinstall | ServiceStatus::ReinstallRequired => {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务需要重装,执行重装流程");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
reinstall_service().await?;
|
|
|
|
|
|
self.0 = ServiceStatus::Ready;
|
|
|
|
|
|
}
|
|
|
|
|
|
ServiceStatus::ForceReinstallRequired => {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务需要强制重装,执行强制重装流程");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
force_reinstall_service().await?;
|
|
|
|
|
|
self.0 = ServiceStatus::Ready;
|
2025-05-08 00:14:58 +08:00
|
|
|
|
}
|
2025-09-17 22:59:02 +08:00
|
|
|
|
ServiceStatus::InstallRequired => {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "需要安装服务,执行安装流程");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
install_service().await?;
|
|
|
|
|
|
self.0 = ServiceStatus::Ready;
|
|
|
|
|
|
}
|
|
|
|
|
|
ServiceStatus::UninstallRequired => {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
|
logging!(info, Type::Service, "服务需要卸载,执行卸载流程");
|
2025-09-17 22:59:02 +08:00
|
|
|
|
uninstall_service().await?;
|
|
|
|
|
|
self.0 = ServiceStatus::Unavailable("Service Uninstalled".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
ServiceStatus::Unavailable(reason) => {
|
|
|
|
|
|
logging!(
|
|
|
|
|
|
info,
|
|
|
|
|
|
Type::Service,
|
|
|
|
|
|
"服务不可用: {},将使用Sidecar模式",
|
|
|
|
|
|
reason
|
|
|
|
|
|
);
|
|
|
|
|
|
self.0 = ServiceStatus::Unavailable(reason.clone());
|
2025-10-11 23:40:37 +08:00
|
|
|
|
return Err(anyhow::anyhow!("服务不可用: {}", reason));
|
2025-09-17 22:59:02 +08:00
|
|
|
|
}
|
2025-05-08 00:14:58 +08:00
|
|
|
|
}
|
2025-10-11 23:40:37 +08:00
|
|
|
|
Ok(())
|
2025-03-25 23:05:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 22:59:02 +08:00
|
|
|
|
pub static SERVICE_MANAGER: Lazy<Mutex<ServiceManager>> =
|
|
|
|
|
|
Lazy::new(|| Mutex::new(ServiceManager::default()));
|