From 36e2425ca99d0478883ecbed54acac0574989575 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 21 Jul 2024 12:48:20 +0800 Subject: [PATCH 01/13] Add ensure minimum webview2 version --- .../bundle/windows/templates/installer.nsi | 115 ++++++++++-------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index 7e015362751c..dd467f56ac7c 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -53,6 +53,7 @@ ${StrLoc} !define WEBVIEW2INSTALLERARGS "{{webview2_installer_args}}" !define WEBVIEW2BOOTSTRAPPERPATH "{{webview2_bootstrapper_path}}" !define WEBVIEW2INSTALLERPATH "{{webview2_installer_path}}" +!define MINIMUMWEBVIEW2VERSION "130" !define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}" !define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}" !define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}" @@ -499,57 +500,75 @@ Section WebView2 ${EndIf} ReadRegStr $5 HKCU "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv" - StrCmp $4 "" 0 webview2_done - StrCmp $5 "" 0 webview2_done - - ; Webview2 installation - ; - ; Skip if updating - ${If} $UpdateMode <> 1 - !if "${INSTALLWEBVIEW2MODE}" == "downloadBootstrapper" - Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe" - DetailPrint "$(webview2Downloading)" - NSISdl::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\MicrosoftEdgeWebview2Setup.exe" - Pop $0 - ${If} $0 = 0 - DetailPrint "$(webview2DownloadSuccess)" + ${If} $4 == "" + ${AndIf} $5 == "" + ; Webview2 installation + ; + ; Skip if updating + ${If} $UpdateMode <> 1 + !if "${INSTALLWEBVIEW2MODE}" == "downloadBootstrapper" + Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe" + DetailPrint "$(webview2Downloading)" + NSISdl::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\MicrosoftEdgeWebview2Setup.exe" + Pop $0 + ${If} $0 = 0 + DetailPrint "$(webview2DownloadSuccess)" + ${Else} + DetailPrint "$(webview2DownloadError)" + Abort "$(webview2AbortError)" + ${EndIf} + StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe" + Goto install_webview2 + !endif + + !if "${INSTALLWEBVIEW2MODE}" == "embedBootstrapper" + Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe" + File "/oname=$TEMP\MicrosoftEdgeWebview2Setup.exe" "${WEBVIEW2BOOTSTRAPPERPATH}" + DetailPrint "$(installingWebview2)" + StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe" + Goto install_webview2 + !endif + + !if "${INSTALLWEBVIEW2MODE}" == "offlineInstaller" + Delete "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" + File "/oname=$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" "${WEBVIEW2INSTALLERPATH}" + DetailPrint "$(installingWebview2)" + StrCpy $6 "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" + Goto install_webview2 + !endif + + Goto webview2_done + + install_webview2: + DetailPrint "$(installingWebview2)" + ; $6 holds the path to the webview2 installer + ExecWait "$6 ${WEBVIEW2INSTALLERARGS} /install" $1 + ${If} $1 = 0 + DetailPrint "$(webview2InstallSuccess)" + ${Else} + DetailPrint "$(webview2InstallError)" + Abort "$(webview2AbortError)" + ${EndIf} + webview2_done: + ${EndIf} + ${Else} + !if "${MINIMUMWEBVIEW2VERSION}" != "" + ${If} $4 != "" + ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 ${Else} - DetailPrint "$(webview2DownloadError)" - Abort "$(webview2AbortError)" + ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$5" $R0 ${EndIf} - StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe" - Goto install_webview2 - !endif - - !if "${INSTALLWEBVIEW2MODE}" == "embedBootstrapper" - Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe" - File "/oname=$TEMP\MicrosoftEdgeWebview2Setup.exe" "${WEBVIEW2BOOTSTRAPPERPATH}" - DetailPrint "$(installingWebview2)" - StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe" - Goto install_webview2 - !endif - - !if "${INSTALLWEBVIEW2MODE}" == "offlineInstaller" - Delete "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" - File "/oname=$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" "${WEBVIEW2INSTALLERPATH}" - DetailPrint "$(installingWebview2)" - StrCpy $6 "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" - Goto install_webview2 - !endif - - Goto webview2_done - - install_webview2: - DetailPrint "$(installingWebview2)" - ; $6 holds the path to the webview2 installer - ExecWait "$6 ${WEBVIEW2INSTALLERARGS} /install" $1 - ${If} $1 = 0 - DetailPrint "$(webview2InstallSuccess)" - ${Else} - DetailPrint "$(webview2InstallError)" - Abort "$(webview2AbortError)" + ${If} $R0 = 1 + DetailPrint "$(installingWebview2)" + ExecWait `"C:\Program Files (x86)\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe" /install appguid={F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}` $1 + ${If} $1 = 0 + DetailPrint "$(webview2InstallSuccess)" + ${Else} + DetailPrint "$(webview2InstallError)" + Abort "$(webview2AbortError)" + ${EndIf} ${EndIf} - webview2_done: + !endif ${EndIf} SectionEnd From ea13a687cb0281676291d1aea0a81b2797bb9717 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 21 Jul 2024 14:41:32 +0800 Subject: [PATCH 02/13] needsadmin --- tooling/bundler/src/bundle/windows/templates/installer.nsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index dd467f56ac7c..783ffef3189f 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -560,7 +560,7 @@ Section WebView2 ${EndIf} ${If} $R0 = 1 DetailPrint "$(installingWebview2)" - ExecWait `"C:\Program Files (x86)\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe" /install appguid={F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}` $1 + ExecWait `"C:\Program Files (x86)\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe" /install appguid="{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}&needsadmin=true"` $1 ${If} $1 = 0 DetailPrint "$(webview2InstallSuccess)" ${Else} From 9e1376ef2c6c4ed1a3e460bafa30efe588ef1ad1 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 21 Jul 2024 14:56:12 +0800 Subject: [PATCH 03/13] Add setting and change file --- .changes/nsis-ensure-webview2-version.md | 5 +++++ core/tauri-config-schema/schema.json | 9 +++++++++ core/tauri-utils/src/config.rs | 5 +++++ tooling/bundler/src/bundle/settings.rs | 4 ++++ tooling/bundler/src/bundle/windows/nsis.rs | 6 ++++++ .../bundler/src/bundle/windows/templates/installer.nsi | 1 + tooling/cli/schema.json | 9 +++++++++ tooling/cli/src/helpers/config.rs | 1 + 8 files changed, 40 insertions(+) create mode 100644 .changes/nsis-ensure-webview2-version.md diff --git a/.changes/nsis-ensure-webview2-version.md b/.changes/nsis-ensure-webview2-version.md new file mode 100644 index 000000000000..6ebaac89f9c6 --- /dev/null +++ b/.changes/nsis-ensure-webview2-version.md @@ -0,0 +1,5 @@ +--- +'tauri-build': 'patch:feat' +--- + +Add a new option `ensureWebview2Version` to trigger a webview2 update if the user's webview2 is older than this version diff --git a/core/tauri-config-schema/schema.json b/core/tauri-config-schema/schema.json index b2c168b6e694..ecd39d4ccef3 100644 --- a/core/tauri-config-schema/schema.json +++ b/core/tauri-config-schema/schema.json @@ -2352,6 +2352,15 @@ "string", "null" ] + }, + "ensureWebview2Version": { + "description": "Ensure webview2 version to be newer than this major version,\n if the user's webview2 is older than this version,\n the installer will trigger a webview2 update", + "type": [ + "integer", + "null" + ], + "format": "uint16", + "minimum": 0.0 } }, "additionalProperties": false diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index 90e41c6353fb..4c2e1030cca9 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -821,6 +821,11 @@ pub struct NsisConfig { /// ``` #[serde(alias = "installer-hooks")] pub installer_hooks: Option, + /// Ensure webview2 version to be newer than this major version, + /// if the user's webview2 is older than this version, + /// the installer will trigger a webview2 update + #[serde(alias = "ensure-webview2-version")] + pub ensure_webview2_version: Option, } /// Install modes for the Webview2 runtime. diff --git a/tooling/bundler/src/bundle/settings.rs b/tooling/bundler/src/bundle/settings.rs index 74a6b9ec1d46..cb0c70707f4f 100644 --- a/tooling/bundler/src/bundle/settings.rs +++ b/tooling/bundler/src/bundle/settings.rs @@ -457,6 +457,10 @@ pub struct NsisSettings { /// !macroend /// ``` pub installer_hooks: Option, + /// Ensure webview2 version to be newer than this major version, + /// if the user's webview2 is older than this version, + /// the installer will trigger a webview2 update + pub ensure_webview2_version: Option, } /// The Windows bundle settings. diff --git a/tooling/bundler/src/bundle/windows/nsis.rs b/tooling/bundler/src/bundle/windows/nsis.rs index b84c9b3af3e8..4f34eaaba381 100644 --- a/tooling/bundler/src/bundle/windows/nsis.rs +++ b/tooling/bundler/src/bundle/windows/nsis.rs @@ -257,6 +257,12 @@ fn build_nsis_app_installer( if let Some(start_menu_folder) = &nsis.start_menu_folder { data.insert("start_menu_folder", to_json(start_menu_folder)); } + if let Some(minimum_webview2_version) = &nsis.ensure_webview2_version { + data.insert( + "minimum_webview2_version", + to_json(minimum_webview2_version), + ); + } } let compression = settings diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index 783ffef3189f..781bf77754a7 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -560,6 +560,7 @@ Section WebView2 ${EndIf} ${If} $R0 = 1 DetailPrint "$(installingWebview2)" + ; From "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" ExecWait `"C:\Program Files (x86)\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe" /install appguid="{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}&needsadmin=true"` $1 ${If} $1 = 0 DetailPrint "$(webview2InstallSuccess)" diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index b2c168b6e694..ecd39d4ccef3 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -2352,6 +2352,15 @@ "string", "null" ] + }, + "ensureWebview2Version": { + "description": "Ensure webview2 version to be newer than this major version,\n if the user's webview2 is older than this version,\n the installer will trigger a webview2 update", + "type": [ + "integer", + "null" + ], + "format": "uint16", + "minimum": 0.0 } }, "additionalProperties": false diff --git a/tooling/cli/src/helpers/config.rs b/tooling/cli/src/helpers/config.rs index 13fd3823e7d1..4d873967e965 100644 --- a/tooling/cli/src/helpers/config.rs +++ b/tooling/cli/src/helpers/config.rs @@ -107,6 +107,7 @@ pub fn nsis_settings(config: NsisConfig) -> tauri_bundler::NsisSettings { compression: config.compression, start_menu_folder: config.start_menu_folder, installer_hooks: config.installer_hooks, + ensure_webview2_version: config.ensure_webview2_version, } } From eca62cf1f6a33df5f75b6830a4a6a70fccd636f1 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 21 Jul 2024 14:57:36 +0800 Subject: [PATCH 04/13] Forget to change hard coded version --- tooling/bundler/src/bundle/windows/templates/installer.nsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index 781bf77754a7..eb075e95ba2f 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -53,7 +53,7 @@ ${StrLoc} !define WEBVIEW2INSTALLERARGS "{{webview2_installer_args}}" !define WEBVIEW2BOOTSTRAPPERPATH "{{webview2_bootstrapper_path}}" !define WEBVIEW2INSTALLERPATH "{{webview2_installer_path}}" -!define MINIMUMWEBVIEW2VERSION "130" +!define MINIMUMWEBVIEW2VERSION "{{minimum_webview2_version}}" !define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}" !define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}" !define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}" From ff50c73de7a84befc4d97a3e066429c42fcdc086 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 21 Jul 2024 17:06:31 +0800 Subject: [PATCH 05/13] Be clear it's for nsis installer --- .changes/nsis-ensure-webview2-version.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changes/nsis-ensure-webview2-version.md b/.changes/nsis-ensure-webview2-version.md index 6ebaac89f9c6..2065b7e78f09 100644 --- a/.changes/nsis-ensure-webview2-version.md +++ b/.changes/nsis-ensure-webview2-version.md @@ -1,5 +1,5 @@ --- -'tauri-build': 'patch:feat' +"tauri-build": "patch:feat" --- -Add a new option `ensureWebview2Version` to trigger a webview2 update if the user's webview2 is older than this version +Add a new option `ensureWebview2Version` for Windows NSIS installer to trigger a webview2 update if the user's webview2 is older than this version From fb2278ea92c950578181182b7d460f7876e3d7f8 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 21 Jul 2024 17:44:49 +0800 Subject: [PATCH 06/13] Wrong quote --- tooling/bundler/src/bundle/windows/templates/installer.nsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index eb075e95ba2f..1f5b6d9f91b4 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -561,7 +561,7 @@ Section WebView2 ${If} $R0 = 1 DetailPrint "$(installingWebview2)" ; From "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" - ExecWait `"C:\Program Files (x86)\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe" /install appguid="{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}&needsadmin=true"` $1 + ExecWait `"C:\Program Files (x86)\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe" /install appguid={F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}&needsadmin=true` $1 ${If} $1 = 0 DetailPrint "$(webview2InstallSuccess)" ${Else} From 507de44ef4d429a3dc2856fce03a07cb3b6285db Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 21 Jul 2024 17:59:09 +0800 Subject: [PATCH 07/13] Add comment abuot chromium updater docs --- tooling/bundler/src/bundle/windows/templates/installer.nsi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index 1f5b6d9f91b4..3ac1e6dd8a5b 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -560,7 +560,8 @@ Section WebView2 ${EndIf} ${If} $R0 = 1 DetailPrint "$(installingWebview2)" - ; From "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" + ; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md + ; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" ExecWait `"C:\Program Files (x86)\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe" /install appguid={F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}&needsadmin=true` $1 ${If} $1 = 0 DetailPrint "$(webview2InstallSuccess)" From 0b7e61f1e15bdb49c4acb3d718467aa7cc69e345 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 22 Aug 2024 09:28:56 +0800 Subject: [PATCH 08/13] Use path from registry key and string version --- core/tauri-config-schema/schema.json | 8 ++-- core/tauri-utils/src/config.rs | 4 +- tooling/bundler/src/bundle/settings.rs | 4 +- .../bundle/windows/templates/installer.nsi | 41 +++++++++++-------- tooling/cli/schema.json | 8 ++-- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/core/tauri-config-schema/schema.json b/core/tauri-config-schema/schema.json index 967ec2e93cc3..c75ae23dd828 100644 --- a/core/tauri-config-schema/schema.json +++ b/core/tauri-config-schema/schema.json @@ -2368,13 +2368,11 @@ ] }, "ensureWebview2Version": { - "description": "Ensure webview2 version to be newer than this major version,\n if the user's webview2 is older than this version,\n the installer will trigger a webview2 update", + "description": "Ensure webview2 version to be newer than this version,\n if the user's webview2 is older than this version,\n the installer will trigger a webview2 update", "type": [ - "integer", + "string", "null" - ], - "format": "uint16", - "minimum": 0.0 + ] } }, "additionalProperties": false diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index 6f7c8a6f8392..cfac86421e19 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -838,11 +838,11 @@ pub struct NsisConfig { /// ``` #[serde(alias = "installer-hooks")] pub installer_hooks: Option, - /// Ensure webview2 version to be newer than this major version, + /// Ensure webview2 version to be newer than this version, /// if the user's webview2 is older than this version, /// the installer will trigger a webview2 update #[serde(alias = "ensure-webview2-version")] - pub ensure_webview2_version: Option, + pub ensure_webview2_version: Option, } /// Install modes for the Webview2 runtime. diff --git a/tooling/bundler/src/bundle/settings.rs b/tooling/bundler/src/bundle/settings.rs index 03c6589f4df9..afa7b095fc74 100644 --- a/tooling/bundler/src/bundle/settings.rs +++ b/tooling/bundler/src/bundle/settings.rs @@ -457,10 +457,10 @@ pub struct NsisSettings { /// !macroend /// ``` pub installer_hooks: Option, - /// Ensure webview2 version to be newer than this major version, + /// Ensure webview2 version to be newer than this version, /// if the user's webview2 is older than this version, /// the installer will trigger a webview2 update - pub ensure_webview2_version: Option, + pub ensure_webview2_version: Option, } /// The Custom Signing Command Settings for Windows exe diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index a317447d2bf5..727ffba1bf40 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -29,6 +29,8 @@ ${StrLoc} !include "{{installer_hooks}}" {{/if}} +!define WEBVIEW2APPGUID "{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" + !define MANUFACTURER "{{manufacturer}}" !define PRODUCTNAME "{{product_name}}" !define VERSION "{{version}}" @@ -494,14 +496,15 @@ SectionEnd Section WebView2 ; Check if Webview2 is already installed and skip this section ${If} ${RunningX64} - ReadRegStr $4 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv" + ReadRegStr $4 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" ${Else} - ReadRegStr $4 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv" + ReadRegStr $4 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" + ${EndIf} + ${If} $4 == "" + ReadRegStr $4 HKCU "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" ${EndIf} - ReadRegStr $5 HKCU "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv" ${If} $4 == "" - ${AndIf} $5 == "" ; Webview2 installation ; ; Skip if updating @@ -553,21 +556,27 @@ Section WebView2 ${EndIf} ${Else} !if "${MINIMUMWEBVIEW2VERSION}" != "" - ${If} $4 != "" - ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 - ${Else} - ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$5" $R0 - ${EndIf} + ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 ${If} $R0 = 1 DetailPrint "$(installingWebview2)" - ; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md - ; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" - ExecWait `"C:\Program Files (x86)\Microsoft\EdgeUpdate\MicrosoftEdgeUpdate.exe" /install appguid={F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}&needsadmin=true` $1 - ${If} $1 = 0 - DetailPrint "$(webview2InstallSuccess)" + ${If} ${RunningX64} + ReadRegStr $R1 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" "path" ${Else} - DetailPrint "$(webview2InstallError)" - Abort "$(webview2AbortError)" + ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\EdgeUpdate" "path" + ${EndIf} + ${If} $R1 == "" + ReadRegStr $R1 HKCU "SOFTWARE\Microsoft\EdgeUpdate" "path" + ${EndIf} + ${If} $R1 != "" + ; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md + ; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" + ExecWait `"$R1" /install appguid=${WEBVIEW2APPGUID}&needsadmin=true` $1 + ${If} $1 = 0 + DetailPrint "$(webview2InstallSuccess)" + ${Else} + DetailPrint "$(webview2InstallError)" + Abort "$(webview2AbortError)" + ${EndIf} ${EndIf} ${EndIf} !endif diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index 967ec2e93cc3..c75ae23dd828 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -2368,13 +2368,11 @@ ] }, "ensureWebview2Version": { - "description": "Ensure webview2 version to be newer than this major version,\n if the user's webview2 is older than this version,\n the installer will trigger a webview2 update", + "description": "Ensure webview2 version to be newer than this version,\n if the user's webview2 is older than this version,\n the installer will trigger a webview2 update", "type": [ - "integer", + "string", "null" - ], - "format": "uint16", - "minimum": 0.0 + ] } }, "additionalProperties": false From 2193ee720b3ca1ba80617e5f71c60985a862a398 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:34:25 +0800 Subject: [PATCH 09/13] Update .changes/nsis-ensure-webview2-version.md Co-authored-by: Amr Bashir --- .changes/nsis-ensure-webview2-version.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changes/nsis-ensure-webview2-version.md b/.changes/nsis-ensure-webview2-version.md index 2065b7e78f09..a45c660c5a2e 100644 --- a/.changes/nsis-ensure-webview2-version.md +++ b/.changes/nsis-ensure-webview2-version.md @@ -1,5 +1,6 @@ --- -"tauri-build": "patch:feat" +"tauri-bundler": "patch:feat" +"tauri-utils": "patch:feat" --- Add a new option `ensureWebview2Version` for Windows NSIS installer to trigger a webview2 update if the user's webview2 is older than this version From d7c9074b9989f3aa33af5543e09a5261198a5e98 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 23 Aug 2024 00:02:04 +0800 Subject: [PATCH 10/13] Add warning message box instead of force abort --- .../bundle/windows/templates/installer.nsi | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index 727ffba1bf40..8a022b1bc79d 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -556,29 +556,31 @@ Section WebView2 ${EndIf} ${Else} !if "${MINIMUMWEBVIEW2VERSION}" != "" - ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 - ${If} $R0 = 1 - DetailPrint "$(installingWebview2)" - ${If} ${RunningX64} - ReadRegStr $R1 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" "path" - ${Else} - ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\EdgeUpdate" "path" - ${EndIf} - ${If} $R1 == "" - ReadRegStr $R1 HKCU "SOFTWARE\Microsoft\EdgeUpdate" "path" - ${EndIf} - ${If} $R1 != "" - ; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md - ; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" - ExecWait `"$R1" /install appguid=${WEBVIEW2APPGUID}&needsadmin=true` $1 - ${If} $1 = 0 - DetailPrint "$(webview2InstallSuccess)" + retry: + ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 + ${If} $R0 = 1 + DetailPrint "$(installingWebview2)" + ${If} ${RunningX64} + ReadRegStr $R1 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" "path" ${Else} - DetailPrint "$(webview2InstallError)" - Abort "$(webview2AbortError)" + ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\EdgeUpdate" "path" + ${EndIf} + ${If} $R1 == "" + ReadRegStr $R1 HKCU "SOFTWARE\Microsoft\EdgeUpdate" "path" + ${EndIf} + ${If} $R1 != "" + ; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md + ; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" + ExecWait `"$R1" /install appguid=${WEBVIEW2APPGUID}&needsadmin=true` $1 + ${If} $1 = 0 + DetailPrint "$(webview2InstallSuccess)" + ${Else} + MessageBox MB_ICONEXCLAMATION|MB_ABORTRETRYIGNORE "$(webview2InstallError)" IDIGNORE ignore IDRETRY retry + Quit + ignore: + ${EndIf} ${EndIf} ${EndIf} - ${EndIf} !endif ${EndIf} SectionEnd From da34e94303c261417c5ec0794e08cca4a2dc0112 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 23 Aug 2024 09:28:34 +0800 Subject: [PATCH 11/13] Tweak name and description --- core/tauri-config-schema/schema.json | 4 ++-- core/tauri-utils/src/config.rs | 8 ++++---- tooling/bundler/src/bundle/settings.rs | 8 ++++---- tooling/bundler/src/bundle/windows/nsis.rs | 2 +- tooling/cli/schema.json | 4 ++-- tooling/cli/src/helpers/config.rs | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/core/tauri-config-schema/schema.json b/core/tauri-config-schema/schema.json index c75ae23dd828..540673714d6f 100644 --- a/core/tauri-config-schema/schema.json +++ b/core/tauri-config-schema/schema.json @@ -2367,8 +2367,8 @@ "null" ] }, - "ensureWebview2Version": { - "description": "Ensure webview2 version to be newer than this version,\n if the user's webview2 is older than this version,\n the installer will trigger a webview2 update", + "minimumWebview2Version": { + "description": "Try to ensure that the WebView2 version is equal to or newer than this version,\n if the user's WebView2 is older than this version,\n the installer will try to trigger a WebView2 update.", "type": [ "string", "null" diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index cfac86421e19..d91bcc810cec 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -838,11 +838,11 @@ pub struct NsisConfig { /// ``` #[serde(alias = "installer-hooks")] pub installer_hooks: Option, - /// Ensure webview2 version to be newer than this version, - /// if the user's webview2 is older than this version, - /// the installer will trigger a webview2 update + /// Try to ensure that the WebView2 version is equal to or newer than this version, + /// if the user's WebView2 is older than this version, + /// the installer will try to trigger a WebView2 update. #[serde(alias = "ensure-webview2-version")] - pub ensure_webview2_version: Option, + pub minimum_webview2_version: Option, } /// Install modes for the Webview2 runtime. diff --git a/tooling/bundler/src/bundle/settings.rs b/tooling/bundler/src/bundle/settings.rs index afa7b095fc74..7c262afb308a 100644 --- a/tooling/bundler/src/bundle/settings.rs +++ b/tooling/bundler/src/bundle/settings.rs @@ -457,10 +457,10 @@ pub struct NsisSettings { /// !macroend /// ``` pub installer_hooks: Option, - /// Ensure webview2 version to be newer than this version, - /// if the user's webview2 is older than this version, - /// the installer will trigger a webview2 update - pub ensure_webview2_version: Option, + /// Try to ensure that the WebView2 version is equal to or newer than this version, + /// if the user's WebView2 is older than this version, + /// the installer will try to trigger a WebView2 update. + pub minimum_webview2_version: Option, } /// The Custom Signing Command Settings for Windows exe diff --git a/tooling/bundler/src/bundle/windows/nsis.rs b/tooling/bundler/src/bundle/windows/nsis.rs index 4f34eaaba381..079601bc1890 100644 --- a/tooling/bundler/src/bundle/windows/nsis.rs +++ b/tooling/bundler/src/bundle/windows/nsis.rs @@ -257,7 +257,7 @@ fn build_nsis_app_installer( if let Some(start_menu_folder) = &nsis.start_menu_folder { data.insert("start_menu_folder", to_json(start_menu_folder)); } - if let Some(minimum_webview2_version) = &nsis.ensure_webview2_version { + if let Some(minimum_webview2_version) = &nsis.minimum_webview2_version { data.insert( "minimum_webview2_version", to_json(minimum_webview2_version), diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index c75ae23dd828..540673714d6f 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -2367,8 +2367,8 @@ "null" ] }, - "ensureWebview2Version": { - "description": "Ensure webview2 version to be newer than this version,\n if the user's webview2 is older than this version,\n the installer will trigger a webview2 update", + "minimumWebview2Version": { + "description": "Try to ensure that the WebView2 version is equal to or newer than this version,\n if the user's WebView2 is older than this version,\n the installer will try to trigger a WebView2 update.", "type": [ "string", "null" diff --git a/tooling/cli/src/helpers/config.rs b/tooling/cli/src/helpers/config.rs index 14d09a62f9f3..a784611ad76f 100644 --- a/tooling/cli/src/helpers/config.rs +++ b/tooling/cli/src/helpers/config.rs @@ -107,7 +107,7 @@ pub fn nsis_settings(config: NsisConfig) -> tauri_bundler::NsisSettings { compression: config.compression, start_menu_folder: config.start_menu_folder, installer_hooks: config.installer_hooks, - ensure_webview2_version: config.ensure_webview2_version, + minimum_webview2_version: config.minimum_webview2_version, } } From c366f77f8c40eb6532b427086ea9d3b2c4d4f139 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 23 Aug 2024 12:09:47 +0800 Subject: [PATCH 12/13] Move retry down --- .../bundler/src/bundle/windows/templates/installer.nsi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index 8a022b1bc79d..c6e728c66dde 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/tooling/bundler/src/bundle/windows/templates/installer.nsi @@ -556,9 +556,9 @@ Section WebView2 ${EndIf} ${Else} !if "${MINIMUMWEBVIEW2VERSION}" != "" - retry: - ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 - ${If} $R0 = 1 + ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 + ${If} $R0 = 1 + update_webview: DetailPrint "$(installingWebview2)" ${If} ${RunningX64} ReadRegStr $R1 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" "path" @@ -575,12 +575,12 @@ Section WebView2 ${If} $1 = 0 DetailPrint "$(webview2InstallSuccess)" ${Else} - MessageBox MB_ICONEXCLAMATION|MB_ABORTRETRYIGNORE "$(webview2InstallError)" IDIGNORE ignore IDRETRY retry + MessageBox MB_ICONEXCLAMATION|MB_ABORTRETRYIGNORE "$(webview2InstallError)" IDIGNORE ignore IDRETRY update_webview Quit ignore: ${EndIf} ${EndIf} - ${EndIf} + ${EndIf} !endif ${EndIf} SectionEnd From bc8e468130ed6eed3b5005173a84ead09920b3ea Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Fri, 23 Aug 2024 15:21:07 +0300 Subject: [PATCH 13/13] Update .changes/nsis-ensure-webview2-version.md [skip ci] --- .changes/nsis-ensure-webview2-version.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/nsis-ensure-webview2-version.md b/.changes/nsis-ensure-webview2-version.md index a45c660c5a2e..bc1e6d499e75 100644 --- a/.changes/nsis-ensure-webview2-version.md +++ b/.changes/nsis-ensure-webview2-version.md @@ -3,4 +3,4 @@ "tauri-utils": "patch:feat" --- -Add a new option `ensureWebview2Version` for Windows NSIS installer to trigger a webview2 update if the user's webview2 is older than this version +Add a new option `minimumWebview2Version` for Windows NSIS installer to trigger a webview2 update if the user's webview2 is older than this version