refacture: Mihomo API integration (#2900)

* feat: add mihomo_api crate as a workspace member

Added a new mihomo_api crate to handle interactions with the Mihomo API. This modular approach provides a dedicated interface for fetching and managing proxy data from Mihomo servers. The implementation includes functionality to refresh and retrieve both proxies and provider proxies with proper error handling and timeouts. Added this crate as a workspace member and included it as a dependency in the main project.

* Refactors Mihomo API integration

Simplifies proxy fetching by removing the MihomoManager structure.

Updates the get_proxies and get_providers_proxies functions to directly use the mihomo_api module.

Removes unused Mihomo API related files and modules for cleaner codebase.

Enhances overall maintainability and performance.
This commit is contained in:
Tunglies
2025-03-05 00:45:08 +08:00
committed by GitHub
parent 7ea7ca1415
commit 4ed36f6223
21 changed files with 190 additions and 411 deletions

View File

@@ -1,35 +1,26 @@
use super::CmdResult;
use crate::module::mihomo::MihomoManager;
use tauri::async_runtime;
use crate::core;
use mihomo_api;
#[tauri::command]
pub async fn get_proxies() -> CmdResult<serde_json::Value> {
let proxies = async_runtime::spawn_blocking(|| {
let rt = tokio::runtime::Runtime::new().unwrap();
let manager = MihomoManager::new();
{
let mut write_guard = manager.write();
rt.block_on(write_guard.refresh_proxies());
}
let read_guard = manager.read();
read_guard.fetch_proxies().clone()
})
.await.map_err(|e| e.to_string())?;
Ok(proxies)
let (mihomo_server, _) = core::clash_api::clash_client_info().unwrap();
let mihomo = mihomo_api::MihomoManager::new(mihomo_server);
Ok(mihomo
.refresh_proxies()
.await
.unwrap()
.get_proxies())
}
#[tauri::command]
pub async fn get_providers_proxies() -> CmdResult<serde_json::Value> {
let providers_proxies = async_runtime::spawn_blocking(|| {
let rt = tokio::runtime::Runtime::new().unwrap();
let manager = MihomoManager::new();
{
let mut write_guard = manager.write();
rt.block_on(write_guard.refresh_providers_proxies());
}
let read_guard = manager.read();
read_guard.fetch_providers_proxies().clone()
})
.await.map_err(|e| e.to_string())?;
Ok(providers_proxies)
}
let (mihomo_server, _) = core::clash_api::clash_client_info().unwrap();
let mihomo = mihomo_api::MihomoManager::new(mihomo_server);
Ok(mihomo
.refresh_providers_proxies()
.await
.unwrap()
.get_providers_proxies())
}