Skip to content

Commit 58dda44

Browse files
feat(bundler/nsis): add minimum webview2 version checks (#10339)
1 parent 88bc357 commit 58dda44

8 files changed

Lines changed: 120 additions & 52 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-bundler": "patch:feat"
3+
"tauri-utils": "patch:feat"
4+
---
5+
6+
Add a new option `minimumWebview2Version` for Windows NSIS installer to trigger a webview2 update if the user's webview2 is older than this version

core/tauri-config-schema/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,13 @@
23662366
"string",
23672367
"null"
23682368
]
2369+
},
2370+
"minimumWebview2Version": {
2371+
"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.",
2372+
"type": [
2373+
"string",
2374+
"null"
2375+
]
23692376
}
23702377
},
23712378
"additionalProperties": false

core/tauri-utils/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ pub struct NsisConfig {
838838
/// ```
839839
#[serde(alias = "installer-hooks")]
840840
pub installer_hooks: Option<PathBuf>,
841+
/// Try to ensure that the WebView2 version is equal to or newer than this version,
842+
/// if the user's WebView2 is older than this version,
843+
/// the installer will try to trigger a WebView2 update.
844+
#[serde(alias = "ensure-webview2-version")]
845+
pub minimum_webview2_version: Option<String>,
841846
}
842847

843848
/// Install modes for the Webview2 runtime.

tooling/bundler/src/bundle/settings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ pub struct NsisSettings {
457457
/// !macroend
458458
/// ```
459459
pub installer_hooks: Option<PathBuf>,
460+
/// Try to ensure that the WebView2 version is equal to or newer than this version,
461+
/// if the user's WebView2 is older than this version,
462+
/// the installer will try to trigger a WebView2 update.
463+
pub minimum_webview2_version: Option<String>,
460464
}
461465

462466
/// The Custom Signing Command Settings for Windows exe

tooling/bundler/src/bundle/windows/nsis.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ fn build_nsis_app_installer(
257257
if let Some(start_menu_folder) = &nsis.start_menu_folder {
258258
data.insert("start_menu_folder", to_json(start_menu_folder));
259259
}
260+
if let Some(minimum_webview2_version) = &nsis.minimum_webview2_version {
261+
data.insert(
262+
"minimum_webview2_version",
263+
to_json(minimum_webview2_version),
264+
);
265+
}
260266
}
261267

262268
let compression = settings

tooling/bundler/src/bundle/windows/templates/installer.nsi

Lines changed: 84 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ ${StrLoc}
2929
!include "{{installer_hooks}}"
3030
{{/if}}
3131

32+
!define WEBVIEW2APPGUID "{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"
33+
3234
!define MANUFACTURER "{{manufacturer}}"
3335
!define PRODUCTNAME "{{product_name}}"
3436
!define VERSION "{{version}}"
@@ -53,6 +55,7 @@ ${StrLoc}
5355
!define WEBVIEW2INSTALLERARGS "{{webview2_installer_args}}"
5456
!define WEBVIEW2BOOTSTRAPPERPATH "{{webview2_bootstrapper_path}}"
5557
!define WEBVIEW2INSTALLERPATH "{{webview2_installer_path}}"
58+
!define MINIMUMWEBVIEW2VERSION "{{minimum_webview2_version}}"
5659
!define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}"
5760
!define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}"
5861
!define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}"
@@ -493,63 +496,92 @@ SectionEnd
493496
Section WebView2
494497
; Check if Webview2 is already installed and skip this section
495498
${If} ${RunningX64}
496-
ReadRegStr $4 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
499+
ReadRegStr $4 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv"
497500
${Else}
498-
ReadRegStr $4 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
501+
ReadRegStr $4 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv"
502+
${EndIf}
503+
${If} $4 == ""
504+
ReadRegStr $4 HKCU "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv"
499505
${EndIf}
500-
ReadRegStr $5 HKCU "SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
501-
502-
StrCmp $4 "" 0 webview2_done
503-
StrCmp $5 "" 0 webview2_done
504506

