magpie's windows are WebView2, which Windows 10 doesn't always have. Without it Wails handed the failure to ErrorHandler and exited, and the desktop build (-H windowsgui) has no console for the log line to land in: ufec's double-click came up to nothing at all. ufec found the cause, that Wails' own Env.Info().PlatformInfo["WebView2"] answers "" then, and that a box can't come from ErrorHandler (it runs on the thread Wails makes its windows on); this takes both from their branch. Run asks webView2Check right after application.New, before any window. Missing, it logs it and shows MessageBoxW (Yes/No, error icon, topmost) in the reader's language (trayLang): the runtime is missing, Microsoft's page https://developer.microsoft.com/microsoft-edge/webview2/, that "magpie web" and "magpie tui" work without it, and whether to open the page now; Yes opens it (ShellExecute), and Run ends. A key Wails doesn't set is read as present: refusing to start a magpie that would have worked is worse than the silent exit. The tray isn't kept: its panel is a WebView2 window too. Run: TestWebView2Missing and TestWebView2Notice (all OSes); TestWebView2MissingFromWails on the Windows box (10.0.0.132, Windows with WebView2 installed): a child process with Wails pointed at a folder that isn't a runtime reads missing, the machine's own runtime reads present. TestWebView2Missing goes red with webView2Missing made to answer false. On the box, a throwaway -H windowsgui test binary calling webView2Check with that bogus runtime path, run in the desktop session: the box came up titled "magpie 需要 WebView2" with the Chinese text, the page and 是/否 buttons (read back from the dialog's controls), the log line was written, pressing 是 opened the page in Edge and the check answered false. go test -tags nogui ./internal/gui in a sandbox HOME; gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and GOOS=windows; windows and linux builds. Not tried: a machine that really lacks the runtime (the box has it; the missing case is Wails' lookup failing on a path that isn't a runtime, the same failure), nor a real magpie.exe start through Run.
62 lines
3.2 KiB
Go
62 lines
3.2 KiB
Go
package gui
|
|
|
|
import "fmt"
|
|
|
|
// magpie's windows are WebView2 on Windows, a runtime Windows 10 doesn't
|
|
// always have. Without it Wails hands the failure to ErrorHandler and exits,
|
|
// and the desktop build has no console for that to land in: a double-click
|
|
// came up to nothing (#1806, ufec). Run asks before any window is made and,
|
|
// missing, says so in a box of Windows' own.
|
|
|
|
// webView2Page is Microsoft's download page for the runtime.
|
|
const webView2Page = "https://developer.microsoft.com/microsoft-edge/webview2/"
|
|
|
|
// webView2Missing reads Wails' own answer, Env.Info().PlatformInfo's
|
|
// "WebView2": the runtime's version, "" when its lookup failed, the lookup
|
|
// a window's WebView2 environment makes. A key Wails doesn't set at all
|
|
// says nothing, and is read as there: refusing to start a magpie that would
|
|
// have worked is worse than the silent exit.
|
|
func webView2Missing(info map[string]any) bool {
|
|
v, ok := info["WebView2"]
|
|
return ok && fmt.Sprint(v) == ""
|
|
}
|
|
|
|
// webView2Notice is the box's title and text in lang (trayLang's), English
|
|
// where it has none. It names the page and asks whether to open it; Yes
|
|
// opens it.
|
|
func webView2Notice(lang string) (title, body string) {
|
|
t, ok := webView2Words[lang]
|
|
if !ok {
|
|
t = webView2Words["en"]
|
|
}
|
|
return t[0], fmt.Sprintf(t[1], webView2Page)
|
|
}
|
|
|
|
var webView2Words = map[string][2]string{
|
|
"en": {"magpie needs WebView2",
|
|
"magpie's windows need Microsoft Edge WebView2 Runtime, which isn't installed on this computer.\r\n\r\n" +
|
|
"Install it from:\r\n%s\r\n\r\n" +
|
|
"Until then, \"magpie web\" opens magpie in your browser and \"magpie tui\" in a terminal.\r\n\r\n" +
|
|
"Open the download page now?"},
|
|
"zh": {"magpie 需要 WebView2",
|
|
"magpie 的窗口需要 Microsoft Edge WebView2 运行时,这台电脑上没有安装。\r\n\r\n" +
|
|
"请从这里安装:\r\n%s\r\n\r\n" +
|
|
"装好之前,可以用 \"magpie web\" 在浏览器里打开 magpie,或用 \"magpie tui\" 在终端里打开。\r\n\r\n" +
|
|
"现在打开下载页面吗?"},
|
|
"zh-TW": {"magpie 需要 WebView2",
|
|
"magpie 的視窗需要 Microsoft Edge WebView2 執行階段,這台電腦上沒有安裝。\r\n\r\n" +
|
|
"請從這裡安裝:\r\n%s\r\n\r\n" +
|
|
"裝好之前,可以用 \"magpie web\" 在瀏覽器裡開啟 magpie,或用 \"magpie tui\" 在終端機裡開啟。\r\n\r\n" +
|
|
"現在開啟下載頁面嗎?"},
|
|
"ja": {"magpie には WebView2 が必要です",
|
|
"magpie のウィンドウには Microsoft Edge WebView2 ランタイムが必要ですが、このコンピューターにはインストールされていません。\r\n\r\n" +
|
|
"こちらからインストールしてください:\r\n%s\r\n\r\n" +
|
|
"それまでは \"magpie web\" でブラウザーから、\"magpie tui\" でターミナルから magpie を使えます。\r\n\r\n" +
|
|
"今すぐダウンロードページを開きますか?"},
|
|
"de": {"magpie braucht WebView2",
|
|
"Die Fenster von magpie brauchen die Microsoft Edge WebView2 Runtime, die auf diesem Computer nicht installiert ist.\r\n\r\n" +
|
|
"Installieren Sie sie von:\r\n%s\r\n\r\n" +
|
|
"Bis dahin öffnet \"magpie web\" magpie im Browser und \"magpie tui\" im Terminal.\r\n\r\n" +
|
|
"Die Download-Seite jetzt öffnen?"},
|
|
}
|