From da76b89856bbecf5a0e24de0996aa090e08870d3 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Mon, 13 Jul 2026 22:53:03 +0800 Subject: [PATCH] build: use system WebView2 for Windows archive --- .gitignore | 11 +------- README.md | 15 +++++----- main.go | 1 - packaging/windows/Verstak.cmd | 8 ------ platform_options_other.go | 7 ----- platform_options_windows.go | 35 ----------------------- runtime_path.go | 7 ----- runtime_path_test.go | 11 -------- scripts/build-windows.sh | 4 +-- scripts/package-windows-portable.sh | 44 +---------------------------- scripts/test-package-formats.sh | 18 +++++++++--- 11 files changed, 26 insertions(+), 135 deletions(-) delete mode 100644 platform_options_other.go delete mode 100644 platform_options_windows.go delete mode 100644 runtime_path.go delete mode 100644 runtime_path_test.go diff --git a/.gitignore b/.gitignore index baa40f8..d918aa0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,7 @@ # .gitignore frontend/node_modules/ frontend/dist/ -build/bin/verstak-desktop -build/appicon.png -build/windows/ -build/windows-amd64/ -build/linux-amd64/ -build/appimage/ -build/deb/ -build/downloads/ -build/tools/ -build/webview2-runtime/ +build/ smoke-platform plugins/ vendor/ diff --git a/README.md b/README.md index 7a77c8d..6fbc5ad 100644 --- a/README.md +++ b/README.md @@ -104,16 +104,17 @@ On distributions without FUSE support, use Build the Windows portable ZIP on Linux with MinGW: ```bash -sudo apt install gcc-mingw-w64-x86-64 cabextract zip +sudo apt install gcc-mingw-w64-x86-64 zip ./scripts/package-windows-portable.sh v0.1.0-alpha.1 ``` -The script downloads the current x64 Microsoft Fixed Version WebView2 Runtime, -bundles it next to `verstak-desktop.exe`, and writes -`release/verstak-windows-amd64-.zip`. On Windows, extract the ZIP to a -local disk (not a network share) and launch `Verstak.cmd`. No separate WebView2 -installation or download is required. To make a reproducible build from an -already downloaded CAB, set `VERSTAK_WEBVIEW2_CAB=/path/to/FixedVersionRuntime.x64.cab`. +The ZIP uses the x64 Evergreen Microsoft WebView2 Runtime installed in Windows +and writes `release/verstak-windows-amd64-.zip`. Extract it to a local +disk (not a network share) and launch `Verstak.cmd`. Windows 11 and most +Windows 10 installations already include this runtime. If Verstak does not +start, install the official [Microsoft WebView2 Runtime x64 standalone +installer](https://go.microsoft.com/fwlink/p/?LinkId=2124701), then launch it +again. Each format is listed in `release/SHA256SUMS` after packaging. diff --git a/main.go b/main.go index 4777c5d..80eb867 100644 --- a/main.go +++ b/main.go @@ -258,7 +258,6 @@ func main() { app, }, } - applyPlatformOptions(appOptions) err = wails.Run(appOptions) if err != nil { diff --git a/packaging/windows/Verstak.cmd b/packaging/windows/Verstak.cmd index a169559..366a007 100644 --- a/packaging/windows/Verstak.cmd +++ b/packaging/windows/Verstak.cmd @@ -2,12 +2,4 @@ setlocal set "ROOT=%~dp0" -if not exist "%ROOT%webview2\msedgewebview2.exe" ( - echo The bundled WebView2 runtime is missing. - pause - exit /b 1 -) - -icacls "%ROOT%webview2" /grant *S-1-15-2-2:(OI)(CI)(RX) /T /C >nul 2>&1 -icacls "%ROOT%webview2" /grant *S-1-15-2-1:(OI)(CI)(RX) /T /C >nul 2>&1 start "" "%ROOT%verstak-desktop.exe" %* diff --git a/platform_options_other.go b/platform_options_other.go deleted file mode 100644 index d346049..0000000 --- a/platform_options_other.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build !windows - -package main - -import "github.com/wailsapp/wails/v2/pkg/options" - -func applyPlatformOptions(_ *options.App) {} diff --git a/platform_options_windows.go b/platform_options_windows.go deleted file mode 100644 index 279d9d6..0000000 --- a/platform_options_windows.go +++ /dev/null @@ -1,35 +0,0 @@ -//go:build windows - -package main - -import ( - "os" - "os/exec" - "path/filepath" - - "github.com/wailsapp/wails/v2/pkg/options" - "github.com/wailsapp/wails/v2/pkg/options/windows" -) - -func applyPlatformOptions(app *options.App) { - executablePath, err := os.Executable() - if err != nil { - return - } - - runtimePath := bundledWebView2Path(executablePath) - if _, err := os.Stat(filepath.Join(runtimePath, "msedgewebview2.exe")); err != nil { - return - } - - // Fixed Version WebView2 runtimes from v120 need these permissions on - // unpackaged Windows 10 applications. The archive is extracted by the user, - // so the command can update permissions without an installer or download. - for _, sid := range []string{"*S-1-15-2-2", "*S-1-15-2-1"} { - _ = exec.Command("icacls", runtimePath, "/grant", sid+":(OI)(CI)(RX)", "/T", "/C").Run() - } - - app.Windows = &windows.Options{ - WebviewBrowserPath: runtimePath, - } -} diff --git a/runtime_path.go b/runtime_path.go deleted file mode 100644 index 3fa1ac3..0000000 --- a/runtime_path.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "path/filepath" - -func bundledWebView2Path(executablePath string) string { - return filepath.Join(filepath.Dir(executablePath), "webview2") -} diff --git a/runtime_path_test.go b/runtime_path_test.go deleted file mode 100644 index d3b6192..0000000 --- a/runtime_path_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import "testing" - -func TestBundledWebView2PathUsesExecutableDirectory(t *testing.T) { - got := bundledWebView2Path("/opt/verstak/verstak-desktop") - want := "/opt/verstak/webview2" - if got != want { - t.Fatalf("bundledWebView2Path() = %q, want %q", got, want) - } -} diff --git a/scripts/build-windows.sh b/scripts/build-windows.sh index b631e5e..9c2ce40 100755 --- a/scripts/build-windows.sh +++ b/scripts/build-windows.sh @@ -55,8 +55,8 @@ fi # Wails' -compiler option selects a Go binary, not a C compiler. Cross-CGO # therefore has to be supplied through the standard Go environment instead. -# The runtime is bundled by package-windows-portable.sh, so never compile an -# Evergreen downloader into the portable executable. +# The portable archive uses the installed Evergreen WebView2 Runtime, so never +# compile an Evergreen downloader into the executable. CC="$WINDOWS_CC" CGO_ENABLED=1 "$WAILS" build -clean -platform windows/amd64 \ -webview2 error -o verstak-desktop.exe diff --git a/scripts/package-windows-portable.sh b/scripts/package-windows-portable.sh index 6536839..54b27fc 100755 --- a/scripts/package-windows-portable.sh +++ b/scripts/package-windows-portable.sh @@ -3,62 +3,21 @@ set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" VERSION="${1:-}" -WEBVIEW2_CAB="${VERSTAK_WEBVIEW2_CAB:-}" -WEBVIEW2_URL="${VERSTAK_WEBVIEW2_URL:-}" if [[ -z "$VERSION" || ! "$VERSION" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]]; then echo "usage: $0 " >&2 echo "example: $0 v0.1.0-alpha.1" >&2 exit 2 fi -for command in cabextract curl python3 zip; do +for command in zip; do if ! command -v "$command" >/dev/null; then echo "$command is required to create the Windows portable archive" >&2 exit 1 fi done -if [[ -z "$WEBVIEW2_CAB" ]]; then - if [[ -z "$WEBVIEW2_URL" ]]; then - WEBVIEW2_URL="$(python3 - <<'PY' -import re -import sys -import urllib.request - -with urllib.request.urlopen('https://developer.microsoft.com/en-us/microsoft-edge/webview2/', timeout=30) as response: - page = response.read().decode('utf-8') -page = page.replace(r'\u002F', '/') -match = re.search(r'"x64","(https://[^\"]+Microsoft\.WebView2\.FixedVersionRuntime[^\"]+\.x64\.cab)"', page) -if not match: - sys.exit('could not locate the x64 FixedVersionRuntime CAB on the Microsoft WebView2 download page') -print(match.group(1)) -PY -)" - fi - WEBVIEW2_CAB="$ROOT/build/downloads/$(basename "${WEBVIEW2_URL%%\?*}")" - mkdir -p "$(dirname "$WEBVIEW2_CAB")" - if [[ ! -f "$WEBVIEW2_CAB" ]]; then - curl --fail --location --show-error "$WEBVIEW2_URL" -o "$WEBVIEW2_CAB" - fi -fi - -if [[ ! -f "$WEBVIEW2_CAB" ]]; then - echo "FixedVersionRuntime CAB was not found: $WEBVIEW2_CAB" >&2 - exit 1 -fi - "$ROOT/scripts/build-windows.sh" -RUNTIME_EXTRACT="$ROOT/build/webview2-runtime" -rm -rf "$RUNTIME_EXTRACT" -mkdir -p "$RUNTIME_EXTRACT" -cabextract -q -d "$RUNTIME_EXTRACT" "$WEBVIEW2_CAB" -WEBVIEW2_RUNTIME_DIR="$(dirname "$(find "$RUNTIME_EXTRACT" -type f -iname msedgewebview2.exe -print -quit)")" -if [[ -z "$WEBVIEW2_RUNTIME_DIR" || ! -f "$WEBVIEW2_RUNTIME_DIR/msedgewebview2.exe" ]]; then - echo "FixedVersionRuntime CAB does not contain msedgewebview2.exe" >&2 - exit 1 -fi - RELEASE_ROOT="$ROOT/release" STAGING="$RELEASE_ROOT/verstak-windows-amd64-$VERSION" ARCHIVE="$RELEASE_ROOT/verstak-windows-amd64-$VERSION.zip" @@ -67,7 +26,6 @@ mkdir -p "$STAGING" cp -R "$ROOT/build/windows-amd64/." "$STAGING/" install -m 644 "$ROOT/README.md" "$ROOT/LICENSE" "$STAGING/" install -m 644 "$ROOT/packaging/windows/Verstak.cmd" "$STAGING/Verstak.cmd" -cp -R "$WEBVIEW2_RUNTIME_DIR" "$STAGING/webview2" (cd "$RELEASE_ROOT" && zip -qr "$(basename "$ARCHIVE")" "$(basename "$STAGING")") (cd "$RELEASE_ROOT" && find . -maxdepth 1 -type f \( -name '*.deb' -o -name '*.AppImage' -o -name '*.zip' \) \ diff --git a/scripts/test-package-formats.sh b/scripts/test-package-formats.sh index 126c497..f06104a 100755 --- a/scripts/test-package-formats.sh +++ b/scripts/test-package-formats.sh @@ -18,11 +18,21 @@ grep -Fq 'packaging/deb/control' "$ROOT/scripts/package-deb.sh" grep -Fq 'libwebkit2gtk-4.1-0' "$ROOT/packaging/deb/control" grep -Fq 'appimagetool' "$ROOT/scripts/package-appimage.sh" grep -Fq 'WebKitWebProcess' "$ROOT/scripts/package-appimage.sh" -grep -Fq 'FixedVersionRuntime' "$ROOT/scripts/package-windows-portable.sh" -grep -Fq 'msedgewebview2.exe' "$ROOT/scripts/package-windows-portable.sh" +if grep -Fq 'FixedVersionRuntime' "$ROOT/scripts/package-windows-portable.sh"; then + echo "Windows portable archive must not bundle Fixed Version WebView2" >&2 + exit 1 +fi +if grep -Fq 'msedgewebview2.exe' "$ROOT/scripts/package-windows-portable.sh"; then + echo "Windows portable archive must not bundle WebView2 binaries" >&2 + exit 1 +fi +if [[ -e "$ROOT/platform_options_windows.go" ]]; then + echo "Windows runtime override must not be present" >&2 + exit 1 +fi grep -Fq 'zip -qr' "$ROOT/scripts/package-windows-portable.sh" -grep -Fq 'WebviewBrowserPath' "$ROOT/platform_options_windows.go" -grep -Fq 'webview2' "$ROOT/platform_options_windows.go" +grep -Fq 'LinkId=2124701' "$ROOT/README.md" +grep -Fq 'WebView2 Runtime' "$ROOT/README.md" grep -Fq 'chmod -R a+rX' "$ROOT/scripts/build-linux-bundle.sh" echo "desktop package script contracts passed"