mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-31 03:02:08 +08:00
* refactor(log): migrate logging to tracing-estuary pipeline Swap flexi_logger + clash-verge-logger wiring for the tracing-estuary crate: buffered file sink with explicit panic/exit drains, live level switching, and tokio-trace/chrome-trace behind crate features. AsyncLogger moves in-house (VecDeque ring); file format and rotation stay unchanged. * fix(log): reset sidecar writer in place and re-pin service-ipc v2.6.7 Rebuilding the sidecar FileLogWriter on config changes leaked flexi's unstoppable flusher thread plus an fd each time; the writer is now flushed and reset in place, matching what the service crate does. get_clash_logs_by_service drops the CompactString conversion layer now that service-ipc v2.6.7 returns plain Vec<String>, and AsyncLogger is renamed LogRing to match. * refactor(log): span-based observability and log noise cleanup Instrument spans carry the structure flat lines never could: the core-start spine (mode, readiness/owner generations, pid, config file), proxy apply and clear routes with guard generations, service IPC sessions with refusal codes and outcomes, profile-switch terminal outcomes, subscription fetch strategies, core upgrades with per-proxy version probes, backup flows, timer tasks, config generation uids, and the startup setup flow; running-mode changes emit one guarded transition event each. ~90 hand-written noise lines are gone or demoted (entry+success pairs, polled getter echoes, phase brackets, window sub-steps, platform install chatter); errors keep their anyhow chain, operation name, and item id, and swallowed retry results surface per attempt.
86 lines
2.5 KiB
Rust
86 lines
2.5 KiB
Rust
use super::CmdResult;
|
|
use crate::cmd::StringifyErr as _;
|
|
use crate::core::{proxy_control, sysopt::Sysopt};
|
|
|
|
use gethostname::gethostname;
|
|
use network_interface::NetworkInterface;
|
|
use serde_yaml_ng::Mapping;
|
|
use sysproxy::{Autoproxy, Sysproxy};
|
|
use tauri_plugin_clash_verge_sysinfo;
|
|
|
|
#[tauri::command]
|
|
pub async fn get_sys_proxy() -> CmdResult<Mapping> {
|
|
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 {
|
|
ref host,
|
|
ref bypass,
|
|
ref port,
|
|
ref enable,
|
|
} = sys_proxy;
|
|
|
|
let mut map = Mapping::new();
|
|
map.insert("enable".into(), (*enable).into());
|
|
map.insert("server".into(), format!("{}:{}", host, port).into());
|
|
map.insert("bypass".into(), bypass.as_str().into());
|
|
Ok(map)
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn get_auto_proxy() -> CmdResult<Mapping> {
|
|
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 { ref enable, ref url } = auto_proxy;
|
|
|
|
let mut map = Mapping::new();
|
|
map.insert("enable".into(), (*enable).into());
|
|
map.insert("url".into(), url.as_str().into());
|
|
Ok(map)
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn get_embedded_server_port() -> CmdResult<u16> {
|
|
crate::utils::server::embedded_server_port().stringify_err()
|
|
}
|
|
|
|
#[tauri::command]
|
|
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]
|
|
pub fn get_network_interfaces() -> Vec<String> {
|
|
tauri_plugin_clash_verge_sysinfo::list_network_interfaces()
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn get_network_interfaces_info() -> CmdResult<Vec<NetworkInterface>> {
|
|
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);
|
|
}
|
|
}
|
|
|
|
Ok(result)
|
|
}
|