diff --git a/Changelog.md b/Changelog.md index 9d30c4ec4..24af63e66 100644 --- a/Changelog.md +++ b/Changelog.md @@ -32,6 +32,7 @@ - 修复窗口较窄时,首页「当前节点」卡片中过长的节点名把延迟标签挤出卡片 - 修复断开链式代理时清空已选节点,导致再次连接需要重新选择的问题 - 修复「连接」页表格排序时表头换行、标题位置跳动的问题 +- 修复「TUN 设置」未手动保存时,界面显示的默认 MTU 1500 未生效的问题 **🍎 macOS** diff --git a/src-tauri/src/constants.rs b/src-tauri/src/constants.rs index 3f85ced31..54ac3f309 100644 --- a/src-tauri/src/constants.rs +++ b/src-tauri/src/constants.rs @@ -70,6 +70,8 @@ pub mod files { pub mod tun { pub const DEFAULT_STACK: &str = "mips"; + pub const DEFAULT_MTU: u16 = 1500; + pub const DNS_HIJACK: &[&str] = &["any:53"]; /// Saved dialog fields; `enable` belongs to the verge switch. diff --git a/src-tauri/src/enhance/mod.rs b/src-tauri/src/enhance/mod.rs index 08b790823..e84e2c20c 100644 --- a/src-tauri/src/enhance/mod.rs +++ b/src-tauri/src/enhance/mod.rs @@ -459,7 +459,7 @@ fn gui_tun_keys(clash_config: &Mapping) -> Vec { keys.extend( constants::tun::GUI_KEYS .iter() - .filter(|key| tun.contains_key(**key)) + .filter(|key| tun.get(**key).is_some_and(|value| !value.is_null())) .map(|key| Value::from(*key)), ); } @@ -531,6 +531,16 @@ fn ensure_lan_bind_address(mut config: Mapping) -> Mapping { config } +fn ensure_tun_default_mtu(mut config: Mapping) -> Mapping { + if let Some(Value::Mapping(tun)) = config.get_mut("tun") + && matches!(tun.get("mtu"), None | Some(Value::Null)) + { + tun.insert(Value::from("mtu"), Value::from(constants::tun::DEFAULT_MTU)); + } + + config +} + /// Merges the app's clash config over the profile; switches are parameters to keep it pure. fn merge_default_config( mut config: Mapping, @@ -548,7 +558,9 @@ fn merge_default_config( }); let patch_tun = value.as_mapping().cloned().unwrap_or_else(Mapping::new); for (key, value) in patch_tun.into_iter() { - tun.insert(key, value); + if !value.is_null() { + tun.insert(key, value); + } } config.insert("tun".into(), tun.into()); } else { @@ -878,6 +890,7 @@ pub async fn enhance( notify_discarded_keys(authoritative.overridden(&authoritative, &authoritative.current(&config))); let config = authoritative.enforce(config); + let config = ensure_tun_default_mtu(config); let config = ensure_lan_bind_address(config); let config = cleanup_proxy_groups(config); diff --git a/src/components/setting/mods/tun-viewer.tsx b/src/components/setting/mods/tun-viewer.tsx index 0ebeb8f73..69953c037 100644 --- a/src/components/setting/mods/tun-viewer.tsx +++ b/src/components/setting/mods/tun-viewer.tsx @@ -54,7 +54,7 @@ export function TunViewer({ ref }: { ref?: Ref }) { autoDetectInterface: true, dnsHijack: ['any:53'], strictRoute: false, - mtu: 1500, + mtu: 1500 as number | undefined, dnsMode: '', }) @@ -374,14 +374,15 @@ export function TunViewer({ ref }: { ref?: Ref }) { autoCapitalize="off" spellCheck="false" sx={{ width: 250 }} - value={values.mtu} + value={values.mtu ?? ''} placeholder="1500" - onChange={(e) => + onChange={(e) => { + const next = Number.parseInt(e.target.value, 10) setValues((v) => ({ ...v, - mtu: parseInt(e.target.value), + mtu: Number.isNaN(next) ? undefined : next, })) - } + }} />