From 11aa7743e7a277ed9ec3e92040dc484afe77d261 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:48:22 +0800 Subject: [PATCH] enhance!(nsis): use `!ifmacrodef` for installer hooks (#10177) --- .changes/nsis-ifmacrodef.md | 5 +++++ core/tauri-config-schema/schema.json | 2 +- core/tauri-utils/src/config.rs | 12 ++++-------- examples/api/src-tauri/Cargo.lock | 16 ++++++++-------- tooling/bundler/src/bundle/settings.rs | 12 ++++-------- .../src/bundle/windows/templates/installer.nsi | 16 ++++++++-------- tooling/cli/schema.json | 2 +- 7 files changed, 31 insertions(+), 34 deletions(-) create mode 100644 .changes/nsis-ifmacrodef.md diff --git a/.changes/nsis-ifmacrodef.md b/.changes/nsis-ifmacrodef.md new file mode 100644 index 000000000..ac33762b9 --- /dev/null +++ b/.changes/nsis-ifmacrodef.md @@ -0,0 +1,5 @@ +--- +"tauri-bundler": "patch:breaking" +--- + +Changed NSIS installer hooks from `!define` to `!macro` diff --git a/core/tauri-config-schema/schema.json b/core/tauri-config-schema/schema.json index f3fc5f114..e91fcfb1a 100644 --- a/core/tauri-config-schema/schema.json +++ b/core/tauri-config-schema/schema.json @@ -2347,7 +2347,7 @@ ] }, "installerHooks": { - "description": "A path to a `.nsh` file that contains special NSIS macros to be hooked into the\n main installer.nsi script.\n\n Supported hooks are:\n - `NSIS_HOOK_PREINSTALL`: This hook runs before copying files, setting registry key values and creating shortcuts.\n - `NSIS_HOOK_POSTINSTALL`: This hook runs after the installer has finished copying all files, setting the registry keys and created shortcuts.\n - `NSIS_HOOK_PREUNINSTALL`: This hook runs before removing any files, registry keys and shortcuts.\n - `NSIS_HOOK_POSTUNINSTALL`: This hook runs after files, registry keys and shortcuts have been removed.\n\n\n ### Example\n\n ```nsh\n !define NSIS_HOOK_PREINSTALL \"NSIS_HOOK_PREINSTALL_\"\n !macro NSIS_HOOK_PREINSTALL_\n MessageBox MB_OK \"PreInstall\"\n !macroend\n\n !define NSIS_HOOK_POSTINSTALL \"NSIS_HOOK_POSTINSTALL_\"\n !macro NSIS_HOOK_POSTINSTALL_\n MessageBox MB_OK \"PostInstall\"\n !macroend\n\n !define NSIS_HOOK_PREUNINSTALL \"NSIS_HOOK_PREUNINSTALL_\"\n !macro NSIS_HOOK_PREUNINSTALL_\n MessageBox MB_OK \"PreUnInstall\"\n !macroend\n\n !define NSIS_HOOK_POSTUNINSTALL \"NSIS_HOOK_POSTUNINSTALL_\"\n !macro NSIS_HOOK_POSTUNINSTALL_\n MessageBox MB_OK \"PostUninstall\"\n !macroend\n\n ```", + "description": "A path to a `.nsh` file that contains special NSIS macros to be hooked into the\n main installer.nsi script.\n\n Supported hooks are:\n - `NSIS_HOOK_PREINSTALL`: This hook runs before copying files, setting registry key values and creating shortcuts.\n - `NSIS_HOOK_POSTINSTALL`: This hook runs after the installer has finished copying all files, setting the registry keys and created shortcuts.\n - `NSIS_HOOK_PREUNINSTALL`: This hook runs before removing any files, registry keys and shortcuts.\n - `NSIS_HOOK_POSTUNINSTALL`: This hook runs after files, registry keys and shortcuts have been removed.\n\n\n ### Example\n\n ```nsh\n !macro NSIS_HOOK_PREINSTALL\n MessageBox MB_OK \"PreInstall\"\n !macroend\n\n !macro NSIS_HOOK_POSTINSTALL\n MessageBox MB_OK \"PostInstall\"\n !macroend\n\n !macro NSIS_HOOK_PREUNINSTALL\n MessageBox MB_OK \"PreUnInstall\"\n !macroend\n\n !macro NSIS_HOOK_POSTUNINSTALL\n MessageBox MB_OK \"PostUninstall\"\n !macroend\n\n ```", "type": [ "string", "null" diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index ac821871f..107e7fdaf 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -802,23 +802,19 @@ pub struct NsisConfig { /// ### Example /// /// ```nsh - /// !define NSIS_HOOK_PREINSTALL "NSIS_HOOK_PREINSTALL_" - /// !macro NSIS_HOOK_PREINSTALL_ + /// !macro NSIS_HOOK_PREINSTALL /// MessageBox MB_OK "PreInstall" /// !macroend /// - /// !define NSIS_HOOK_POSTINSTALL "NSIS_HOOK_POSTINSTALL_" - /// !macro NSIS_HOOK_POSTINSTALL_ + /// !macro NSIS_HOOK_POSTINSTALL /// MessageBox MB_OK "PostInstall" /// !macroend /// - /// !define NSIS_HOOK_PREUNINSTALL "NSIS_HOOK_PREUNINSTALL_" - /// !macro NSIS_HOOK_PREUNINSTALL_ + /// !macro NSIS_HOOK_PREUNINSTALL /// MessageBox MB_OK "PreUnInstall" /// !macroend /// - /// !define NSIS_HOOK_POSTUNINSTALL "NSIS_HOOK_POSTUNINSTALL_" - /// !macro NSIS_HOOK_POSTUNINSTALL_ + /// !macro NSIS_HOOK_POSTUNINSTALL /// MessageBox MB_OK "PostUninstall" /// !macroend /// diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 57e3e905d..d0f7e2688 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -3033,7 +3033,7 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "tauri" -version = "2.0.0-beta.22" +version = "2.0.0-beta.23" dependencies = [ "anyhow", "bytes", @@ -3083,7 +3083,7 @@ dependencies = [ [[package]] name = "tauri-build" -version = "2.0.0-beta.17" +version = "2.0.0-beta.18" dependencies = [ "anyhow", "cargo_toml", @@ -3105,7 +3105,7 @@ dependencies = [ [[package]] name = "tauri-codegen" -version = "2.0.0-beta.17" +version = "2.0.0-beta.18" dependencies = [ "base64 0.22.1", "brotli", @@ -3130,7 +3130,7 @@ dependencies = [ [[package]] name = "tauri-macros" -version = "2.0.0-beta.17" +version = "2.0.0-beta.18" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -3142,7 +3142,7 @@ dependencies = [ [[package]] name = "tauri-plugin" -version = "2.0.0-beta.17" +version = "2.0.0-beta.18" dependencies = [ "anyhow", "glob", @@ -3168,7 +3168,7 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "2.0.0-beta.18" +version = "2.0.0-beta.19" dependencies = [ "dpi", "gtk", @@ -3185,7 +3185,7 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "2.0.0-beta.18" +version = "2.0.0-beta.19" dependencies = [ "cocoa", "gtk", @@ -3207,7 +3207,7 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "2.0.0-beta.17" +version = "2.0.0-beta.18" dependencies = [ "aes-gcm", "brotli", diff --git a/tooling/bundler/src/bundle/settings.rs b/tooling/bundler/src/bundle/settings.rs index 921f76f6f..74a6b9ec1 100644 --- a/tooling/bundler/src/bundle/settings.rs +++ b/tooling/bundler/src/bundle/settings.rs @@ -440,23 +440,19 @@ pub struct NsisSettings { /// ### Example /// /// ```nsh - /// !define NSIS_HOOK_PREINSTALL "NSIS_HOOK_PREINSTALL_" - /// !macro NSIS_HOOK_PREINSTALL_ + /// !macro NSIS_HOOK_PREINSTALL /// MessageBox MB_OK "PreInstall" /// !macroend /// - /// !define NSIS_HOOK_POSTINSTALL "NSIS_HOOK_POSTINSTALL_" - /// !macro NSIS_HOOK_POSTINSTALL_ + /// !macro NSIS_HOOK_POSTINSTALL /// MessageBox MB_OK "PostInstall" /// !macroend /// - /// !define NSIS_HOOK_PREUNINSTALL "NSIS_HOOK_PREUNINSTALL_" - /// !macro NSIS_HOOK_PREUNINSTALL_ + /// !macro NSIS_HOOK_PREUNINSTALL /// MessageBox MB_OK "PreUnInstall" /// !macroend /// - /// !define NSIS_HOOK_POSTUNINSTALL "NSIS_HOOK_POSTUNINSTALL_" - /// !macro NSIS_HOOK_POSTUNINSTALL_ + /// !macro NSIS_HOOK_POSTUNINSTALL /// MessageBox MB_OK "PostUninstall" /// !macroend /// ``` diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index 3216867f3..860295b5a 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -558,8 +558,8 @@ Section Install !insertmacro CheckIfAppIsRunning - !ifdef NSIS_HOOK_PREINSTALL - !insertmacro "${NSIS_HOOK_PREINSTALL}" + !ifmacrodef NSIS_HOOK_PREINSTALL + !insertmacro NSIS_HOOK_PREINSTALL !endif ; Copy main executable @@ -638,8 +638,8 @@ Section Install Call CreateOrUpdateDesktopShortcut ${EndIf} - !ifdef NSIS_HOOK_POSTINSTALL - !insertmacro "${NSIS_HOOK_POSTINSTALL}" + !ifmacrodef NSIS_HOOK_POSTINSTALL + !insertmacro NSIS_HOOK_POSTINSTALL !endif ; Auto close this page for passive mode @@ -685,8 +685,8 @@ Section Uninstall !insertmacro CheckIfAppIsRunning - !ifdef NSIS_HOOK_PREUNINSTALL - !insertmacro "${NSIS_HOOK_PREUNINSTALL}" + !ifmacrodef NSIS_HOOK_PREUNINSTALL + !insertmacro NSIS_HOOK_PREUNINSTALL !endif ; Delete the app directory and its content from disk @@ -776,8 +776,8 @@ Section Uninstall RmDir /r "$LOCALAPPDATA\${BUNDLEID}" ${EndIf} - !ifdef NSIS_HOOK_POSTUNINSTALL - !insertmacro "${NSIS_HOOK_POSTUNINSTALL}" + !ifmacrodef NSIS_HOOK_POSTUNINSTALL + !insertmacro NSIS_HOOK_PREUNINSTALL !endif ; Auto close if passive mode diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index f3fc5f114..e91fcfb1a 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -2347,7 +2347,7 @@ ] }, "installerHooks": { - "description": "A path to a `.nsh` file that contains special NSIS macros to be hooked into the\n main installer.nsi script.\n\n Supported hooks are:\n - `NSIS_HOOK_PREINSTALL`: This hook runs before copying files, setting registry key values and creating shortcuts.\n - `NSIS_HOOK_POSTINSTALL`: This hook runs after the installer has finished copying all files, setting the registry keys and created shortcuts.\n - `NSIS_HOOK_PREUNINSTALL`: This hook runs before removing any files, registry keys and shortcuts.\n - `NSIS_HOOK_POSTUNINSTALL`: This hook runs after files, registry keys and shortcuts have been removed.\n\n\n ### Example\n\n ```nsh\n !define NSIS_HOOK_PREINSTALL \"NSIS_HOOK_PREINSTALL_\"\n !macro NSIS_HOOK_PREINSTALL_\n MessageBox MB_OK \"PreInstall\"\n !macroend\n\n !define NSIS_HOOK_POSTINSTALL \"NSIS_HOOK_POSTINSTALL_\"\n !macro NSIS_HOOK_POSTINSTALL_\n MessageBox MB_OK \"PostInstall\"\n !macroend\n\n !define NSIS_HOOK_PREUNINSTALL \"NSIS_HOOK_PREUNINSTALL_\"\n !macro NSIS_HOOK_PREUNINSTALL_\n MessageBox MB_OK \"PreUnInstall\"\n !macroend\n\n !define NSIS_HOOK_POSTUNINSTALL \"NSIS_HOOK_POSTUNINSTALL_\"\n !macro NSIS_HOOK_POSTUNINSTALL_\n MessageBox MB_OK \"PostUninstall\"\n !macroend\n\n ```", + "description": "A path to a `.nsh` file that contains special NSIS macros to be hooked into the\n main installer.nsi script.\n\n Supported hooks are:\n - `NSIS_HOOK_PREINSTALL`: This hook runs before copying files, setting registry key values and creating shortcuts.\n - `NSIS_HOOK_POSTINSTALL`: This hook runs after the installer has finished copying all files, setting the registry keys and created shortcuts.\n - `NSIS_HOOK_PREUNINSTALL`: This hook runs before removing any files, registry keys and shortcuts.\n - `NSIS_HOOK_POSTUNINSTALL`: This hook runs after files, registry keys and shortcuts have been removed.\n\n\n ### Example\n\n ```nsh\n !macro NSIS_HOOK_PREINSTALL\n MessageBox MB_OK \"PreInstall\"\n !macroend\n\n !macro NSIS_HOOK_POSTINSTALL\n MessageBox MB_OK \"PostInstall\"\n !macroend\n\n !macro NSIS_HOOK_PREUNINSTALL\n MessageBox MB_OK \"PreUnInstall\"\n !macroend\n\n !macro NSIS_HOOK_POSTUNINSTALL\n MessageBox MB_OK \"PostUninstall\"\n !macroend\n\n ```", "type": [ "string", "null"