mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 02:52:07 +08:00
* refactor(utils): drop dead reset helper and tidy init_resources
- remove resolve_reset_async, which had no callers
- drop the duplicated time.*.com entry from the default fake-ip-filter
- init_resources no longer recreates app_home (ensure_directories during
init_config already created it) and now propagates res_dir creation errors
* refactor(profile): remove identical blind retry when switching node
The second select_node_for_group call in switch_proxy_node was a
zero-interval retry with identical arguments. Its success path was a
degraded copy of the first (missing the Refresh::Proxies announcement
ever since the old force-refresh emit was removed), and its distinct
"回退/最终失败" log wording misled maintainers. Keep a single call,
the primary success aftermath, and one error log.
* refactor(enhance): simplify tun mode check and lowercase helpers
- Drop the always-true second clause in use_tun's enhanced-mode check:
the key is absent only when the unwrap_or default already makes
current_mode == "fake-ip" true.
- Collapse use_lowercase into a delegation to use_lowercase_owned.
* refactor(core): drop unreachable hotkey dtor and dedupe tray predicate
Remove impl Drop for Hotkey: the instance lives in a OnceLock static via
the singleton! macro and is never dropped; exit-time unregistration is
already handled by Hotkey::reset().
Spell the include_proxy_groups/display-mode predicate identically at
both evaluation sites in tray menu building; behavior is unchanged
(Option != Some("disable") is equivalent to unwrap_or("default") != "disable").
* refactor(config): fold port guards into single helper
The five IClashTemp port guards duplicated the same read/parse/default
logic with drifting defaults: some hardcoded 7895/7898/7899 while others
referenced network::ports constants. Route them all through one
guard_port_value helper and use the constants everywhere, keeping each
guard's name, key and cfg attributes.
* refactor(config): dedupe prfitem factories and companion seeding
from_rules/from_proxies/from_groups differed only in uid prefix, type
string and template, so they now delegate to a shared from_seq_item.
The five current_* accessors collapse into a local macro. The identical
five-block companion seeding in from_local and from_url moves into
ensure_companion_items, preserving seeding order and error propagation.
* refactor(config): share patch macro and profiles helpers
IVerge::patch_config, IProfiles::patch_item and PrfOption::merge each
hand-rolled the same copy-Some-overwrite pattern; they now share one
patch_opt_field macro (the or-else merge form is field-for-field
equivalent for Option fields). The four profiles *_safe wrappers that
inlined Config::profiles().with_data_modify boilerplate delegate to a
with_profiles_edit helper, and record/forget_selected_node share the
current-item lookup prelude via current_item_mut.
* refactor(enhance): merge chain processing and drop unused builtin js payload
- collapse the identical process_global_items/process_profile_items into
one parameterized process_override_items (entry uid sources unchanged)
- fold the identical rules/proxies/groups arms of ChainItem::from_async
into a single arm with an inner dispatch
- stop embedding builtin JS payloads never executed by any path: the
enhance loop dispatches builtin items by uid to native implementations,
so ChainItem::builtin now carries empty script data (uids unchanged)
- source ProfileItems fallback literals from Default instead of a second
hand-written copy in collect_profile_items
* refactor(net): reuse webpki tls config and fallback
Extract build_webpki_rooted_tls_config so the delay-test TLS connector
and the reqwest clients share one static-webpki-roots builder; ALPN
stays caller-specific (only reqwest offers h2).
Collapse the duplicated platform-verifier -> static-webpki-roots retry
in get/get_bytes into request_with_static_webpki_fallback, gated by the
caller's certificate-verification setting.
* refactor(app): extract common exit cleanup
restart_app and quit duplicate the whole exit preparation: set the
exiting flag, persist configs, run interactive cleanup, and on a failed
core stop clear the flag, restore public DNS under the lifecycle lock
on macOS, and send the stop-failed notice.
Move that flow into run_exit_cleanup_flow next to clean_async, taking
the notice variant as a parameter and returning the CleanupResult so
each caller keeps its own tail: restart aborts before shutdown, quit
always shuts down and exits with the cleanup code.
* refactor(backup): share restore finalize path
restore_webdav_backup and restore_local_backup duplicated the
credential extraction (backup creation strips the WebDAV credentials,
so both re-inject the live ones), the archive extraction and the
finalize tail. Move that tail into a private restore_backup_archive
helper so the two entries keep only their download/locate logic; the
config-write lock scope and the off-runtime extraction land in one
place. The webdav entry keeps its downloaded-file cleanup.
* refactor(sysopt): drop redundant lock and busy-wait
The proxy target pair sat behind an Arc<RwLock> with no readers and an
Arc that was never cloned; both writers already serialize on
update_lock, so store the pair inside that mutex and delete the RwLock.
refresh_guard waited for the guard to become ready with a yield_now spin
at full CPU while holding guard_operation_lock; a 10 ms sleep keeps the
same wait condition and lock scope without the spin.
* refactor(sysopt): share macos bypass formatting
The macOS default bypass list and its three-way composition (empty ->
default, default + custom, custom only) were maintained twice: in
sysopt's format_bypass and inline in proxy_control's service_bypass.
Keep the literal once in constants and compose both paths through
format_bypass; service_bypass keeps its NUL check and UTF-8 truncation.
* refactor(core): dedupe window listeners, elevated runners, backup settings
- Collapse the close/focus window listener pairs in lightweight.rs onto a shared WindowListener with per-listener event and log label.
- Extract the windows runas-or-direct execution into service::run_maybe_elevated, shared by win_uwp and the service uninstaller, and factor the common uninstaller path resolution and status check shared across platforms.
- Make the auto-backup watch channel the single settings source, replacing the duplicate Arc<RwLock> copy with a stored receiver.
* refactor(enhance): fold lowercase helpers into single owned function
use_lowercase_owned disappears; the surviving use_lowercase takes the
owned Mapping and borrowed callers clone at the call site.
* refactor(enhance): rename ChainSupport variants to Mihomo names
Clash is a legacy name; the variants match the verge-mihomo and
verge-mihomo-alpha cores they gate.
* refactor(enhance): lowercase takes a reference and chain support is copy
use_lowercase borrows the mapping and clones only the values; call
sites no longer clone whole configs. ChainSupport is a fieldless enum
and now Copy; builtin() registers each support pair without clones.
* refactor(config): name prfitem constructor for what it builds
new_seq_item states that a fresh item is built from a template; the
from_ prefix wrongly implied an existing source. append_companion_item
returns the uid directly: append_item bails on a missing uid, so the
Option was always Some on the Ok path.
* refactor(sysopt): name the proxy state lock for its full role
The lock now owns the (Sysproxy, Autoproxy) state, so proxy_state_lock
says what it guards; the guard locals follow. constants::proxy held a
single sysproxy constant and is renamed sysproxy.
* refactor: replace remaining clash meta naming with mihomo
Doc comment, generated bindings and the prebuild sidecar helpers stop
referring to the legacy Clash Meta name; installer legacy-process
cleanup keeps the old executable names on purpose.
* refactor(enhance): drop builtin core filtering that never discriminates
Both valid cores matched a different ChainSupport variant, yet each
variant registered the same uid pair, so the filtered builtin list was
identical for stable and alpha. Invalid cores are coerced at startup
(validate_and_fix_config / get_valid_clash_core) and the None arm of
is_support was unreachable. builtin() now returns the items directly
and the clash_core threading through ConfigValues goes away; re-add
core discrimination when a builtin actually differs per core.
* refactor(enhance): drop unreachable mode script guard
merge_default_config overwrites the profile's mode with the verge-owned
clash config, whose mode is always present (template seeds rule and
patch semantics never clear it) and restricted to rule/global/direct;
change_clash_mode is rejected by the core before persisting anything
else. mode:script can therefore only arrive through a hand-crafted
patch_clash call, and for that path an explicit invalid-mode validation
error is more honest than silently rewriting to rule. mihomo rejects
mode:script outright (invalid mode), and user merge/script chains run
after the builtins, so the guard never covered them anyway.
* refactor(enhance): call the hysteria alpn builtin directly
builtin() existed to feed the uid-dispatch loop; with a single
builtin the vec and match are ceremony. apply_builtin_scripts calls
builtin_hy_alpn directly and to_script goes away; tests construct
ChainItem literals the way the merge items already did.
537 lines
20 KiB
Rust
537 lines
20 KiB
Rust
use crate::config::Config;
|
|
use crate::{
|
|
config::{DEFAULT_PAC, deserialize_encrypted, patch_opt_field, serialize_encrypted},
|
|
constants::network,
|
|
utils::{dirs, help},
|
|
};
|
|
use anyhow::Result;
|
|
use clash_verge_logging::{Type, logging};
|
|
use log::LevelFilter;
|
|
use serde::{Deserialize, Serialize};
|
|
use smartstring::alias::String;
|
|
|
|
/// ### `verge.yaml` schema
|
|
#[derive(Default, Debug, Clone, Deserialize, Serialize, specta::Type)]
|
|
#[serde(default)]
|
|
pub struct IVerge {
|
|
/// silent | error | warn | info | debug | trace
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub app_log_level: Option<String>,
|
|
|
|
/// Maximum app log size in KiB.
|
|
pub app_log_max_size: Option<u64>,
|
|
|
|
pub app_log_max_count: Option<usize>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub language: Option<String>,
|
|
|
|
/// `light` or `dark` or `system`
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub theme_mode: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub tray_event: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub env_type: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub start_page: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub startup_script: Option<String>,
|
|
|
|
pub traffic_graph: Option<bool>,
|
|
|
|
/// show memory info (only for Mihomo)
|
|
pub enable_memory_usage: Option<bool>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub enable_group_icon: Option<bool>,
|
|
|
|
pub pause_render_traffic_stats_on_blur: Option<bool>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub common_tray_icon: Option<bool>,
|
|
|
|
#[cfg(target_os = "macos")]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub tray_icon: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub menu_icon: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
#[specta(type = Option<Vec<std::string::String>>)]
|
|
pub menu_order: Option<Vec<String>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub proxy_group_tools_position: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub notice_position: Option<String>,
|
|
|
|
pub collapse_navbar: Option<bool>,
|
|
|
|
pub sysproxy_tray_icon: Option<bool>,
|
|
|
|
pub tun_tray_icon: Option<bool>,
|
|
|
|
pub enable_tun_mode: Option<bool>,
|
|
|
|
pub enable_auto_launch: Option<bool>,
|
|
|
|
pub enable_silent_start: Option<bool>,
|
|
|
|
pub enable_system_proxy: Option<bool>,
|
|
|
|
pub enable_proxy_guard: Option<bool>,
|
|
|
|
pub enable_bypass_check: Option<bool>,
|
|
|
|
/// Initial DNS override preference for profiles without a saved setting.
|
|
pub enable_dns_settings: Option<bool>,
|
|
|
|
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
|
|
#[specta(type = std::collections::BTreeMap<std::string::String, super::dns::ProfileDnsSettings>)]
|
|
pub profile_dns_settings: std::collections::BTreeMap<String, super::dns::ProfileDnsSettings>,
|
|
|
|
pub use_default_bypass: Option<bool>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub system_proxy_bypass: Option<String>,
|
|
|
|
pub proxy_guard_duration: Option<u64>,
|
|
|
|
pub proxy_auto_config: Option<bool>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub pac_file_content: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub proxy_host: Option<String>,
|
|
|
|
pub theme_setting: Option<IVergeTheme>,
|
|
#[specta(type = Option<Vec<std::string::String>>)]
|
|
pub web_ui_list: Option<Vec<String>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub clash_core: Option<String>,
|
|
|
|
/// format: {func},{key}
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
#[specta(type = Option<Vec<std::string::String>>)]
|
|
pub hotkeys: Option<Vec<String>>,
|
|
|
|
pub enable_global_hotkey: Option<bool>,
|
|
|
|
#[specta(type = Option<crate::ipc::JsonValue>)]
|
|
pub home_cards: Option<serde_json::Value>,
|
|
|
|
pub auto_close_connection: Option<bool>,
|
|
|
|
pub auto_check_update: Option<bool>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub default_latency_test: Option<String>,
|
|
|
|
pub default_latency_timeout: Option<i16>,
|
|
|
|
pub enable_auto_delay_detection: Option<bool>,
|
|
|
|
/// 自动检测当前节点延迟的间隔(分钟)
|
|
pub auto_delay_detection_interval_minutes: Option<u64>,
|
|
|
|
pub enable_builtin_enhanced: Option<bool>,
|
|
|
|
pub proxy_layout_column: Option<u8>,
|
|
|
|
pub test_list: Option<Vec<IVergeTestItem>>,
|
|
|
|
/// 0: 不清理; 1: 1天;2: 7天; 3: 30天; 4: 90天
|
|
pub auto_log_clean: Option<i32>,
|
|
|
|
pub enable_auto_backup_schedule: Option<bool>,
|
|
|
|
/// Automatic backup interval in hours
|
|
pub auto_backup_interval_hours: Option<u64>,
|
|
|
|
pub auto_backup_on_change: Option<bool>,
|
|
|
|
/// verge 的各种 port 用于覆盖 clash 的各种 port
|
|
#[cfg(not(target_os = "windows"))]
|
|
pub verge_redir_port: Option<u16>,
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
pub verge_redir_enabled: Option<bool>,
|
|
|
|
#[cfg(target_os = "linux")]
|
|
pub verge_tproxy_port: Option<u16>,
|
|
|
|
#[cfg(target_os = "linux")]
|
|
pub verge_tproxy_enabled: Option<bool>,
|
|
|
|
pub verge_mixed_port: Option<u16>,
|
|
|
|
pub verge_socks_port: Option<u16>,
|
|
|
|
pub verge_socks_enabled: Option<bool>,
|
|
|
|
pub verge_port: Option<u16>,
|
|
|
|
pub verge_http_enabled: Option<bool>,
|
|
|
|
#[serde(
|
|
serialize_with = "serialize_encrypted",
|
|
deserialize_with = "deserialize_encrypted",
|
|
skip_serializing_if = "Option::is_none",
|
|
default
|
|
)]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub webdav_url: Option<String>,
|
|
|
|
#[serde(
|
|
serialize_with = "serialize_encrypted",
|
|
deserialize_with = "deserialize_encrypted",
|
|
skip_serializing_if = "Option::is_none",
|
|
default
|
|
)]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub webdav_username: Option<String>,
|
|
|
|
#[serde(
|
|
serialize_with = "serialize_encrypted",
|
|
deserialize_with = "deserialize_encrypted",
|
|
skip_serializing_if = "Option::is_none",
|
|
default
|
|
)]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub webdav_password: Option<String>,
|
|
|
|
#[cfg(target_os = "macos")]
|
|
pub enable_tray_speed: Option<bool>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub tray_proxy_groups_display_mode: Option<String>,
|
|
pub tray_inline_outbound_modes: Option<bool>,
|
|
|
|
pub enable_auto_light_weight_mode: Option<bool>,
|
|
|
|
/// 自动进入轻量模式的延迟(分钟)
|
|
pub auto_light_weight_minutes: Option<u64>,
|
|
|
|
pub enable_hover_jump_navigator: Option<bool>,
|
|
|
|
/// 代理页面自动滚动延迟(毫秒)
|
|
pub hover_jump_navigator_delay: Option<u64>,
|
|
|
|
pub enable_external_controller: Option<bool>,
|
|
}
|
|
|
|
#[derive(Default, Debug, Clone, Deserialize, Serialize, specta::Type)]
|
|
#[serde(default)]
|
|
pub struct IVergeTestItem {
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub uid: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub name: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub icon: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub url: Option<String>,
|
|
}
|
|
|
|
#[derive(Default, Debug, Clone, Deserialize, Serialize, specta::Type)]
|
|
#[serde(default)]
|
|
pub struct IVergeTheme {
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub primary_color: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub secondary_color: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub primary_text: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub secondary_text: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub info_color: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub error_color: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub warning_color: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub success_color: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub font_family: Option<String>,
|
|
#[specta(type = Option<std::string::String>)]
|
|
pub css_injection: Option<String>,
|
|
}
|
|
|
|
impl IVerge {
|
|
pub const VALID_CLASH_CORES: &'static [&'static str] = &["verge-mihomo", "verge-mihomo-alpha"];
|
|
|
|
pub async fn validate_and_fix_config() -> Result<()> {
|
|
let config_path = dirs::verge_path()?;
|
|
let mut config = match help::read_yaml::<Self>(&config_path).await {
|
|
Ok(config) => config,
|
|
Err(_) => Self::template(),
|
|
};
|
|
|
|
let mut needs_fix = false;
|
|
|
|
if let Some(ref core) = config.clash_core {
|
|
let core_str = core.trim();
|
|
if core_str.is_empty() || !Self::VALID_CLASH_CORES.contains(&core_str) {
|
|
logging!(
|
|
warn,
|
|
Type::Config,
|
|
"启动时发现无效的clash_core配置: '{}', 将自动修正为 'verge-mihomo'",
|
|
core
|
|
);
|
|
config.clash_core = Some("verge-mihomo".into());
|
|
needs_fix = true;
|
|
}
|
|
} else {
|
|
logging!(
|
|
info,
|
|
Type::Config,
|
|
"启动时发现未配置clash_core, 将设置为默认值 'verge-mihomo'"
|
|
);
|
|
config.clash_core = Some("verge-mihomo".into());
|
|
needs_fix = true;
|
|
}
|
|
|
|
if needs_fix {
|
|
logging!(debug, Type::Config, "正在保存修正后的配置文件...");
|
|
help::save_yaml(&config_path, &config, Some("# Clash Verge Config")).await?;
|
|
logging!(info, Type::Config, "配置文件修正完成,需要重新加载配置");
|
|
|
|
Self::reload_config_after_fix(config).await;
|
|
} else {
|
|
logging!(debug, Type::Config, "clash_core配置验证通过: {:?}", config.clash_core);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn reload_config_after_fix(updated_config: Self) {
|
|
logging!(
|
|
info,
|
|
Type::Config,
|
|
"内存配置已强制更新,新的clash_core: {:?}",
|
|
&updated_config.clash_core
|
|
);
|
|
|
|
let config_draft = Config::verge().await;
|
|
config_draft.edit_draft(|d| {
|
|
*d = updated_config;
|
|
});
|
|
config_draft.apply();
|
|
}
|
|
|
|
pub fn get_valid_clash_core(&self) -> String {
|
|
self.clash_core.clone().unwrap_or_else(|| "verge-mihomo".into())
|
|
}
|
|
|
|
pub async fn new() -> Self {
|
|
match dirs::verge_path() {
|
|
Ok(path) => match help::read_yaml::<Self>(&path).await {
|
|
Ok(mut config) => {
|
|
if let Some(start_page) = config.start_page.clone()
|
|
&& start_page == "/home"
|
|
{
|
|
config.start_page = Some(String::from("/"));
|
|
}
|
|
config
|
|
}
|
|
Err(err) => {
|
|
logging!(error, Type::Config, "failed to read verge config: {err:#}");
|
|
Self::template()
|
|
}
|
|
},
|
|
Err(err) => {
|
|
logging!(error, Type::Config, "failed to get verge config path: {err:#}");
|
|
Self::template()
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn template() -> Self {
|
|
Self {
|
|
app_log_max_size: Some(128),
|
|
app_log_max_count: Some(8),
|
|
clash_core: Some("verge-mihomo".into()),
|
|
language: Some(clash_verge_i18n::system_language().into()),
|
|
theme_mode: Some("system".into()),
|
|
#[cfg(not(target_os = "windows"))]
|
|
env_type: Some("bash".into()),
|
|
#[cfg(target_os = "windows")]
|
|
env_type: Some("powershell".into()),
|
|
start_page: Some("/".into()),
|
|
traffic_graph: Some(true),
|
|
enable_memory_usage: Some(true),
|
|
enable_group_icon: Some(true),
|
|
pause_render_traffic_stats_on_blur: Some(true),
|
|
#[cfg(target_os = "macos")]
|
|
tray_icon: Some("monochrome".into()),
|
|
menu_icon: Some("monochrome".into()),
|
|
notice_position: Some("top-right".into()),
|
|
collapse_navbar: Some(false),
|
|
common_tray_icon: Some(false),
|
|
sysproxy_tray_icon: Some(false),
|
|
tun_tray_icon: Some(false),
|
|
enable_auto_launch: Some(false),
|
|
enable_silent_start: Some(false),
|
|
enable_hover_jump_navigator: Some(true),
|
|
hover_jump_navigator_delay: Some(280),
|
|
enable_system_proxy: Some(false),
|
|
proxy_auto_config: Some(false),
|
|
pac_file_content: Some(DEFAULT_PAC.into()),
|
|
proxy_host: Some("127.0.0.1".into()),
|
|
#[cfg(not(target_os = "windows"))]
|
|
verge_redir_port: Some(7895),
|
|
#[cfg(not(target_os = "windows"))]
|
|
verge_redir_enabled: Some(false),
|
|
#[cfg(target_os = "linux")]
|
|
verge_tproxy_port: Some(7896),
|
|
#[cfg(target_os = "linux")]
|
|
verge_tproxy_enabled: Some(false),
|
|
verge_mixed_port: Some(network::ports::DEFAULT_MIXED),
|
|
verge_socks_port: Some(7898),
|
|
verge_socks_enabled: Some(false),
|
|
verge_port: Some(7899),
|
|
verge_http_enabled: Some(false),
|
|
enable_proxy_guard: Some(false),
|
|
enable_bypass_check: Some(true),
|
|
use_default_bypass: Some(true),
|
|
proxy_guard_duration: Some(30),
|
|
auto_close_connection: Some(true),
|
|
auto_check_update: Some(true),
|
|
enable_builtin_enhanced: Some(true),
|
|
auto_log_clean: Some(2), // 1: 1天, 2: 7天, 3: 30天, 4: 90天
|
|
enable_auto_backup_schedule: Some(false),
|
|
auto_backup_interval_hours: Some(24),
|
|
auto_backup_on_change: Some(true),
|
|
webdav_url: None,
|
|
webdav_username: None,
|
|
webdav_password: None,
|
|
#[cfg(target_os = "macos")]
|
|
enable_tray_speed: Some(false),
|
|
tray_proxy_groups_display_mode: Some("default".into()),
|
|
tray_inline_outbound_modes: Some(false),
|
|
enable_global_hotkey: Some(true),
|
|
enable_auto_light_weight_mode: Some(false),
|
|
auto_light_weight_minutes: Some(10),
|
|
enable_dns_settings: Some(false),
|
|
home_cards: None,
|
|
enable_external_controller: Some(false),
|
|
..Self::default()
|
|
}
|
|
}
|
|
|
|
pub async fn save_file(&self) -> Result<()> {
|
|
help::save_yaml(&dirs::verge_path()?, &self, Some("# Clash Verge Config")).await
|
|
}
|
|
|
|
#[allow(clippy::cognitive_complexity)]
|
|
pub fn patch_config(&mut self, patch: &Self) {
|
|
patch_opt_field!(self, patch, app_log_level);
|
|
patch_opt_field!(self, patch, app_log_max_size);
|
|
patch_opt_field!(self, patch, app_log_max_count);
|
|
|
|
patch_opt_field!(self, patch, language);
|
|
patch_opt_field!(self, patch, theme_mode);
|
|
patch_opt_field!(self, patch, tray_event);
|
|
patch_opt_field!(self, patch, env_type);
|
|
patch_opt_field!(self, patch, start_page);
|
|
patch_opt_field!(self, patch, startup_script);
|
|
patch_opt_field!(self, patch, traffic_graph);
|
|
patch_opt_field!(self, patch, enable_memory_usage);
|
|
patch_opt_field!(self, patch, enable_group_icon);
|
|
patch_opt_field!(self, patch, pause_render_traffic_stats_on_blur);
|
|
#[cfg(target_os = "macos")]
|
|
patch_opt_field!(self, patch, tray_icon);
|
|
patch_opt_field!(self, patch, menu_icon);
|
|
patch_opt_field!(self, patch, menu_order);
|
|
patch_opt_field!(self, patch, proxy_group_tools_position);
|
|
patch_opt_field!(self, patch, notice_position);
|
|
patch_opt_field!(self, patch, collapse_navbar);
|
|
patch_opt_field!(self, patch, common_tray_icon);
|
|
patch_opt_field!(self, patch, sysproxy_tray_icon);
|
|
patch_opt_field!(self, patch, tun_tray_icon);
|
|
|
|
patch_opt_field!(self, patch, enable_tun_mode);
|
|
patch_opt_field!(self, patch, enable_auto_launch);
|
|
patch_opt_field!(self, patch, enable_silent_start);
|
|
patch_opt_field!(self, patch, enable_hover_jump_navigator);
|
|
patch_opt_field!(self, patch, hover_jump_navigator_delay);
|
|
#[cfg(not(target_os = "windows"))]
|
|
patch_opt_field!(self, patch, verge_redir_port);
|
|
#[cfg(not(target_os = "windows"))]
|
|
patch_opt_field!(self, patch, verge_redir_enabled);
|
|
#[cfg(target_os = "linux")]
|
|
patch_opt_field!(self, patch, verge_tproxy_port);
|
|
#[cfg(target_os = "linux")]
|
|
patch_opt_field!(self, patch, verge_tproxy_enabled);
|
|
patch_opt_field!(self, patch, verge_mixed_port);
|
|
patch_opt_field!(self, patch, verge_socks_port);
|
|
patch_opt_field!(self, patch, verge_socks_enabled);
|
|
patch_opt_field!(self, patch, verge_port);
|
|
patch_opt_field!(self, patch, verge_http_enabled);
|
|
patch_opt_field!(self, patch, enable_system_proxy);
|
|
patch_opt_field!(self, patch, enable_proxy_guard);
|
|
patch_opt_field!(self, patch, enable_bypass_check);
|
|
patch_opt_field!(self, patch, use_default_bypass);
|
|
patch_opt_field!(self, patch, system_proxy_bypass);
|
|
patch_opt_field!(self, patch, proxy_guard_duration);
|
|
patch_opt_field!(self, patch, proxy_auto_config);
|
|
patch_opt_field!(self, patch, pac_file_content);
|
|
patch_opt_field!(self, patch, proxy_host);
|
|
patch_opt_field!(self, patch, theme_setting);
|
|
patch_opt_field!(self, patch, web_ui_list);
|
|
patch_opt_field!(self, patch, clash_core);
|
|
patch_opt_field!(self, patch, hotkeys);
|
|
patch_opt_field!(self, patch, enable_global_hotkey);
|
|
|
|
patch_opt_field!(self, patch, auto_close_connection);
|
|
patch_opt_field!(self, patch, auto_check_update);
|
|
patch_opt_field!(self, patch, default_latency_test);
|
|
patch_opt_field!(self, patch, default_latency_timeout);
|
|
patch_opt_field!(self, patch, enable_auto_delay_detection);
|
|
patch_opt_field!(self, patch, auto_delay_detection_interval_minutes);
|
|
patch_opt_field!(self, patch, enable_builtin_enhanced);
|
|
patch_opt_field!(self, patch, proxy_layout_column);
|
|
patch_opt_field!(self, patch, test_list);
|
|
patch_opt_field!(self, patch, auto_log_clean);
|
|
patch_opt_field!(self, patch, enable_auto_backup_schedule);
|
|
patch_opt_field!(self, patch, auto_backup_interval_hours);
|
|
patch_opt_field!(self, patch, auto_backup_on_change);
|
|
|
|
patch_opt_field!(self, patch, webdav_url);
|
|
patch_opt_field!(self, patch, webdav_username);
|
|
patch_opt_field!(self, patch, webdav_password);
|
|
#[cfg(target_os = "macos")]
|
|
patch_opt_field!(self, patch, enable_tray_speed);
|
|
patch_opt_field!(self, patch, tray_proxy_groups_display_mode);
|
|
patch_opt_field!(self, patch, tray_inline_outbound_modes);
|
|
patch_opt_field!(self, patch, enable_auto_light_weight_mode);
|
|
patch_opt_field!(self, patch, auto_light_weight_minutes);
|
|
patch_opt_field!(self, patch, enable_dns_settings);
|
|
patch_opt_field!(self, patch, home_cards);
|
|
patch_opt_field!(self, patch, enable_external_controller);
|
|
}
|
|
|
|
pub fn get_log_level(&self) -> LevelFilter {
|
|
if let Some(level) = self.app_log_level.as_ref() {
|
|
match level.to_lowercase().as_str() {
|
|
"silent" => LevelFilter::Off,
|
|
"error" => LevelFilter::Error,
|
|
"warn" => LevelFilter::Warn,
|
|
"info" => LevelFilter::Info,
|
|
"debug" => LevelFilter::Debug,
|
|
"trace" => LevelFilter::Trace,
|
|
_ => LevelFilter::Info,
|
|
}
|
|
} else {
|
|
LevelFilter::Info
|
|
}
|
|
}
|
|
}
|