Documentation
¶
Overview ¶
Package corehook lets Tango's own feature packages (menu, tray, ...) reach core internals without the root package exporting them.
It is a leaf package (it imports only internal/platform). The root tango package and the menu package fill in the variables from their init functions; they are nil until those packages are linked in.
Index ¶
Constants ¶
const InternalPrefix = "\x00tango-int:"
InternalPrefix starts every internal page→Go message:
"\x00tango-int:" + channel + ":" + payload
The core consumes such messages before App.OnMessage handlers (and so before ipc) see them. A channel name never contains ':'.
Variables ¶
var AdoptEmbeddedWebView func(parent any, canvas platform.Canvas, child any) (platform.EmbeddedWebView, error)
AdoptEmbeddedWebView returns an existing embedded surface's view. Main thread only. Set by package tango.
var AfterUIThread func(app any, done <-chan struct{}, release func())
AfterUIThread registers a stopped UI thread and an optional nonblocking release callback on the main thread. The callback runs there after done closes, including during quit if the regular queue has already stopped. Threads that miss the common quit deadline are abandoned without release.
var AppMenuProxy func(app any, parent platform.SurfaceID) (am platform.AppMenu, ok bool)
AppMenuProxy, when set, lets the menu package's SetAppMenu and SetSurfaceMenu for app (a *tango.App) and parent (0: the application menu) go somewhere else than the backend: it returns ok false to use the backend. Set by package uihost in tan dev workers.
var AttachCanvas func(surface any, layer platform.CanvasLayer, sink platform.CanvasSink) (platform.Canvas, error)
AttachCanvas puts a platform.Canvas inside the WebView surface surface (a *tango.Surface), placed by layer (docs/specs/canvas-surface.md, step D). sink receives the canvas callbacks on the main thread, never before AttachCanvas returns. The returned Canvas also implements platform.AttachedCanvas when the backend can move or detach it. It must be called on the main thread. It returns an error wrapping platform.ErrUnsupported when the backend cannot mix a canvas with a WebView. Set by package tango.
var AttachMenu func(app any, key any, m any, apply func(items []platform.MenuItem, onClick func(id uint32))) error
AttachMenu shows the *menu.Menu m (as any) at a persistent place identified by key: apply receives the converted items and the click router and is called on the main thread now and whenever the menu is updated. A nil m detaches key and calls apply(nil, nil) once. Set by package menu.
var Await func(app any, fn func()) bool
Await runs fn on the main thread of app (a *tango.App) and waits, reporting whether it ran (false after the app has quit). On the main thread it calls fn directly.
var CommitWebPlacement func(surface any, ev platform.EmbeddedWebView, placement platform.WebPlacement)
CommitWebPlacement applies the native placement and records its revision for page operations. Main thread only. Set by package tango.
var DetachMenu func(key any)
DetachMenu forgets key without calling its apply function. Set by package menu.
var Done func(app any) <-chan struct{}
Done returns a channel closed once app (a *tango.App) has quit.
var EmbeddedParent func(surface any) any
EmbeddedParent returns the *tango.Surface (as any) an embedded WebView surface lives in, or nil when surface is a window. Set by package tango.
var FinishRunnerStartup func(runner, thread, renderer any)
FinishRunnerStartup finalizes uihost's one-time ownership handoff on main, before any frame or application task can run. ui installs this hook.
var FollowUILocale func(last, next any) bool
FollowUILocale installs next if the current default is last or next. Both arguments are *ui.Locale. A nil last permits the first update. Set by package ui.
var Guard func(app any, where string, fn func()) bool
Guard runs fn, recovering a panic in it and handing it to app's panic handling (a *tango.App: Options.OnPanic or the default, see docs/panics.md) as a tango.Panic with the given Where. It reports whether fn returned normally. With a nil app fn runs unguarded (a panic propagates to the caller). Packages that call application code from callbacks the core does not route (uihost frames, ...) wrap them with it. Set by package tango.
var GuardNonFatal func(app any, where string, fn func()) bool
GuardNonFatal reports a callback panic to the app and lets its caller continue. It returns false when the callback panicked.
var HandleInternal func(app any, channel string, fn func(surface any, payload string))
HandleInternal registers fn for internal messages on channel of app (a *tango.App). fn runs on the main thread with the sending *tango.Surface (as any) and the payload. Registering a channel again replaces fn. Set by package tango.
var HostProxyWebView func(parent any, opts platform.SurfaceOptions, web platform.WebOptions, events ProxyWebViewEvents) (platform.EmbeddedWebView, error)
HostProxyWebView opens the native side of a dev worker's embedded view. The bridge and asset callbacks belong to the worker's surface.
var IsMain func(app any) bool
IsMain reports whether the caller is on the app's main thread.
var IsOverlaySurface func(surface any) bool
IsOverlaySurface reports whether surface (a *tango.Surface) is an overlay.
var NewCanvasSurface func(app any, opts any, sink platform.CanvasSink) (surface any, canvas platform.Canvas, err error)
NewCanvasSurface creates a surface whose content is a platform.Canvas (see docs/specs/canvas-surface.md). app is a *tango.App, opts a tango.SurfaceOptions (URL and Debug are ignored); surface is the new *tango.Surface. The surface is an ordinary one — closing, events, appearance and OnClose/OnClosed work as for NewSurface — and sink receives the canvas callbacks on the main thread. It must be called on the main thread. It returns an error wrapping platform.ErrUnsupported when the backend cannot create canvas surfaces. Set by package tango.
var NewEmbeddedNativeView func(parent any, view uintptr, opts platform.NativeViewOptions, closed func()) (platform.EmbeddedNativeView, error)
NewEmbeddedNativeView embeds the application's native view (NSView*, HWND, GtkWidget*) in the content area of the canvas surface parent (a *tango.Surface), see platform.NativeViewEmbedder. closed runs on the main thread if the backend removes the view because parent closed. Main thread only. It returns an error wrapping platform.ErrUnsupported when the backend or parent cannot host native views. Set by package tango.
var NewEmbeddedWebView func(parent any, canvas platform.Canvas, opts any, script string) (surface any, ev platform.EmbeddedWebView, err error)
NewEmbeddedWebView creates a WebView embedded in the content area of the canvas surface parent (a *tango.Surface), see docs/specs/webview-embed.md. opts is a tango.SurfaceOptions: URL, Debug and WebView apply, window fields are ignored. script is appended to the bridge scripts of the new page. The new *tango.Surface is an ordinary WebView surface for Navigate, Eval, Send, OnMessage, OnLoaded, the WebView extensions and OnClosed; ev places it. It is closed with its parent. Main thread only. It returns an error wrapping platform.ErrUnsupported when the backend cannot embed WebViews. Set by package tango.
var NewProxySurface func(app any, opts any, create func(id platform.SurfaceID, ev ProxyEvents) (platform.Surface, error)) (surface any, err error)
NewProxySurface creates a *tango.Surface (returned as any) for app (a *tango.App) with opts (a tango.SurfaceOptions; only the window state the core records is used) whose native surface is the one create returns. create gets the new surface's id and its event sink. Main thread. Set by package tango in builds with tango_dev.
var NoteSurfaceActivity func(surface any, at time.Time)
NoteSurfaceActivity records input observed by the canvas or dev host.
var OnPrepareSurface func(app any, fn func(p *SurfacePlacement))
OnPrepareSurface registers fn to adjust the placement of every surface (WebView or canvas) app (a *tango.App) is about to create, before the native surface exists. fn runs on the main thread.
var OnQuit func(app any, fn func())
OnQuit registers a nonblocking stop notification on app (*tango.App). Main thread only, both to register and to call. Notifications run in order after Backend.Run and its Terminating event, after closing the main queue but before releasing its waiters. Use AfterUIThread for any wait.
var OnQuitStart func(app any, fn func())
OnQuitStart registers a nonblocking stop request for window work on main. It runs when quit is committed, before backend cancellation can resume an Await. A registration made during quit runs immediately.
var OnSurfaceCreated func(app any, fn func(surface any))
OnSurfaceCreated registers fn to run on the main thread each time app (a *tango.App) has created a surface (WebView or canvas); fn receives the *tango.Surface as any. It is App.OnSurfaceCreated for code that only holds the app as any (tan dev's host, which wires windowstate into apps it hot-reloads). Set by package tango.
ReportPanic reports a panic another package already recovered (ipc bindings, sys/background tasks) to the app owning conn, when conn is a *tango.Surface, or to conn itself when it is a *tango.App. It only reports: a fatal decision (keepRunning false) does not end the process. It returns false when conn belongs to no app. Set by package tango.
var ReturnRunnerToMain func(runner any)
ReturnRunnerToMain undoes FinishRunnerStartup when uihost hands a running window back to the main thread: the runner (any) drops its thread binding, so Post goes through the window's UIPoster again, and draws with a new CPU renderer. Called on the runner's UI thread, outside Frame, before that thread stops. ui installs this hook.
var StartWindowMove func(surface any)
StartWindowMove hands the primary-button press in progress on surface (a *tango.Surface) to the window manager as a window move, where the platform's surface supports it (platform.Dragger). Set by package tango; package uihost calls it for the drag areas of a self-drawn title bar.
var SurfaceClosed func(surface any) bool
SurfaceClosed reports whether surface (a *tango.Surface) has closed.
var SurfaceLoaded func(surface any) bool
SurfaceLoaded reports whether the page of surface (a *tango.Surface) has finished loading. Main thread.
var SurfaceOf func(app any, id platform.SurfaceID) any
SurfaceOf returns the surface with id of app (a *tango.App) as a *tango.Surface, or nil if there is none.
var SurfaceWebKey func(surface any, key input.Key, mods input.Modifiers, done func(error))
SurfaceWebKey dispatches a parsed chord to the native WebView on the main thread.
var Surfaces func(app any) []any
Surfaces returns the open surfaces of app (a *tango.App) in creation order, each a *tango.Surface (App.Surfaces).
var WatchAppearance func(surface any, fn func())
WatchAppearance registers fn for SetAppearance on surface (a *tango.Surface). Registration and notifications run on the main thread.
var WatchSurfaceActivity func(surface any, fn func(time.Time))
WatchSurfaceActivity sets the dev host relay on its top-level surface.
Functions ¶
This section is empty.
Types ¶
type ProxyEvents ¶
type ProxyEvents interface {
// Event delivers a surface event (SurfaceClosed after Close, focus,
// geometry, state).
Event(ev platform.SurfaceEvent)
// ShouldClose asks the surface's OnClose handlers.
ShouldClose() bool
}
ProxyEvents feeds a proxy surface's events to the core, as a backend does through platform.Host. Main thread.
type ProxyWebViewEvents ¶
type ProxyWebViewEvents struct {
Event func(platform.SurfaceEvent)
Message func(origin, msg string)
Asset func(http.ResponseWriter, *http.Request)
}
ProxyWebViewEvents relays the backend callbacks of a dev host WebView.
type ProxyWebViewParent ¶
type ProxyWebViewParent interface {
NewProxyWebView(platform.SurfaceID, platform.SurfaceOptions, platform.WebOptions, ProxyWebViewEvents) (platform.EmbeddedWebView, error)
}
ProxyWebViewParent is the native part of a canvas surface in a dev worker.
type SurfacePlacement ¶
type SurfacePlacement struct {
Title string
X, Y, Width, Height int
Centered bool
State platform.WindowState
}
SurfacePlacement is the part of a tango.SurfaceOptions OnPrepareSurface handlers see. Changes to X, Y, Width, Height, Centered and State go into the options of the surface being created; Title is read only.