//go:build windows package main // Is the WebView2 runtime actually installed? // // It is the one dependency OpsLog cannot ship inside its own executable, and // its absence is invisible: the process starts, Wails fails to create the // browser environment, and on some machines that failure arrives as a silent // exit rather than as an error we can print. So the version is read straight // from where the runtime registers itself, and written to the startup log // BEFORE the window is attempted — a log that says "WebView2: not found" // answers the whole question in one line. import ( "golang.org/x/sys/windows/registry" ) // webview2Client is the runtime's own update-client GUID, the key it registers // its version under. Documented by Microsoft for exactly this check. const webview2Client = `Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}` // webView2Version returns the installed runtime version, or "" if there is none. // // Both hives: a per-machine install writes to HKLM (and to the WOW6432 view of // it on 64-bit Windows, which is where it usually lands), a per-user install to // HKCU. Missing all three is the answer that matters. func webView2Version() string { type place struct { key registry.Key access uint32 } for _, p := range []place{ {registry.CURRENT_USER, registry.QUERY_VALUE}, {registry.LOCAL_MACHINE, registry.QUERY_VALUE}, {registry.LOCAL_MACHINE, registry.QUERY_VALUE | registry.WOW64_32KEY}, } { k, err := registry.OpenKey(p.key, webview2Client, p.access) if err != nil { continue } v, _, err := k.GetStringValue("pv") k.Close() if err == nil && v != "" && v != "0.0.0.0" { return v } } return "" }