fix(windows): restore Windows 7 startup compatibility
This commit is contained in:
@@ -1,65 +1,76 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$CacheRoot = (Join-Path $env:LOCALAPPDATA "tauri"),
|
||||
[string]$RuntimeDirectory = (Join-Path $PSScriptRoot "..\..\src-tauri\webview2-fixed-runtime"),
|
||||
[string]$DownloadDirectory = $env:RUNNER_TEMP
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$runtimeVersion = "109.0.1518.140"
|
||||
$runtimeUrl = "https://catalog.s.download.windowsupdate.com/c/msdownload/update/software/updt/2023/09/microsoftedgestandaloneinstallerx64_1c890b4b8dd6b7c93da98ebdc08ecdc5e30e50cb.exe"
|
||||
$runtimeSha256 = "eac95c8095ec5f9971eade9827d8fb67fd251f5c16e702b5312d31067e39119b"
|
||||
$evergreenUrl = "https://go.microsoft.com/fwlink/?linkid=2124701"
|
||||
$runtimeVersion = "109.0.1518.78"
|
||||
$runtimeFolderName = "Microsoft.WebView2.FixedVersionRuntime.$runtimeVersion.x64"
|
||||
$archiveName = "$runtimeFolderName.cab"
|
||||
$runtimeUrl = "https://github.com/westinyang/WebView2RuntimeArchive/releases/download/$runtimeVersion/$archiveName"
|
||||
$runtimeSha256 = "7622281cf83de1a35e3a471f432f7a897d65f0a7d3975df08512b7b253dd45c7"
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($CacheRoot)) {
|
||||
throw "A Tauri cache root is required."
|
||||
if ([string]::IsNullOrWhiteSpace($RuntimeDirectory)) {
|
||||
throw "A WebView2 fixed runtime directory is required."
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($DownloadDirectory)) {
|
||||
$DownloadDirectory = [System.IO.Path]::GetTempPath()
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $DownloadDirectory | Out-Null
|
||||
$downloadPath = Join-Path $DownloadDirectory "MicrosoftEdgeWebView2Runtime-$runtimeVersion-x64.exe"
|
||||
$archivePath = Join-Path $DownloadDirectory $archiveName
|
||||
|
||||
if (Test-Path $downloadPath) {
|
||||
$downloadHash = (Get-FileHash -LiteralPath $downloadPath -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
if (Test-Path $archivePath) {
|
||||
$downloadHash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
if ($downloadHash -ne $runtimeSha256) {
|
||||
Remove-Item -LiteralPath $downloadPath -Force
|
||||
Remove-Item -LiteralPath $archivePath -Force
|
||||
}
|
||||
}
|
||||
|
||||
if (!(Test-Path $downloadPath)) {
|
||||
Write-Host "Downloading WebView2 Runtime $runtimeVersion for Windows 7..."
|
||||
Invoke-WebRequest -Uri $runtimeUrl -OutFile $downloadPath
|
||||
if (!(Test-Path $archivePath)) {
|
||||
Write-Host "Downloading WebView2 fixed runtime $runtimeVersion for Windows 7..."
|
||||
Invoke-WebRequest -Uri $runtimeUrl -OutFile $archivePath
|
||||
}
|
||||
|
||||
$actualHash = (Get-FileHash -LiteralPath $downloadPath -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
$actualHash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
if ($actualHash -ne $runtimeSha256) {
|
||||
throw "WebView2 Runtime SHA-256 mismatch. Expected $runtimeSha256, got $actualHash."
|
||||
throw "WebView2 fixed runtime SHA-256 mismatch. Expected $runtimeSha256, got $actualHash."
|
||||
}
|
||||
|
||||
# Tauri 2.11 does not expose an offline-installer path override. It resolves the
|
||||
# Evergreen URL and reuses a matching cache entry, so place the verified 109
|
||||
# installer at that exact location before bundling.
|
||||
$response = Invoke-WebRequest -Uri $evergreenUrl -Method Head
|
||||
$resolvedUrl = $response.BaseResponse.RequestMessage.RequestUri.AbsoluteUri
|
||||
$match = [regex]::Match(
|
||||
$resolvedUrl,
|
||||
"/filestreamingservice/files/(?<guid>[^/]+)/(?<filename>[^/?]+)"
|
||||
)
|
||||
if (!$match.Success) {
|
||||
throw "Unexpected Evergreen WebView2 URL: $resolvedUrl"
|
||||
# Microsoft no longer publishes old Fixed Version downloads. The archive is
|
||||
# accepted only when both its pinned hash and original Microsoft signature match.
|
||||
$signature = Get-AuthenticodeSignature -LiteralPath $archivePath
|
||||
if ($signature.Status -ne [System.Management.Automation.SignatureStatus]::Valid -or
|
||||
$null -eq $signature.SignerCertificate -or
|
||||
$signature.SignerCertificate.Subject -notmatch "Microsoft Corporation") {
|
||||
throw "WebView2 fixed runtime does not have a valid Microsoft signature."
|
||||
}
|
||||
|
||||
$cacheDirectory = Join-Path $CacheRoot (Join-Path "x64" $match.Groups["guid"].Value)
|
||||
$cachePath = Join-Path $cacheDirectory $match.Groups["filename"].Value
|
||||
New-Item -ItemType Directory -Force -Path $cacheDirectory | Out-Null
|
||||
Copy-Item -LiteralPath $downloadPath -Destination $cachePath -Force
|
||||
$extractDirectory = Join-Path $DownloadDirectory "dbx-webview2-fixed-runtime-$runtimeVersion"
|
||||
if (Test-Path $extractDirectory) {
|
||||
Remove-Item -LiteralPath $extractDirectory -Recurse -Force
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path $extractDirectory | Out-Null
|
||||
|
||||
$cacheHash = (Get-FileHash -LiteralPath $cachePath -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
if ($cacheHash -ne $runtimeSha256) {
|
||||
throw "Cached WebView2 Runtime SHA-256 mismatch. Expected $runtimeSha256, got $cacheHash."
|
||||
$expand = Join-Path $env:SystemRoot "System32\expand.exe"
|
||||
& $expand $archivePath "-F:*" $extractDirectory
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Failed to extract WebView2 fixed runtime archive (exit code $LASTEXITCODE)."
|
||||
}
|
||||
|
||||
Write-Host "Prepared WebView2 Runtime $runtimeVersion at $cachePath"
|
||||
$extractedRuntime = Join-Path $extractDirectory $runtimeFolderName
|
||||
$runtimeExecutable = Join-Path $extractedRuntime "msedgewebview2.exe"
|
||||
if (!(Test-Path $runtimeExecutable)) {
|
||||
throw "Extracted WebView2 runtime is missing msedgewebview2.exe."
|
||||
}
|
||||
|
||||
if (Test-Path $RuntimeDirectory) {
|
||||
Remove-Item -LiteralPath $RuntimeDirectory -Recurse -Force
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $RuntimeDirectory) | Out-Null
|
||||
Move-Item -LiteralPath $extractedRuntime -Destination $RuntimeDirectory
|
||||
|
||||
Write-Host "Prepared WebView2 fixed runtime $runtimeVersion at $RuntimeDirectory"
|
||||
|
||||
Reference in New Issue
Block a user