mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-09 11:52:08 +08:00
refactor: backend (#7102)
* refactor(tray): move tray log opening to utils helper * refactor(enhance): move owned config through pipeline * refactor(enhance): move sequence values in use_seq * refactor(enhance): move values while sorting fields * refactor(enhance): move values when lowercasing owned config * refactor(backend): move owned config values in utilities * refactor(tray): borrow hotkey accelerators * refactor(core): borrow proxy config strings * fix(backend): preserve config patch semantics * refactor(enhance): clarify config transform names
This commit is contained in:
@@ -6,8 +6,11 @@ use crate::process::AsyncHandler;
|
||||
use crate::singleton;
|
||||
use crate::utils::window_manager::WindowManager;
|
||||
use crate::{
|
||||
Type, cmd, config::Config, feat, logging, module::lightweight::is_in_lightweight_mode,
|
||||
utils::dirs::find_target_icons,
|
||||
Type, cmd,
|
||||
config::Config,
|
||||
feat, logging,
|
||||
module::lightweight::is_in_lightweight_mode,
|
||||
utils::{dirs::find_target_icons, help},
|
||||
};
|
||||
use clash_verge_limiter::{Limiter, SystemClock, SystemLimiter};
|
||||
use clash_verge_logging::logging_error;
|
||||
@@ -399,7 +402,7 @@ impl Tray {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_hotkeys(hotkeys: &Option<Vec<String>>) -> HashMap<String, String> {
|
||||
fn create_hotkeys(hotkeys: &Option<Vec<String>>) -> HashMap<&str, &str> {
|
||||
hotkeys
|
||||
.as_ref()
|
||||
.map(|h| {
|
||||
@@ -412,13 +415,13 @@ fn create_hotkeys(hotkeys: &Option<Vec<String>>) -> HashMap<String, String> {
|
||||
if key.to_uppercase().contains("NUMPAD") {
|
||||
None
|
||||
} else {
|
||||
Some((func.into(), key.into()))
|
||||
Some((func, key))
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.collect::<std::collections::HashMap<String, String>>()
|
||||
.collect::<HashMap<&str, &str>>()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
@@ -655,7 +658,7 @@ async fn create_tray_menu(
|
||||
MenuIds::DASHBOARD,
|
||||
&texts.dashboard,
|
||||
true,
|
||||
hotkeys.get("open_or_close_dashboard").map(|s| s.as_str()),
|
||||
hotkeys.get("open_or_close_dashboard").copied(),
|
||||
)?;
|
||||
|
||||
let rule_mode = &CheckMenuItem::with_id(
|
||||
@@ -664,7 +667,7 @@ async fn create_tray_menu(
|
||||
&texts.rule_mode,
|
||||
true,
|
||||
current_proxy_mode == "rule",
|
||||
hotkeys.get("clash_mode_rule").map(|s| s.as_str()),
|
||||
hotkeys.get("clash_mode_rule").copied(),
|
||||
)?;
|
||||
|
||||
let global_mode = &CheckMenuItem::with_id(
|
||||
@@ -673,7 +676,7 @@ async fn create_tray_menu(
|
||||
&texts.global_mode,
|
||||
true,
|
||||
current_proxy_mode == "global",
|
||||
hotkeys.get("clash_mode_global").map(|s| s.as_str()),
|
||||
hotkeys.get("clash_mode_global").copied(),
|
||||
)?;
|
||||
|
||||
let direct_mode = &CheckMenuItem::with_id(
|
||||
@@ -682,7 +685,7 @@ async fn create_tray_menu(
|
||||
&texts.direct_mode,
|
||||
true,
|
||||
current_proxy_mode == "direct",
|
||||
hotkeys.get("clash_mode_direct").map(|s| s.as_str()),
|
||||
hotkeys.get("clash_mode_direct").copied(),
|
||||
)?;
|
||||
|
||||
let outbound_modes = if show_outbound_modes_inline {
|
||||
@@ -730,7 +733,7 @@ async fn create_tray_menu(
|
||||
&texts.system_proxy,
|
||||
true,
|
||||
system_proxy_enabled,
|
||||
hotkeys.get("toggle_system_proxy").map(|s| s.as_str()),
|
||||
hotkeys.get("toggle_system_proxy").copied(),
|
||||
)?;
|
||||
|
||||
let tun_mode = &CheckMenuItem::with_id(
|
||||
@@ -739,7 +742,7 @@ async fn create_tray_menu(
|
||||
&texts.tun_mode,
|
||||
tun_mode_available,
|
||||
tun_mode_enabled,
|
||||
hotkeys.get("toggle_tun_mode").map(|s| s.as_str()),
|
||||
hotkeys.get("toggle_tun_mode").copied(),
|
||||
)?;
|
||||
|
||||
let close_all_connections = &MenuItem::with_id(
|
||||
@@ -756,7 +759,7 @@ async fn create_tray_menu(
|
||||
&texts.lightweight_mode,
|
||||
true,
|
||||
is_lightweight_mode,
|
||||
hotkeys.get("entry_lightweight_mode").map(|s| s.as_str()),
|
||||
hotkeys.get("entry_lightweight_mode").copied(),
|
||||
)?;
|
||||
|
||||
let copy_env = &MenuItem::with_id(app_handle, MenuIds::COPY_ENV, &texts.copy_env, true, None::<&str>)?;
|
||||
@@ -811,7 +814,7 @@ async fn create_tray_menu(
|
||||
],
|
||||
)?;
|
||||
|
||||
let quit_accelerator = hotkeys.get("quit").map(|s| s.as_str());
|
||||
let quit_accelerator = hotkeys.get("quit").copied();
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let quit_accelerator = quit_accelerator.or(Some("Cmd+Q"));
|
||||
@@ -953,10 +956,10 @@ fn on_menu_event(_: &AppHandle, event: MenuEvent) {
|
||||
let _ = cmd::open_logs_dir().await;
|
||||
}
|
||||
MenuIds::APP_LOG => {
|
||||
let _ = cmd::open_app_log().await;
|
||||
let _ = help::open_app_latest_log();
|
||||
}
|
||||
MenuIds::CORE_LOG => {
|
||||
let _ = cmd::open_core_log().await;
|
||||
let _ = help::open_core_latest_log();
|
||||
}
|
||||
MenuIds::RESTART_CLASH => feat::restart_clash_core().await,
|
||||
MenuIds::RESTART_APP => feat::restart_app().await,
|
||||
|
||||
Reference in New Issue
Block a user