mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor(Draft): Replace latest() with latest_ref() and data() with data_mut() in multiple files for improved mutability handling and consistency across the codebase (#3987)
* feat: add benchmarking for draft operations and new draft management structure * Refactor Config Access: Replace `latest()` with `latest_ref()` and `data()` with `data_mut()` in multiple files for improved mutability handling and consistency across the codebase. * refactor: remove DraftNew implementation and related benchmarks for cleaner codebase
This commit is contained in:
@@ -118,9 +118,9 @@ pub async fn find_unused_port() -> Result<u16> {
|
||||
}
|
||||
Err(_) => {
|
||||
let port = Config::verge()
|
||||
.latest()
|
||||
.latest_ref()
|
||||
.verge_mixed_port
|
||||
.unwrap_or(Config::clash().data().get_mixed_port());
|
||||
.unwrap_or(Config::clash().latest_ref().get_mixed_port());
|
||||
log::warn!(target: "app", "use default port: {port}");
|
||||
Ok(port)
|
||||
}
|
||||
@@ -160,7 +160,7 @@ pub async fn resolve_setup_async(app_handle: &AppHandle) {
|
||||
// 启动时清理冗余的 Profile 文件
|
||||
logging!(info, Type::Setup, true, "清理冗余的Profile文件...");
|
||||
let profiles = Config::profiles();
|
||||
if let Err(e) = profiles.latest().auto_cleanup() {
|
||||
if let Err(e) = profiles.latest_ref().auto_cleanup() {
|
||||
logging!(warn, Type::Setup, true, "启动时清理Profile文件失败: {}", e);
|
||||
} else {
|
||||
logging!(info, Type::Setup, true, "启动时Profile文件清理完成");
|
||||
@@ -204,7 +204,7 @@ pub async fn resolve_setup_async(app_handle: &AppHandle) {
|
||||
);
|
||||
|
||||
// 创建窗口
|
||||
let is_silent_start = { Config::verge().data().enable_silent_start }.unwrap_or(false);
|
||||
let is_silent_start = { Config::verge().latest_ref().enable_silent_start }.unwrap_or(false);
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
if is_silent_start {
|
||||
@@ -574,7 +574,7 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
|
||||
match PrfItem::from_url(url.as_ref(), name, None, None).await {
|
||||
Ok(item) => {
|
||||
let uid = item.uid.clone().unwrap();
|
||||
let _ = wrap_err!(Config::profiles().data().append_item(item));
|
||||
let _ = wrap_err!(Config::profiles().data_mut().append_item(item));
|
||||
handle::Handle::notice_message("import_sub_url::ok", uid);
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -592,12 +592,15 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
|
||||
async fn resolve_random_port_config() -> Result<()> {
|
||||
let verge_config = Config::verge();
|
||||
let clash_config = Config::clash();
|
||||
let enable_random_port = verge_config.latest().enable_random_port.unwrap_or(false);
|
||||
let enable_random_port = verge_config
|
||||
.latest_ref()
|
||||
.enable_random_port
|
||||
.unwrap_or(false);
|
||||
|
||||
let default_port = verge_config
|
||||
.latest()
|
||||
.latest_ref()
|
||||
.verge_mixed_port
|
||||
.unwrap_or(clash_config.data().get_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)
|
||||
@@ -609,7 +612,7 @@ async fn resolve_random_port_config() -> Result<()> {
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let verge_config_accessor = Config::verge();
|
||||
let mut verge_data = verge_config_accessor.data();
|
||||
let mut verge_data = verge_config_accessor.data_mut();
|
||||
verge_data.patch_config(IVerge {
|
||||
verge_mixed_port: Some(port_to_save),
|
||||
..IVerge::default()
|
||||
@@ -620,7 +623,7 @@ async fn resolve_random_port_config() -> Result<()> {
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let clash_config_accessor = Config::clash(); // Extend lifetime of the accessor
|
||||
let mut clash_data = clash_config_accessor.data(); // Access within blocking task, made mutable
|
||||
let mut clash_data = clash_config_accessor.data_mut(); // Access within blocking task, made mutable
|
||||
let mut mapping = Mapping::new();
|
||||
mapping.insert("mixed-port".into(), port_to_save.into());
|
||||
clash_data.patch_config(mapping);
|
||||
|
||||
Reference in New Issue
Block a user