From 926a57bb0851e45d47ad1ee68fc96a9c25754c7c Mon Sep 17 00:00:00 2001 From: Xuhui Zheng <2529677678@qq.com> Date: Wed, 8 Apr 2026 16:10:55 +0800 Subject: [PATCH] feat(windows): NSIS uninstaller icon and header image support (#15201) * feat: NSIS uninstaller support. * chore: fix typo and update schema. * fix: comments and alias. * fix: add pages for uninst sidebar. * chore: fix typo in comments of fields. * fix: group HEADERIMAGE. * fix: remove welcome/finish of uninstaller. * fix: remove uninstaller_sidebar_image. * Update crates/tauri-utils/src/config.rs Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * chore: revert comments. * chore: update schema. * Update crates/tauri-utils/src/config.rs Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * Update crates/tauri-utils/src/config.rs Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * fix: typo of installer_icon. * chore: add change file. * fix: typo. * chore: update config.json. * Update .changes/feat-uninstaller-icon-image.md Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * fix: revert alias. * chore: update comments in settings.rs. * chore: update comments. * fix: installer.nsi * fix: installer.nsi --------- Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> --- .changes/feat-uninstaller-icon-image.md | 13 +++++++++++ crates/tauri-bundler/src/bundle/settings.rs | 7 ++++++ .../src/bundle/windows/nsis/installer.nsi | 22 +++++++++++++++++-- .../src/bundle/windows/nsis/mod.rs | 14 ++++++++++++ crates/tauri-cli/config.schema.json | 14 ++++++++++++ crates/tauri-cli/src/helpers/config.rs | 2 ++ .../schemas/config.schema.json | 14 ++++++++++++ crates/tauri-utils/src/config.rs | 10 +++++++++ 8 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 .changes/feat-uninstaller-icon-image.md diff --git a/.changes/feat-uninstaller-icon-image.md b/.changes/feat-uninstaller-icon-image.md new file mode 100644 index 000000000000..af2177e17263 --- /dev/null +++ b/.changes/feat-uninstaller-icon-image.md @@ -0,0 +1,13 @@ +--- +"tauri-bundler": minor:feat +"tauri-cli": minor:feat +"@tauri-apps/cli": minor:feat +"tauri-utils": minor:feat +--- + +Added uninstaller icon and uninstaller header image support for NSIS installer. + +Notes: + +- For `tauri-bundler` lib users, the `NsisSettings` now has 2 new fields `uninstaller_icon` and `uninstaller_header_image` which can be a breaking change +- When bundling with NSIS, users can add `uninstallerIcon` and `uninstallerHeaderImage` under `bundle > windows > nsis` to configure them. diff --git a/crates/tauri-bundler/src/bundle/settings.rs b/crates/tauri-bundler/src/bundle/settings.rs index d94708dae5ce..815f342cd592 100644 --- a/crates/tauri-bundler/src/bundle/settings.rs +++ b/crates/tauri-bundler/src/bundle/settings.rs @@ -470,6 +470,13 @@ pub struct NsisSettings { pub sidebar_image: Option, /// The path to an icon file used as the installer icon. pub installer_icon: Option, + /// The path to an icon file used as the uninstaller icon. + pub uninstaller_icon: Option, + /// The path to a bitmap file to display on the header of uninstallers pages. + /// Defaults to [`Self::header_image`]. If this is set but [`Self::header_image`] is not, a default image from NSIS will be applied to `header_image` + /// + /// The recommended dimensions are 150px x 57px. + pub uninstaller_header_image: Option, /// Whether the installation will be for all users or just the current user. pub install_mode: NSISInstallerMode, /// A list of installer languages. diff --git a/crates/tauri-bundler/src/bundle/windows/nsis/installer.nsi b/crates/tauri-bundler/src/bundle/windows/nsis/installer.nsi index e178c49ea12c..a48a46149f6d 100644 --- a/crates/tauri-bundler/src/bundle/windows/nsis/installer.nsi +++ b/crates/tauri-bundler/src/bundle/windows/nsis/installer.nsi @@ -41,6 +41,8 @@ ${StrLoc} !define INSTALLERICON "{{installer_icon}}" !define SIDEBARIMAGE "{{sidebar_image}}" !define HEADERIMAGE "{{header_image}}" +!define UNINSTALLERICON "{{uninstaller_icon}}" +!define UNINSTALLERHEADERIMAGE "{{uninstaller_header_image}}" !define MAINBINARYNAME "{{main_binary_name}}" !define MAINBINARYSRCPATH "{{main_binary_path}}" !define BUNDLEID "{{bundle_id}}" @@ -129,10 +131,26 @@ VIAddVersionKey "ProductVersion" "${VERSION}" !define MUI_WELCOMEFINISHPAGE_BITMAP "${SIDEBARIMAGE}" !endif -; Installer header image +; Enable header images for installer and uninstaller pages when either image is configured. !if "${HEADERIMAGE}" != "" !define MUI_HEADERIMAGE - !define MUI_HEADERIMAGE_BITMAP "${HEADERIMAGE}" +!else if "${UNINSTALLERHEADERIMAGE}" != "" + !define MUI_HEADERIMAGE +!endif + +; Installer header image +!if "${HEADERIMAGE}" != "" + !define MUI_HEADERIMAGE_BITMAP "${HEADERIMAGE}" +!endif + +; Uninstaller header image +!if "${UNINSTALLERHEADERIMAGE}" != "" + !define MUI_HEADERIMAGE_UNBITMAP "${UNINSTALLERHEADERIMAGE}" +!endif + +; Uninstaller icon +!if "${UNINSTALLERICON}" != "" + !define MUI_UNICON "${UNINSTALLERICON}" !endif ; Define registry key to store installer language diff --git a/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs b/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs index 21d15aa46e35..85370834f80c 100644 --- a/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs +++ b/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs @@ -354,6 +354,20 @@ fn build_nsis_app_installer( ); } + if let Some(uninstaller_icon) = &nsis.uninstaller_icon { + data.insert( + "uninstaller_icon", + to_json(dunce::canonicalize(uninstaller_icon)?), + ); + } + + if let Some(uninstaller_header_image) = &nsis.uninstaller_header_image { + data.insert( + "uninstaller_header_image", + to_json(dunce::canonicalize(uninstaller_header_image)?), + ); + } + if let Some(installer_hooks) = &nsis.installer_hooks { let installer_hooks = dunce::canonicalize(installer_hooks)?; data.insert("installer_hooks", to_json(installer_hooks)); diff --git a/crates/tauri-cli/config.schema.json b/crates/tauri-cli/config.schema.json index 86bfe5d46b33..a489c8881542 100644 --- a/crates/tauri-cli/config.schema.json +++ b/crates/tauri-cli/config.schema.json @@ -2996,6 +2996,20 @@ "null" ] }, + "uninstallerIcon": { + "description": "The path to an icon file used as the uninstaller icon.", + "type": [ + "string", + "null" + ] + }, + "uninstallerHeaderImage": { + "description": "The path to a bitmap file to display on the header of uninstallers pages.\n Defaults to [`Self::header_image`]. If this is set but [`Self::header_image`] is not, a default image from NSIS will be applied to `header_image`\n\n The recommended dimensions are 150px x 57px.", + "type": [ + "string", + "null" + ] + }, "installMode": { "description": "Whether the installation will be for all users or just the current user.", "default": "currentUser", diff --git a/crates/tauri-cli/src/helpers/config.rs b/crates/tauri-cli/src/helpers/config.rs index f53d8c8693c5..75fb6b1ac605 100644 --- a/crates/tauri-cli/src/helpers/config.rs +++ b/crates/tauri-cli/src/helpers/config.rs @@ -110,6 +110,8 @@ pub fn nsis_settings(config: NsisConfig) -> tauri_bundler::NsisSettings { header_image: config.header_image, sidebar_image: config.sidebar_image, installer_icon: config.installer_icon, + uninstaller_icon: config.uninstaller_icon, + uninstaller_header_image: config.uninstaller_header_image, install_mode: config.install_mode, languages: config.languages, custom_language_files: config.custom_language_files, diff --git a/crates/tauri-schema-generator/schemas/config.schema.json b/crates/tauri-schema-generator/schemas/config.schema.json index 86bfe5d46b33..a489c8881542 100644 --- a/crates/tauri-schema-generator/schemas/config.schema.json +++ b/crates/tauri-schema-generator/schemas/config.schema.json @@ -2996,6 +2996,20 @@ "null" ] }, + "uninstallerIcon": { + "description": "The path to an icon file used as the uninstaller icon.", + "type": [ + "string", + "null" + ] + }, + "uninstallerHeaderImage": { + "description": "The path to a bitmap file to display on the header of uninstallers pages.\n Defaults to [`Self::header_image`]. If this is set but [`Self::header_image`] is not, a default image from NSIS will be applied to `header_image`\n\n The recommended dimensions are 150px x 57px.", + "type": [ + "string", + "null" + ] + }, "installMode": { "description": "Whether the installation will be for all users or just the current user.", "default": "currentUser", diff --git a/crates/tauri-utils/src/config.rs b/crates/tauri-utils/src/config.rs index 2b6304069279..cb974ac93428 100644 --- a/crates/tauri-utils/src/config.rs +++ b/crates/tauri-utils/src/config.rs @@ -857,9 +857,19 @@ pub struct NsisConfig { /// The recommended dimensions are 164px x 314px. #[serde(alias = "sidebar-image")] pub sidebar_image: Option, + // TODO: Change the alias to installer-icon in v3 /// The path to an icon file used as the installer icon. #[serde(alias = "install-icon")] pub installer_icon: Option, + /// The path to an icon file used as the uninstaller icon. + #[serde(alias = "uninstaller-icon")] + pub uninstaller_icon: Option, + /// The path to a bitmap file to display on the header of uninstallers pages. + /// Defaults to [`Self::header_image`]. If this is set but [`Self::header_image`] is not, a default image from NSIS will be applied to `header_image` + /// + /// The recommended dimensions are 150px x 57px. + #[serde(alias = "uninstaller-header-image")] + pub uninstaller_header_image: Option, /// Whether the installation will be for all users or just the current user. #[serde(default, alias = "install-mode")] pub install_mode: NSISInstallerMode,