505-
; Webview2 installation
506-
;
507-
; Skip if updating
508-
${If} $UpdateMode <> 1
509-
!if "${INSTALLWEBVIEW2MODE}" == "downloadBootstrapper"
510-
Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe"
511-
DetailPrint "$(webview2Downloading)"
512-
NSISdl::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\MicrosoftEdgeWebview2Setup.exe"
513-
Pop $0
514-
${If} $0 = 0
515-
DetailPrint "$(webview2DownloadSuccess)"
516-
${Else}
517-
DetailPrint "$(webview2DownloadError)"
518-
Abort "$(webview2AbortError)"
507+
${If} $4 == ""
508+
; Webview2 installation
509+
;
510+
; Skip if updating
511+
${If} $UpdateMode <> 1
512+
!if "${INSTALLWEBVIEW2MODE}" == "downloadBootstrapper"
513+
Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe"
514+
DetailPrint "$(webview2Downloading)"
515+
NSISdl::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\MicrosoftEdgeWebview2Setup.exe"
516+
Pop $0
517+
${If} $0 = 0
518+
DetailPrint "$(webview2DownloadSuccess)"
519+
${Else}
520+
DetailPrint "$(webview2DownloadError)"
521+
Abort "$(webview2AbortError)"
522+
${EndIf}
523+
StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe"
524+
Goto install_webview2
525+
!endif
526+
527+
!if "${INSTALLWEBVIEW2MODE}" == "embedBootstrapper"
528+
Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe"
529+
File "/oname=$TEMP\MicrosoftEdgeWebview2Setup.exe" "${WEBVIEW2BOOTSTRAPPERPATH}"
530+
DetailPrint "$(installingWebview2)"
531+
StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe"
532+
Goto install_webview2
533+
!endif
534+
535+
!if "${INSTALLWEBVIEW2MODE}" == "offlineInstaller"
536+
Delete "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe"
537+
File "/oname=$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" "${WEBVIEW2INSTALLERPATH}"
538+
DetailPrint "$(installingWebview2)"
539+
StrCpy $6 "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe"
540+
Goto install_webview2
541+
!endif
542+
543+
Goto webview2_done
544+
545+
install_webview2:
546+
DetailPrint "$(installingWebview2)"
547+
; $6 holds the path to the webview2 installer
548+
ExecWait "$6 ${WEBVIEW2INSTALLERARGS} /install" $1
549+
${If} $1 = 0
550+
DetailPrint "$(webview2InstallSuccess)"
551+
${Else}
552+
DetailPrint "$(webview2InstallError)"
553+
Abort "$(webview2AbortError)"
554+
${EndIf}
555+
webview2_done:
556+
${EndIf}
557+
${Else}
558+
!if "${MINIMUMWEBVIEW2VERSION}" != ""
559+
${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0
560+
${If} $R0 = 1
561+
update_webview:
562+
DetailPrint "$(installingWebview2)"
563+
${If} ${RunningX64}
564+
ReadRegStr $R1 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" "path"
565+
${Else}
566+
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\EdgeUpdate" "path"
567+
${EndIf}
568+
${If} $R1 == ""
569+
ReadRegStr $R1 HKCU "SOFTWARE\Microsoft\EdgeUpdate" "path"
570+
${EndIf}
571+
${If} $R1 != ""
572+
; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md
573+
; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath"
574+
ExecWait `"$R1" /install appguid=${WEBVIEW2APPGUID}&needsadmin=true` $1
575+
${If} $1 = 0
576+
DetailPrint "$(webview2InstallSuccess)"
577+
${Else}
578+
MessageBox MB_ICONEXCLAMATION|MB_ABORTRETRYIGNORE "$(webview2InstallError)" IDIGNORE ignore IDRETRY update_webview
579+
Quit
580+
ignore:
581+
${EndIf}
582+
${EndIf}
519583
${EndIf}
520-
StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe"
521-
Goto install_webview2
522584
!endif
523-
524-
!if "${INSTALLWEBVIEW2MODE}" == "embedBootstrapper"
525-
Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe"
526-
File "/oname=$TEMP\MicrosoftEdgeWebview2Setup.exe" "${WEBVIEW2BOOTSTRAPPERPATH}"
527-
DetailPrint "$(installingWebview2)"
528-
StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe"
529-
Goto install_webview2
530-
!endif
531-
532-
!if "${INSTALLWEBVIEW2MODE}" == "offlineInstaller"
533-
Delete "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe"
534-
File "/oname=$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" "${WEBVIEW2INSTALLERPATH}"
535-
DetailPrint "$(installingWebview2)"
536-
StrCpy $6 "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe"
537-
Goto install_webview2
538-
!endif
539-
540-
Goto webview2_done
541-
542-
install_webview2:
543-
DetailPrint "$(installingWebview2)"
544-
; $6 holds the path to the webview2 installer
545-
ExecWait "$6 ${WEBVIEW2INSTALLERARGS} /install" $1
546-
${If} $1 = 0
547-
DetailPrint "$(webview2InstallSuccess)"
548-
${Else}
549-
DetailPrint "$(webview2InstallError)"
550-
Abort "$(webview2AbortError)"
551-
${EndIf}
552-
webview2_done:
553585
${EndIf}
554586
SectionEnd
555587

tooling/cli/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,13 @@
23662366
"string",
23672367
"null"
23682368
]
2369+
},
2370+
"minimumWebview2Version": {
2371+
"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.",
2372+
"type": [
2373+
"string",
2374+
"null"
2375+
]
23692376
}
23702377
},
23712378
"additionalProperties": false

tooling/cli/src/helpers/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub fn nsis_settings(config: NsisConfig) -> tauri_bundler::NsisSettings {
107107
compression: config.compression,
108108
start_menu_folder: config.start_menu_folder,
109109
installer_hooks: config.installer_hooks,
110+
minimum_webview2_version: config.minimum_webview2_version,
110111
}
111112
}
112113

0 commit comments

Comments
 (0)