5b7f7d9f31
A packed binary opened the system browser, so it felt like a tab, not an app. Build with -tags webview (cgo) and the viewer instead opens the site in its own window backed by the OS WebView: WKWebView on macOS, WebView2 on Windows, WebKitGTK on Linux. The viewer package picks an implementation at build time. The default file opens the browser and keeps the build pure Go, so CGO_ENABLED=0 and the release pipeline are untouched. The webview file links the platform WebView and runs its event loop on the main goroutine, which main now pins with LockOSThread before anything else, since macOS requires UI on the initial thread. Both kage open and the embedded viewer serve over HTTP in a goroutine and hand the URL to the viewer, then tear the server down when the window closes or Ctrl-C cancels. The window title comes from the archive's M/Title. OpenInBrowser moves out of pack into the viewer package, its only caller.
38 lines
845 B
Go
38 lines
845 B
Go
//go:build !webview
|
|
|
|
package viewer
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNativeIsFalseInDefaultBuild(t *testing.T) {
|
|
if Native {
|
|
t.Fatal("Native should be false without the webview build tag")
|
|
}
|
|
}
|
|
|
|
func TestLockMainThreadIsNoop(t *testing.T) {
|
|
// Must not panic; there is no native UI to pin to.
|
|
LockMainThread()
|
|
}
|
|
|
|
func TestShowReturnsWhenContextCancelled(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
done := make(chan error, 1)
|
|
// Browser:false so no system browser is launched during the test.
|
|
go func() { done <- Show(ctx, Options{URL: "http://127.0.0.1:0", Browser: false}) }()
|
|
|
|
cancel()
|
|
select {
|
|
case err := <-done:
|
|
if err != nil {
|
|
t.Fatalf("Show returned error: %v", err)
|
|
}
|
|
case <-time.After(2 * time.Second):
|
|
t.Fatal("Show did not return after context cancellation")
|
|
}
|
|
}
|