mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
fix: improve service availability checks #5788
This commit is contained in:
@@ -469,9 +469,10 @@ pub(super) async fn stop_core_by_service() -> Result<()> {
|
||||
|
||||
/// 检查服务是否正在运行
|
||||
pub async fn is_service_available() -> Result<()> {
|
||||
// Service client 当前会优先判断 IPC 文件是否存在
|
||||
// 睡一会等文件拉起服务
|
||||
tokio::time::sleep(Duration::from_millis(725)).await;
|
||||
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);
|
||||
return Err(e.into());
|
||||
}
|
||||
clash_verge_service_ipc::connect().await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -480,8 +481,6 @@ pub async fn is_service_available() -> Result<()> {
|
||||
/// TODO 使用 tokio select 之类机制并结合 timeout 实现更优雅的等待机制,期望等待文件出现,再尝试连接
|
||||
pub async fn wait_and_check_service_available(status: &mut ServiceManager) -> Result<()> {
|
||||
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?;
|
||||
status.0 = ServiceStatus::Ready;
|
||||
Ok(())
|
||||
@@ -498,8 +497,8 @@ impl ServiceManager {
|
||||
|
||||
pub const fn config() -> clash_verge_service_ipc::IpcConfig {
|
||||
clash_verge_service_ipc::IpcConfig {
|
||||
default_timeout: Duration::from_millis(60),
|
||||
retry_delay: Duration::from_millis(250),
|
||||
default_timeout: Duration::from_millis(100),
|
||||
retry_delay: Duration::from_millis(200),
|
||||
max_retries: 6,
|
||||
}
|
||||
}
|
||||
@@ -525,7 +524,6 @@ impl ServiceManager {
|
||||
|
||||
/// 综合服务状态检查(一次性完成所有检查)
|
||||
pub async fn check_service_comprehensive(&self) -> ServiceStatus {
|
||||
tokio::time::sleep(Duration::from_millis(125)).await;
|
||||
match check_service_needs_reinstall().await {
|
||||
Ok(need) => {
|
||||
logging!(debug, Type::Service, "服务当前可用,检查是否需要重装");
|
||||
|
||||
Reference in New Issue
Block a user