mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-28 16:30:52 +08:00
renew: remove whether to enable_random_port (#4401)
* refactor: streamline clean old assets job by using reusable workflow
* refactor: update clean old assets job to include steps section
* refactor: add checkout step in clean_old_assets job for improved repository access
* fix: correct path to clean old assets workflow in autobuild.yml
* fix: update path to clean old assets workflow in autobuild.yml
* refactor: simplify clean_old_assets job by removing unnecessary steps
* refactor: enhance clean_old_assets job dependencies for improved execution flow
* Revert "refactor: enhance clean_old_assets job dependencies for improved execution flow"
This reverts commit 1a5108b5ad.
* feat: implement get_latest_tauri_commit script and update release versioning logic
* renew: remove whether to enable_random_port
---------
Co-authored-by: Tunglies <77394545+Tunglies@users.noreply.github.com>
This commit is contained in:
@@ -138,9 +138,6 @@ pub struct IVerge {
|
|||||||
/// 0: 不清理; 1: 1天;2: 7天; 3: 30天; 4: 90天
|
/// 0: 不清理; 1: 1天;2: 7天; 3: 30天; 4: 90天
|
||||||
pub auto_log_clean: Option<i32>,
|
pub auto_log_clean: Option<i32>,
|
||||||
|
|
||||||
/// 是否启用随机端口
|
|
||||||
pub enable_random_port: Option<bool>,
|
|
||||||
|
|
||||||
/// verge 的各种 port 用于覆盖 clash 的各种 port
|
/// verge 的各种 port 用于覆盖 clash 的各种 port
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub verge_redir_port: Option<u16>,
|
pub verge_redir_port: Option<u16>,
|
||||||
@@ -374,7 +371,6 @@ impl IVerge {
|
|||||||
proxy_auto_config: Some(false),
|
proxy_auto_config: Some(false),
|
||||||
pac_file_content: Some(DEFAULT_PAC.into()),
|
pac_file_content: Some(DEFAULT_PAC.into()),
|
||||||
proxy_host: Some("127.0.0.1".into()),
|
proxy_host: Some("127.0.0.1".into()),
|
||||||
enable_random_port: Some(false),
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
verge_redir_port: Some(7895),
|
verge_redir_port: Some(7895),
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
@@ -448,7 +444,6 @@ impl IVerge {
|
|||||||
patch!(enable_auto_launch);
|
patch!(enable_auto_launch);
|
||||||
patch!(enable_silent_start);
|
patch!(enable_silent_start);
|
||||||
patch!(enable_hover_jump_navigator);
|
patch!(enable_hover_jump_navigator);
|
||||||
patch!(enable_random_port);
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
patch!(verge_redir_port);
|
patch!(verge_redir_port);
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
@@ -567,7 +562,6 @@ pub struct IVergeResponse {
|
|||||||
pub proxy_layout_column: Option<i32>,
|
pub proxy_layout_column: Option<i32>,
|
||||||
pub test_list: Option<Vec<IVergeTestItem>>,
|
pub test_list: Option<Vec<IVergeTestItem>>,
|
||||||
pub auto_log_clean: Option<i32>,
|
pub auto_log_clean: Option<i32>,
|
||||||
pub enable_random_port: Option<bool>,
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub verge_redir_port: Option<u16>,
|
pub verge_redir_port: Option<u16>,
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
@@ -640,7 +634,6 @@ impl From<IVerge> for IVergeResponse {
|
|||||||
proxy_layout_column: verge.proxy_layout_column,
|
proxy_layout_column: verge.proxy_layout_column,
|
||||||
test_list: verge.test_list,
|
test_list: verge.test_list,
|
||||||
auto_log_clean: verge.auto_log_clean,
|
auto_log_clean: verge.auto_log_clean,
|
||||||
enable_random_port: verge.enable_random_port,
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
verge_redir_port: verge.verge_redir_port,
|
verge_redir_port: verge.verge_redir_port,
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use crate::AppHandleManager;
|
use crate::AppHandleManager;
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{Config, IVerge, PrfItem},
|
config::{Config, PrfItem},
|
||||||
core::*,
|
core::*,
|
||||||
logging, logging_error,
|
logging, logging_error,
|
||||||
module::lightweight::{self, auto_lightweight_mode_init},
|
module::lightweight::{self, auto_lightweight_mode_init},
|
||||||
@@ -14,10 +14,8 @@ use once_cell::sync::OnceCell;
|
|||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
use percent_encoding::percent_decode_str;
|
use percent_encoding::percent_decode_str;
|
||||||
use scopeguard;
|
use scopeguard;
|
||||||
use serde_yaml::Mapping;
|
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use tauri::{AppHandle, Manager};
|
use tauri::{AppHandle, Manager};
|
||||||
use tokio::net::TcpListener;
|
|
||||||
|
|
||||||
use tauri::Url;
|
use tauri::Url;
|
||||||
//#[cfg(not(target_os = "linux"))]
|
//#[cfg(not(target_os = "linux"))]
|
||||||
@@ -107,23 +105,6 @@ pub fn reset_ui_ready() {
|
|||||||
logging!(info, Type::Window, true, "UI就绪状态已重置");
|
logging!(info, Type::Window, true, "UI就绪状态已重置");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_unused_port() -> Result<u16> {
|
|
||||||
match TcpListener::bind("127.0.0.1:0").await {
|
|
||||||
Ok(listener) => {
|
|
||||||
let port = listener.local_addr()?.port();
|
|
||||||
Ok(port)
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
let port = Config::verge()
|
|
||||||
.latest_ref()
|
|
||||||
.verge_mixed_port
|
|
||||||
.unwrap_or(Config::clash().latest_ref().get_mixed_port());
|
|
||||||
log::warn!(target: "app", "use default port: {port}");
|
|
||||||
Ok(port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 异步方式处理启动后的额外任务
|
/// 异步方式处理启动后的额外任务
|
||||||
pub async fn resolve_setup_async(app_handle: &AppHandle) {
|
pub async fn resolve_setup_async(app_handle: &AppHandle) {
|
||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
@@ -147,16 +128,6 @@ pub async fn resolve_setup_async(app_handle: &AppHandle) {
|
|||||||
|
|
||||||
logging_error!(Type::Setup, true, init::startup_script().await);
|
logging_error!(Type::Setup, true, init::startup_script().await);
|
||||||
|
|
||||||
if let Err(err) = resolve_random_port_config().await {
|
|
||||||
logging!(
|
|
||||||
error,
|
|
||||||
Type::System,
|
|
||||||
true,
|
|
||||||
"Failed to resolve random port config: {}",
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
logging!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
Type::Config,
|
Type::Config,
|
||||||
@@ -686,64 +657,6 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn resolve_random_port_config() -> Result<()> {
|
|
||||||
let verge_config = Config::verge();
|
|
||||||
let clash_config = Config::clash();
|
|
||||||
let enable_random_port = verge_config
|
|
||||||
.latest_ref()
|
|
||||||
.enable_random_port
|
|
||||||
.unwrap_or(false);
|
|
||||||
|
|
||||||
let default_port = verge_config
|
|
||||||
.latest_ref()
|
|
||||||
.verge_mixed_port
|
|
||||||
.unwrap_or(clash_config.latest_ref().get_mixed_port());
|
|
||||||
|
|
||||||
let port = if enable_random_port {
|
|
||||||
find_unused_port().await.unwrap_or(default_port)
|
|
||||||
} else {
|
|
||||||
default_port
|
|
||||||
};
|
|
||||||
|
|
||||||
let port_to_save = port;
|
|
||||||
|
|
||||||
// 合并配置访问以避免锁竞争死锁
|
|
||||||
tokio::task::spawn_blocking(move || -> Result<()> {
|
|
||||||
logging!(
|
|
||||||
debug,
|
|
||||||
Type::Config,
|
|
||||||
true,
|
|
||||||
"开始合并配置更新操作,避免锁竞争"
|
|
||||||
);
|
|
||||||
|
|
||||||
// 按顺序更新配置,避免交叉锁定
|
|
||||||
{
|
|
||||||
let verge_accessor = Config::verge();
|
|
||||||
let mut verge_data = verge_accessor.data_mut();
|
|
||||||
verge_data.patch_config(IVerge {
|
|
||||||
verge_mixed_port: Some(port_to_save),
|
|
||||||
..IVerge::default()
|
|
||||||
});
|
|
||||||
verge_data.save_file()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let clash_accessor = Config::clash();
|
|
||||||
let mut clash_data = clash_accessor.data_mut();
|
|
||||||
let mut mapping = Mapping::new();
|
|
||||||
mapping.insert("mixed-port".into(), port_to_save.into());
|
|
||||||
clash_data.patch_config(mapping);
|
|
||||||
clash_data.save_config()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
logging!(debug, Type::Config, true, "配置更新操作完成");
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub async fn set_public_dns(dns_server: String) {
|
pub async fn set_public_dns(dns_server: String) {
|
||||||
use crate::{core::handle, utils::dirs};
|
use crate::{core::handle, utils::dirs};
|
||||||
|
|||||||
Reference in New Issue
Block a user