mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-13 13:30:31 +08:00
fix: improve service availability checks #5788
This commit is contained in:
parent
cea78289c1
commit
e56a989944
24
Cargo.lock
generated
24
Cargo.lock
generated
@ -147,7 +147,7 @@ dependencies = [
|
|||||||
"objc2-foundation 0.3.2",
|
"objc2-foundation 0.3.2",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"windows-sys 0.60.2",
|
"windows-sys 0.59.0",
|
||||||
"wl-clipboard-rs",
|
"wl-clipboard-rs",
|
||||||
"x11rb",
|
"x11rb",
|
||||||
]
|
]
|
||||||
@ -1312,8 +1312,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clash_verge_service_ipc"
|
name = "clash_verge_service_ipc"
|
||||||
version = "2.0.24"
|
version = "2.0.25"
|
||||||
source = "git+https://github.com/clash-verge-rev/clash-verge-service-ipc#c5a557d5a9f15264697a8ac70d42946a881598d7"
|
source = "git+https://github.com/clash-verge-rev/clash-verge-service-ipc#c94cf2d5fde45d6c203c4d606dcdddfe0fc0a2fe"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"compact_str",
|
"compact_str",
|
||||||
@ -1372,7 +1372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2080,7 +2080,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"option-ext",
|
"option-ext",
|
||||||
"redox_users 0.5.2",
|
"redox_users 0.5.2",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2353,7 +2353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3880,7 +3880,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"hermit-abi 0.5.2",
|
"hermit-abi 0.5.2",
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -4671,7 +4671,7 @@ version = "0.50.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -5165,7 +5165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
|
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.45.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -5994,7 +5994,7 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"socket2 0.5.10",
|
"socket2 0.5.10",
|
||||||
"tracing",
|
"tracing",
|
||||||
"windows-sys 0.60.2",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -6557,7 +6557,7 @@ dependencies = [
|
|||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.11.0",
|
"linux-raw-sys 0.11.0",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -8076,7 +8076,7 @@ dependencies = [
|
|||||||
"getrandom 0.3.4",
|
"getrandom 0.3.4",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix 1.1.2",
|
"rustix 1.1.2",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@ -94,7 +94,7 @@ tauri-plugin-devtools = { version = "2.0.1" }
|
|||||||
tauri-plugin-mihomo = { git = "https://github.com/clash-verge-rev/tauri-plugin-mihomo" }
|
tauri-plugin-mihomo = { git = "https://github.com/clash-verge-rev/tauri-plugin-mihomo" }
|
||||||
clash_verge_logger = { git = "https://github.com/clash-verge-rev/clash-verge-logger" }
|
clash_verge_logger = { git = "https://github.com/clash-verge-rev/clash-verge-logger" }
|
||||||
async-trait = "0.1.89"
|
async-trait = "0.1.89"
|
||||||
clash_verge_service_ipc = { version = "2.0.24", features = [
|
clash_verge_service_ipc = { version = "2.0.25", features = [
|
||||||
"client",
|
"client",
|
||||||
], git = "https://github.com/clash-verge-rev/clash-verge-service-ipc" }
|
], git = "https://github.com/clash-verge-rev/clash-verge-service-ipc" }
|
||||||
arc-swap = "1.7.1"
|
arc-swap = "1.7.1"
|
||||||
|
|||||||
@ -469,9 +469,10 @@ pub(super) async fn stop_core_by_service() -> Result<()> {
|
|||||||
|
|
||||||
/// 检查服务是否正在运行
|
/// 检查服务是否正在运行
|
||||||
pub async fn is_service_available() -> Result<()> {
|
pub async fn is_service_available() -> Result<()> {
|
||||||
// Service client 当前会优先判断 IPC 文件是否存在
|
if let Err(e) = Path::metadata(clash_verge_service_ipc::IPC_PATH.as_ref()) {
|
||||||
// 睡一会等文件拉起服务
|
logging!(warn, Type::Service, "Some issue with service IPC Path: {}", e);
|
||||||
tokio::time::sleep(Duration::from_millis(725)).await;
|
return Err(e.into());
|
||||||
|
}
|
||||||
clash_verge_service_ipc::connect().await?;
|
clash_verge_service_ipc::connect().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -480,8 +481,6 @@ pub async fn is_service_available() -> Result<()> {
|
|||||||
/// TODO 使用 tokio select 之类机制并结合 timeout 实现更优雅的等待机制,期望等待文件出现,再尝试连接
|
/// TODO 使用 tokio select 之类机制并结合 timeout 实现更优雅的等待机制,期望等待文件出现,再尝试连接
|
||||||
pub async fn wait_and_check_service_available(status: &mut ServiceManager) -> Result<()> {
|
pub async fn wait_and_check_service_available(status: &mut ServiceManager) -> Result<()> {
|
||||||
status.0 = ServiceStatus::Unavailable("Waiting for service to be available".into());
|
status.0 = ServiceStatus::Unavailable("Waiting for service to be available".into());
|
||||||
// 过早返回可能导致 UI 侧积极尝试连接服务失败
|
|
||||||
tokio::time::sleep(Duration::from_millis(725)).await;
|
|
||||||
clash_verge_service_ipc::connect().await?;
|
clash_verge_service_ipc::connect().await?;
|
||||||
status.0 = ServiceStatus::Ready;
|
status.0 = ServiceStatus::Ready;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -498,8 +497,8 @@ impl ServiceManager {
|
|||||||
|
|
||||||
pub const fn config() -> clash_verge_service_ipc::IpcConfig {
|
pub const fn config() -> clash_verge_service_ipc::IpcConfig {
|
||||||
clash_verge_service_ipc::IpcConfig {
|
clash_verge_service_ipc::IpcConfig {
|
||||||
default_timeout: Duration::from_millis(60),
|
default_timeout: Duration::from_millis(100),
|
||||||
retry_delay: Duration::from_millis(250),
|
retry_delay: Duration::from_millis(200),
|
||||||
max_retries: 6,
|
max_retries: 6,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,7 +524,6 @@ impl ServiceManager {
|
|||||||
|
|
||||||
/// 综合服务状态检查(一次性完成所有检查)
|
/// 综合服务状态检查(一次性完成所有检查)
|
||||||
pub async fn check_service_comprehensive(&self) -> ServiceStatus {
|
pub async fn check_service_comprehensive(&self) -> ServiceStatus {
|
||||||
tokio::time::sleep(Duration::from_millis(125)).await;
|
|
||||||
match check_service_needs_reinstall().await {
|
match check_service_needs_reinstall().await {
|
||||||
Ok(need) => {
|
Ok(need) => {
|
||||||
logging!(debug, Type::Service, "服务当前可用,检查是否需要重装");
|
logging!(debug, Type::Service, "服务当前可用,检查是否需要重装");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user