fix(proxy): check if proxy port is in use #5891

This commit is contained in:
Tunglies
2025-12-20 19:10:38 +08:00
parent 5afe11e55b
commit 16c3dcc616
21 changed files with 103 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ use clash_verge_logging::{Type, logging};
use gethostname::gethostname;
use network_interface::NetworkInterface;
use serde_yaml_ng::Mapping;
use std::net::TcpListener;
use sysproxy::{Autoproxy, Sysproxy};
use tauri_plugin_clash_verge_sysinfo;
@@ -95,3 +96,11 @@ pub fn get_network_interfaces_info() -> CmdResult<Vec<NetworkInterface>> {
Ok(result)
}
#[tauri::command]
pub fn is_port_in_use(port: u16) -> bool {
match TcpListener::bind(("127.0.0.1", port)) {
Ok(_listener) => false,
Err(_) => true,
}
}

View File

@@ -137,6 +137,7 @@ mod app_init {
tauri_plugin_clash_verge_sysinfo::commands::get_app_uptime,
tauri_plugin_clash_verge_sysinfo::commands::app_is_admin,
tauri_plugin_clash_verge_sysinfo::commands::export_diagnostic_info,
cmd::is_port_in_use,
cmd::get_sys_proxy,
cmd::get_auto_proxy,
cmd::open_app_dir,