From 2286bc597d1839810027c3fe2e3545a9b6da4faf Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 25 Oct 2026 05:49:44 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=88=86=E5=8F=91=E5=8C=85=E6=94=B9?= =?UTF-8?q?=E7=94=A8=20WebView2=20=E5=9C=A8=E7=BA=BF=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- scripts/package.py | 11 ++++++++--- src-tauri/src/lib.rs | 10 +++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6474365..94eab45 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Windows 桌面程序,用来登录 RaptDrama、黄豆短剧和 DramaBox,浏 1. 解压 `dist/VideosDownTools-windows-x64.zip`。 2. 进入 `VideosDownTools`,运行 `VideosDownTools.exe`。 -3. 压缩包里已经带有 Python、adb、ffmpeg 和 WebView2 离线安装包。本机如果还没有 WebView2,程序启动时会静默安装。 +3. 压缩包里已经带有 Python、adb、ffmpeg 和大约 2 MB 的 WebView2 在线安装器。本机如果还没有 WebView2,程序启动时会用它联网静默安装。 程序会在自己的目录里写入: @@ -44,8 +44,8 @@ python scripts\package.py - `dist/cache` 里的 Windows 嵌入式 Python,以及 `server/requirements.txt` 里的依赖 - `vendor/platform-tools` 里的 adb,拷到压缩包的 `tools/platform-tools` - `tools/ffmpeg/ffmpeg.exe` -- `vendor/webview2/MicrosoftEdgeWebView2RuntimeInstallerX64.exe` +- `vendor/webview2/MicrosoftEdgeWebview2Setup.exe`。本机还没有这个文件时,打包会从微软下载这份在线安装器。同目录里的离线安装包不会打进压缩包。 -adb 和 WebView2 打包时不再下载。完成后得到 `dist/VideosDownTools-windows-x64.zip`。 +adb 打包时不再下载。完成后得到 `dist/VideosDownTools-windows-x64.zip`。 打包脚本是 Python,公共步骤和平台相关的运行时是分开的。目前只接好了 Windows。macOS 和 Linux 以后把对应文件放进 `vendor` 即可。 diff --git a/scripts/package.py b/scripts/package.py index 3ee23a5..6de86f7 100644 --- a/scripts/package.py +++ b/scripts/package.py @@ -4,7 +4,7 @@ python scripts/package.py -Windows 会编译界面和桌面程序,并拷贝本地已有的 Python 缓存、adb、ffmpeg 和 WebView2 离线安装包。 +Windows 会编译界面和桌面程序,并拷贝本地已有的 Python 缓存、adb、ffmpeg 和 WebView2 在线安装器。 macOS、Linux 以后可以在对应函数里补上自己的运行时,其余步骤可以复用。 """ @@ -31,7 +31,8 @@ PYTHON_EMBED_URL = ( ) GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py" FFMPEG_URL = "https://github.com/eugeneware/ffmpeg-static/releases/download/b6.1.1/ffmpeg-win32-x64.gz" -WEBVIEW_INSTALLER = "MicrosoftEdgeWebView2RuntimeInstallerX64.exe" +WEBVIEW_INSTALLER = "MicrosoftEdgeWebview2Setup.exe" +WEBVIEW_BOOTSTRAP_URL = "https://go.microsoft.com/fwlink/p/?LinkId=2124703" def log(message: str) -> None: @@ -166,7 +167,11 @@ def bundle_webview(stage: Path) -> None: return source = ROOT / "vendor" / "webview2" / WEBVIEW_INSTALLER if not source.is_file(): - raise SystemExit(f"vendor/webview2 里没有 {WEBVIEW_INSTALLER}") + download(WEBVIEW_BOOTSTRAP_URL, source) + data = source.read_bytes()[:2] + size = source.stat().st_size + if data != b"MZ" or not 200_000 <= size <= 20_000_000: + raise SystemExit(f"{WEBVIEW_INSTALLER} 不是 WebView2 在线安装器") dest = stage / "vendor" / "webview2" dest.mkdir(parents=True, exist_ok=True) shutil.copy2(source, dest / source.name) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 9089ff1..6e1532d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -54,11 +54,11 @@ fn prepare_webview_runtime(root: &Path) { if webview_runtime_installed() { return; } - let installer = root - .join("vendor") - .join("webview2") - .join("MicrosoftEdgeWebView2RuntimeInstallerX64.exe"); - if installer.is_file() { + let installer = ["MicrosoftEdgeWebview2Setup.exe", "MicrosoftEdgeWebView2RuntimeInstallerX64.exe"] + .into_iter() + .map(|name| root.join("vendor").join("webview2").join(name)) + .find(|path| path.is_file()); + if let Some(installer) = installer { let _ = Command::new(installer).args(["/silent", "/install"]).status(); } }