Extracted from prototypes/yetano-webview (AP1): packages assets, document, bridge and window (macOS Cocoa/WKWebView via cgo, Windows Win32/WebView2 pure Go). No local HTTP listener or port: assets go through the WebView's resource handler, app routes through the native message binding. Own go.mod and gui/vX.Y.Z tags keep cgo and the WebView dependencies out of the main core module. Adds backend-free tests for the window's dispatch/destroy guards and a yet-gui migration guide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package bridge
|
|
|
|
import (
|
|
_ "embed"
|
|
"encoding/json"
|
|
)
|
|
|
|
//go:embed bridge.js
|
|
var bridgeJS string
|
|
|
|
// PageConfig is exposed to the page as window.__yetano_config (and
|
|
// window.yetano.config) before the bridge installs itself.
|
|
type PageConfig struct {
|
|
External string `json:"external"` // "reject" (default) or "passthrough"
|
|
Transport string `json:"transport"` // "native" (scheme handler) or "inline" (data: entry, bridge only)
|
|
Origin string `json:"origin,omitempty"`
|
|
DefaultTimeoutMs int `json:"defaultTimeoutMs,omitempty"`
|
|
HandshakeTimeoutMs int `json:"handshakeTimeoutMs,omitempty"`
|
|
ForwardConsole bool `json:"forwardConsole,omitempty"`
|
|
Selftest bool `json:"selftest,omitempty"`
|
|
Run int `json:"run,omitempty"`
|
|
ProtocolOverride int `json:"protocolOverride,omitempty"` // tests only
|
|
}
|
|
|
|
// InitScript returns the document-start script: config + bridge.
|
|
func InitScript(cfg PageConfig) string {
|
|
if cfg.External == "" {
|
|
cfg.External = "reject"
|
|
}
|
|
b, _ := json.Marshal(cfg)
|
|
return "window.__yetano_config=" + string(b) + ";\n" + bridgeJS
|
|
}
|