From df66d976a5be61b3850b547e9b0b50e95ba95681 Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Sun, 26 Jul 2026 02:02:02 +0800 Subject: [PATCH] feat(updater): skip installer language prompt during auto-update (#7572) * feat(updater): skip installer language prompt during auto-update * fix: Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- crates/clash-verge-i18n/src/lib.rs | 2 +- src-tauri/packages/windows/installer.nsi | 17 +++++++++++++- src-tauri/src/core/updater.rs | 30 +++++++++++++++++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/crates/clash-verge-i18n/src/lib.rs b/crates/clash-verge-i18n/src/lib.rs index 04b04fdfb..a59027e94 100644 --- a/crates/clash-verge-i18n/src/lib.rs +++ b/crates/clash-verge-i18n/src/lib.rs @@ -39,7 +39,7 @@ fn resolve_supported_language(language: &str) -> Option> { } #[inline] -fn current_language(language: Option<&str>) -> Cow<'static, str> { +pub fn current_language(language: Option<&str>) -> Cow<'static, str> { language .filter(|lang| !lang.is_empty()) .and_then(resolve_supported_language) diff --git a/src-tauri/packages/windows/installer.nsi b/src-tauri/packages/windows/installer.nsi index e6fc49407..f486688d9 100644 --- a/src-tauri/packages/windows/installer.nsi +++ b/src-tauri/packages/windows/installer.nsi @@ -478,7 +478,22 @@ Function .onInit ${EndIf} !if "${DISPLAYLANGUAGESELECTOR}" == "true" - !insertmacro MUI_LANGDLL_DISPLAY + ; Auto-update forwards the app's UI language as `/LANG=` so + ; the installer uses it directly and skips the interactive language + ; selector, letting the update start without prompting the user. + ; See `src-tauri/src/core/updater.rs` (`nsis_language_id`). + ${GetOptions} $CMDLINE "/LANG=" $0 + ${IfNot} ${Errors} + ${If} $0 == "1033" + ${OrIf} $0 == "1049" + ${OrIf} $0 == "2052" + StrCpy $LANGUAGE $0 + ${Else} + !insertmacro MUI_LANGDLL_DISPLAY + ${EndIf} + ${Else} + !insertmacro MUI_LANGDLL_DISPLAY + ${EndIf} !endif !insertmacro SetContext diff --git a/src-tauri/src/core/updater.rs b/src-tauri/src/core/updater.rs index 81da3cc8f..7eaf90db9 100644 --- a/src-tauri/src/core/updater.rs +++ b/src-tauri/src/core/updater.rs @@ -127,6 +127,21 @@ fn version_lte(a: &str, b: &str) -> bool { true // equal } +/// Map the app's resolved UI language code to an NSIS installer language ID. +/// +/// The Windows installer only ships SimpChinese, English and Russian +/// (`tauri.windows.conf.json` `nsis.languages`). Languages without a matching +/// NSIS translation fall back to English; Traditional Chinese ("zhtw") is +/// mapped to SimpChinese so Chinese users don't get an English installer. +#[cfg(target_os = "windows")] +fn nsis_language_id(app_language: &str) -> &'static str { + match app_language { + "zh" | "zhtw" => "2052", // SimpChinese + "ru" => "1049", // Russian + _ => "1033", // English + } +} + // ─── Startup Install & Cache Management ───────────────────────────────────── impl SilentUpdater { @@ -186,7 +201,20 @@ impl SilentUpdater { // Need a fresh Update object from the server to call install(). // This is a lightweight HTTP request (< 1s), not a re-download. - let update = match app_handle.updater() { + // + // The updater is built with the app's current language forwarded as + // `/LANG=`. On Windows the NSIS installer parses this in + // `.onInit` (see `packages/windows/installer.nsi`) and sets `$LANGUAGE` + // directly, skipping its language-selection dialog so the update starts + // without prompting. Other platforms don't run an installer. + let updater_builder = app_handle.updater_builder(); + #[cfg(target_os = "windows")] + let updater_builder = { + let verge_lang = Config::verge().await.latest_arc().language.clone(); + let lang_id = nsis_language_id(&clash_verge_i18n::current_language(verge_lang.as_deref())); + updater_builder.installer_arg(format!("/LANG={lang_id}")) + }; + let update = match updater_builder.build() { Ok(updater) => match updater.check().await { Ok(Some(u)) => u, Ok(None) => {