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>
This commit is contained in:
AnnAngela
2026-07-26 02:02:02 +08:00
committed by GitHub
co-authored by Copilot Autofix powered by AI
parent 85b5501faf
commit df66d976a5
3 changed files with 46 additions and 3 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ fn resolve_supported_language(language: &str) -> Option<Cow<'static, str>> {
}
#[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)
+16 -1
View File
@@ -478,7 +478,22 @@ Function .onInit
${EndIf}
!if "${DISPLAYLANGUAGESELECTOR}" == "true"
!insertmacro MUI_LANGDLL_DISPLAY
; Auto-update forwards the app's UI language as `/LANG=<NSIS-lang-id>` 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
+29 -1
View File
@@ -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=<NSIS-lang-id>`. 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) => {