mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
refactor: remove port_scanner dependency and simplify port checking logic
This commit is contained in:
@@ -99,8 +99,5 @@ pub fn get_network_interfaces_info() -> CmdResult<Vec<NetworkInterface>> {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn is_port_in_use(port: u16) -> bool {
|
||||
match TcpListener::bind(("127.0.0.1", port)) {
|
||||
Ok(_listener) => false,
|
||||
Err(_) => true,
|
||||
}
|
||||
TcpListener::bind(("127.0.0.1", port)).is_err()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::resolve;
|
||||
use crate::{
|
||||
cmd::is_port_in_use,
|
||||
config::{Config, DEFAULT_PAC, IVerge},
|
||||
module::lightweight,
|
||||
process::AsyncHandler,
|
||||
@@ -9,7 +10,6 @@ use anyhow::{Result, bail};
|
||||
use clash_verge_logging::{Type, logging, logging_error};
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use port_scanner::local_port_available;
|
||||
use reqwest::ClientBuilder;
|
||||
use smartstring::alias::String;
|
||||
use std::time::Duration;
|
||||
@@ -27,7 +27,7 @@ static SHUTDOWN_SENDER: OnceCell<Mutex<Option<oneshot::Sender<()>>>> = OnceCell:
|
||||
/// check whether there is already exists
|
||||
pub async fn check_singleton() -> Result<()> {
|
||||
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()?;
|
||||
// 需要确保 Send
|
||||
#[allow(clippy::needless_collect)]
|
||||
|
||||
Reference in New Issue
Block a user