mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-16 23:40:32 +08:00
refactor: remove port_scanner dependency and simplify port checking logic
This commit is contained in:
parent
a5752f7b00
commit
af094bfcd7
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -1220,7 +1220,6 @@ dependencies = [
|
|||||||
"open",
|
"open",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"port_scanner",
|
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"reqwest_dav",
|
"reqwest_dav",
|
||||||
@ -5656,12 +5655,6 @@ dependencies = [
|
|||||||
"universal-hash",
|
"universal-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "port_scanner"
|
|
||||||
version = "0.1.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "325a6d2ac5dee293c3b2612d4993b98aec1dff096b0a2dae70ed7d95784a05da"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "portable-atomic"
|
name = "portable-atomic"
|
||||||
version = "1.11.1"
|
version = "1.11.1"
|
||||||
|
|||||||
@ -61,7 +61,6 @@ nanoid = "0.4"
|
|||||||
chrono = "0.4.42"
|
chrono = "0.4.42"
|
||||||
boa_engine = "0.21.0"
|
boa_engine = "0.21.0"
|
||||||
once_cell = { version = "1.21.3", features = ["parking_lot"] }
|
once_cell = { version = "1.21.3", features = ["parking_lot"] }
|
||||||
port_scanner = "0.1.5"
|
|
||||||
delay_timer = "0.11.6"
|
delay_timer = "0.11.6"
|
||||||
percent-encoding = "2.3.2"
|
percent-encoding = "2.3.2"
|
||||||
reqwest = { version = "0.12.24", features = ["json", "cookies", "rustls-tls"] }
|
reqwest = { version = "0.12.24", features = ["json", "cookies", "rustls-tls"] }
|
||||||
|
|||||||
@ -99,8 +99,5 @@ pub fn get_network_interfaces_info() -> CmdResult<Vec<NetworkInterface>> {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn is_port_in_use(port: u16) -> bool {
|
pub fn is_port_in_use(port: u16) -> bool {
|
||||||
match TcpListener::bind(("127.0.0.1", port)) {
|
TcpListener::bind(("127.0.0.1", port)).is_err()
|
||||||
Ok(_listener) => false,
|
|
||||||
Err(_) => true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use super::resolve;
|
use super::resolve;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
cmd::is_port_in_use,
|
||||||
config::{Config, DEFAULT_PAC, IVerge},
|
config::{Config, DEFAULT_PAC, IVerge},
|
||||||
module::lightweight,
|
module::lightweight,
|
||||||
process::AsyncHandler,
|
process::AsyncHandler,
|
||||||
@ -9,7 +10,6 @@ use anyhow::{Result, bail};
|
|||||||
use clash_verge_logging::{Type, logging, logging_error};
|
use clash_verge_logging::{Type, logging, logging_error};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use port_scanner::local_port_available;
|
|
||||||
use reqwest::ClientBuilder;
|
use reqwest::ClientBuilder;
|
||||||
use smartstring::alias::String;
|
use smartstring::alias::String;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -27,7 +27,7 @@ static SHUTDOWN_SENDER: OnceCell<Mutex<Option<oneshot::Sender<()>>>> = OnceCell:
|
|||||||
/// check whether there is already exists
|
/// check whether there is already exists
|
||||||
pub async fn check_singleton() -> Result<()> {
|
pub async fn check_singleton() -> Result<()> {
|
||||||
let port = IVerge::get_singleton_port();
|
let port = IVerge::get_singleton_port();
|
||||||
if !local_port_available(port) {
|
if is_port_in_use(port) {
|
||||||
let client = ClientBuilder::new().timeout(Duration::from_millis(500)).build()?;
|
let client = ClientBuilder::new().timeout(Duration::from_millis(500)).build()?;
|
||||||
// 需要确保 Send
|
// 需要确保 Send
|
||||||
#[allow(clippy::needless_collect)]
|
#[allow(clippy::needless_collect)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user