Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bundler/nsis): add minimum webview2 version checks #10339

Merged
merged 19 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
36e2425
Add ensure minimum webview2 version
Legend-Master Jul 21, 2024
ea13a68
needsadmin
Legend-Master Jul 21, 2024
9e1376e
Add setting and change file
Legend-Master Jul 21, 2024
eca62cf
Forget to change hard coded version
Legend-Master Jul 21, 2024
ff50c73
Be clear it's for nsis installer
Legend-Master Jul 21, 2024
fb2278e
Wrong quote
Legend-Master Jul 21, 2024
507de44
Add comment abuot chromium updater docs
Legend-Master Jul 21, 2024
35d154f
Merge remote-tracking branch 'upstream/dev' into nsis-ensure-webview2…
Legend-Master Jul 31, 2024
4dedf80
Merge branch 'dev' into nsis-ensure-webview2-version
Legend-Master Jul 31, 2024
21b4c7e
Merge remote-tracking branch 'upstream/dev' into nsis-ensure-webview2…
Legend-Master Aug 4, 2024
56b46ab
Merge branch 'nsis-ensure-webview2-version' of https://github.com/Leg…
Legend-Master Aug 4, 2024
039b5c2
Merge remote-tracking branch 'upstream/dev' into nsis-ensure-webview2…
Legend-Master Aug 22, 2024
0b7e61f
Use path from registry key and string version
Legend-Master Aug 22, 2024
2193ee7
Update .changes/nsis-ensure-webview2-version.md
Legend-Master Aug 22, 2024
d7c9074
Add warning message box instead of force abort
Legend-Master Aug 22, 2024
da34e94
Tweak name and description
Legend-Master Aug 23, 2024
c366f77
Move retry down
Legend-Master Aug 23, 2024
71257a4
Merge remote-tracking branch 'upstream/dev' into nsis-ensure-webview2…
Legend-Master Aug 23, 2024
bc8e468
Update .changes/nsis-ensure-webview2-version.md [skip ci]
amrbashir Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/nsis-ensure-webview2-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": "patch:feat"
Legend-Master marked this conversation as resolved.
Show resolved Hide resolved
---

Add a new option `ensureWebview2Version` for Windows NSIS installer to trigger a webview2 update if the user's webview2 is older than this version
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,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
Expand Down
5 changes: 5 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,11 @@ pub struct NsisConfig {
/// ```
#[serde(alias = "installer-hooks")]
pub installer_hooks: Option<PathBuf>,
/// 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<u16>,
Legend-Master marked this conversation as resolved.
Show resolved Hide resolved
}

/// Install modes for the Webview2 runtime.
Expand Down
4 changes: 4 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ pub struct NsisSettings {
/// !macroend
/// ```
pub installer_hooks: Option<PathBuf>,
/// 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<u16>,
Legend-Master marked this conversation as resolved.
Show resolved Hide resolved
}

/// The Windows bundle settings.
Expand Down
6 changes: 6 additions & 0 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
117 changes: 69 additions & 48 deletions tooling/bundler/src/bundle/windows/templates/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ${StrLoc}
!define WEBVIEW2INSTALLERARGS "{{webview2_installer_args}}"
!define WEBVIEW2BOOTSTRAPPERPATH "{{webview2_bootstrapper_path}}"
!define WEBVIEW2INSTALLERPATH "{{webview2_installer_path}}"
!define MINIMUMWEBVIEW2VERSION "{{minimum_webview2_version}}"
!define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}"
!define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}"
!define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}"
Expand Down Expand Up @@ -499,57 +500,77 @@ 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)"
; 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
Legend-Master marked this conversation as resolved.
Show resolved Hide resolved
${If} $1 = 0
DetailPrint "$(webview2InstallSuccess)"
${Else}
DetailPrint "$(webview2InstallError)"
Abort "$(webview2AbortError)"
${EndIf}
${EndIf}
webview2_done:
!endif
${EndIf}
SectionEnd

Expand Down
9 changes: 9 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,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
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/helpers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
Loading