feat(proxy): add proxy commands and integrate with API

Add new proxy.rs module with get_proxies and get_providers_proxies commands.
Update mod.rs and lib.rs to re-export and register proxy commands.
Update API.ts to use invoke for proxy commands.
Minor formatting improvements in module/mihomo.rs.
This commit is contained in:
Tunglies
2025-03-04 01:01:24 +08:00
parent 3b69465016
commit 1ba688727e
5 changed files with 81 additions and 29 deletions

View File

@@ -15,6 +15,7 @@ pub mod verge;
pub mod runtime;
pub mod save_profile;
pub mod system;
pub mod proxy;
// Re-export all command functions for backwards compatibility
pub use profile::*;
@@ -27,4 +28,5 @@ pub use clash::*;
pub use verge::*;
pub use runtime::*;
pub use save_profile::*;
pub use system::*;
pub use system::*;
pub use proxy::*;

View File

@@ -0,0 +1,35 @@
use super::CmdResult;
use crate::module::mihomo::MihomoManager;
use tauri::async_runtime;
#[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)
}
#[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)
}