Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,57 @@ jobs:
name: MXU-win-${{ matrix.arch }}
path: "install"

- name: Download WebView2 Fixed Version Runtime
shell: pwsh
run: |
# 从微软官方 CDN 下载 WebView2 Fixed Version Runtime
# 更新版本时需同步更新 $version 和 $guidMap 中的 GUID
# GUID 可在 https://developer.microsoft.com/en-us/microsoft-edge/webview2/ 页面从 Fixed Version 的下载链接中获取
# 或前往 Scoop 存储库查看 https://github.com/ScoopInstaller/Extras/blob/master/bucket/webview2.json
$version = '145.0.3800.65'
$archMap = @{ 'x86_64' = 'x64'; 'aarch64' = 'arm64' }
$guidMap = @{
'x64' = 'c411606c-d282-4304-8420-8ae6b1dd3e9a'
'arm64' = '2d2cf37b-d24c-4c72-b5bc-e8061e7a7583'
}
$arch = $archMap['${{ matrix.arch }}']
$guid = $guidMap[$arch]
$cabName = "Microsoft.WebView2.FixedVersionRuntime.$version.$arch.cab"
$uri = "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/$guid/$cabName"

Write-Host "Downloading $cabName from Microsoft CDN ..."
Invoke-WebRequest -Uri $uri -OutFile $cabName -ErrorAction Stop

$tempDir = "temp_wv2"
New-Item -ItemType Directory -Force -Path $tempDir | Out-Null
expand.exe $cabName -F:* $tempDir
if ($LASTEXITCODE -ne 0) {
throw "Failed to extract $cabName with exit code $LASTEXITCODE"
}

$dest = "install\webview2_runtime"
New-Item -ItemType Directory -Force -Path $dest | Out-Null

# cab 解压后文件在版本子目录中,将其内容移动到 webview2_runtime/
$versionDir = Get-ChildItem $tempDir -Directory | Where-Object { $_.Name -like "Microsoft.WebView2*" } | Select-Object -First 1
if (-not $versionDir -and (Get-ChildItem $tempDir).Count -eq 0) {
throw "No files found after extracting $cabName"
}
if ($versionDir) {
Copy-Item -Path "$($versionDir.FullName)\*" -Destination $dest -Recurse -Force -ErrorAction Stop
} else {
Copy-Item -Path "$tempDir\*" -Destination $dest -Recurse -Force -ErrorAction Stop
}

Remove-Item $cabName, $tempDir -Recurse -Force
Write-Host "WebView2 Fixed Version Runtime $version ($arch) ready at $dest"

- name: Upload fixed-webview artifacts
uses: actions/upload-artifact@v4
with:
name: MXU-win-${{ matrix.arch }}-fixed-webview
path: "install"

linux:
needs: meta
runs-on: ubuntu-latest
Expand Down
14 changes: 13 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ fn main() {
// 确保目录存在
let _ = std::fs::create_dir_all(&webview_data_dir);
std::env::set_var("WEBVIEW2_USER_DATA_FOLDER", &webview_data_dir);

// 检测内置的 WebView2 固定版本运行时
let webview2_runtime_dir = exe_dir.join("webview2_runtime");
if webview2_runtime_dir.is_dir() {
std::env::set_var(
"WEBVIEW2_BROWSER_EXECUTABLE_FOLDER",
&webview2_runtime_dir,
);
}
}
}

if !webview2::ensure_webview2() {
// 未内置 WebView2 运行时时,检测系统是否已安装,未安装则自动下载安装
if std::env::var_os("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER").is_none()
&& !webview2::ensure_webview2()
{
std::process::exit(1);
}

Expand Down
Loading