mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-18 23:30:51 +08:00
* refactor(ipc): generate bindings with Specta * fix(profile): project IPC inputs to consumed fields * fix(events): remove unused refresh payloads * fix(webdav): return only consumed backup metadata * fix(network): trim unused interface metadata * fix(sysinfo): return only displayed system fields * chore(knip): check generated runtime exports * fix(proxy): confirm runtime chain updates before UI changes * fix(clipboard): propagate proxy environment copy failures * refactor(dns): remove ignored runtime patch * refactor(core): trim unused upgrade response fields * refactor(ipc): avoid redundant response copies * refactor(proxy): clarify automatic proxy query naming * chore(tests): remove added IPC regression tests * refactor(ipc): enforce typed command boundaries * chore(contract): check generated bindings before push * refactor(ipc): remove unused proxy liveness payloads
100 lines
2.6 KiB
Rust
100 lines
2.6 KiB
Rust
use super::CmdResult;
|
|
use crate::cmd::StringifyErr as _;
|
|
use crate::core::{proxy_control, sysopt::Sysopt};
|
|
|
|
use gethostname::gethostname;
|
|
use sysproxy::{Autoproxy, Sysproxy};
|
|
use tauri_plugin_clash_verge_sysinfo;
|
|
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn get_sys_proxy() -> CmdResult<SystemProxy> {
|
|
Sysopt::global().wait_idle().await;
|
|
// With no network service there is no proxy configured anywhere, which reads as disabled.
|
|
let sys_proxy = match Sysproxy::get_system_proxy() {
|
|
Err(error) if proxy_control::is_missing_network_service(&error) => Sysproxy::default(),
|
|
other => other.stringify_err()?,
|
|
};
|
|
let Sysproxy {
|
|
host,
|
|
bypass,
|
|
port,
|
|
enable,
|
|
} = sys_proxy;
|
|
|
|
Ok(SystemProxy {
|
|
enable,
|
|
server: format!("{host}:{port}"),
|
|
bypass,
|
|
})
|
|
}
|
|
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub async fn get_auto_proxy() -> CmdResult<AutoProxy> {
|
|
Sysopt::global().wait_idle().await;
|
|
let auto_proxy = match Autoproxy::get_auto_proxy() {
|
|
Err(error) if proxy_control::is_missing_network_service(&error) => Autoproxy::default(),
|
|
other => other.stringify_err()?,
|
|
};
|
|
let Autoproxy { enable, url } = auto_proxy;
|
|
|
|
Ok(AutoProxy { enable, url })
|
|
}
|
|
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub fn get_embedded_server_port() -> CmdResult<u16> {
|
|
crate::utils::server::embedded_server_port().stringify_err()
|
|
}
|
|
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub fn get_system_hostname() -> String {
|
|
match gethostname().into_string() {
|
|
Ok(name) => name,
|
|
Err(os_string) => {
|
|
let fallback = format!("{os_string:?}");
|
|
fallback.trim_matches('"').to_string()
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub fn get_network_interfaces() -> Vec<String> {
|
|
tauri_plugin_clash_verge_sysinfo::list_network_interfaces()
|
|
}
|
|
|
|
#[tauri::command]
|
|
#[specta::specta]
|
|
pub fn get_network_interfaces_info() -> CmdResult<Vec<crate::ipc::NetworkInterfaceView>> {
|
|
use network_interface::{NetworkInterface, NetworkInterfaceConfig as _};
|
|
|
|
let names = get_network_interfaces();
|
|
let interfaces = NetworkInterface::show().stringify_err()?;
|
|
|
|
let mut result = Vec::new();
|
|
|
|
for interface in interfaces {
|
|
if names.contains(&interface.name) {
|
|
result.push(interface.into());
|
|
}
|
|
}
|
|
|
|
Ok(result)
|
|
}
|
|
|
|
#[derive(serde::Serialize, specta::Type)]
|
|
pub struct SystemProxy {
|
|
pub enable: bool,
|
|
pub server: String,
|
|
pub bypass: String,
|
|
}
|
|
|
|
#[derive(serde::Serialize, specta::Type)]
|
|
pub struct AutoProxy {
|
|
pub enable: bool,
|
|
pub url: String,
|
|
}
|