Documentation
¶
Overview ¶
Package window decides when and where the cockpit's native window and its omnibox panel show; a Host draws them.
Index ¶
Constants ¶
const MalformedLinkRoute = "link=malformed"
MalformedLinkRoute is the route a link that cannot be read opens: the default view, which the cockpit tells about the link.
const PanelRoute = "panel=omnibox"
PanelRoute is the cockpit route the panel loads.
Variables ¶
This section is empty.
Functions ¶
func InsetTitleBar ¶
InsetTitleBar marks a cockpit URL for a window whose title bar the page draws, around the window controls.
func LinkRoute ¶
LinkRoute is the cockpit route of a deep link, <scheme>://open/#<route>; ok is false for anything else. The route is kept as written, still escaped.
func Navigation ¶
Navigation is how a host moves a webview from current to next: load the page when anything before the fragment differs (another daemon port or token), or only set its hash; an empty hash on the same page keeps the place.
Types ¶
type Config ¶
type Config struct {
Host Host
Daemon Events
CockpitURL func(route string) (string, error)
Hotkey string
Log func(format string, args ...any)
// After is time.After unless a test supplies its own.
After func(time.Duration) <-chan time.Time
}
Config is what a Controller needs.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller keeps one main window and one panel.
func (*Controller) OpenLink ¶
func (c *Controller) OpenLink(link string)
OpenLink shows a deep link's route in the main window; a link it cannot read shows the default view, which says so.
func (*Controller) Run ¶
func (c *Controller) Run(ctx context.Context) error
Run binds the host's handlers, then follows the window requests the daemon relays until ctx ends, subscribing again whenever the daemon goes away; it returns once the stream it follows has closed.
func (*Controller) Show ¶
func (c *Controller) Show(route string) error
Show shows the main window at route ("" keeps where it was) and hides the panel; a panel route shows the panel instead, since the panel's page in the main window would hand every other route back to it.
func (*Controller) TogglePanel ¶
func (c *Controller) TogglePanel()
TogglePanel shows the panel, or hides it when it shows.
type Events ¶
type Events interface {
Events(ctx context.Context, client string, since api.Since) (<-chan api.Change, error)
}
Events is the daemon's events stream.
type Handlers ¶
type Handlers struct {
// Hotkey is an accelerator such as "ctrl+option+space"; "" binds none.
Hotkey string
OnHotkey func()
// OnReopen runs when the Dock icon is clicked or the bundle is opened
// again while running.
OnReopen func()
// OnPanelHidden runs when the host hid the panel on its own, as on
// focus loss.
OnPanelHidden func()
// OnOpenURL runs for each deep link the system hands the app.
OnOpenURL func(link string)
}
Handlers are what a host calls back.
type Host ¶
type Host interface {
// ShowMain shows, focuses and brings the app forward, in the Dock and
// ⌘Tab while shown.
ShowMain(url string)
// ShowPanel shows the panel without activating the app.
ShowPanel(url string)
HidePanel()
// ShowDetached shows and focuses the secondary window id, opening it at
// url when none is open; it closes for good and is not restored at
// relaunch.
ShowDetached(id, url string)
// OpenExternal opens url, a web address, in the default browser.
OpenExternal(url string)
// Listen binds the hotkey, the reopen and opened links; an error leaves
// the reopen and the links bound.
Listen(h Handlers) error
}
Host shows the cockpit natively. Every method returns at once; the host runs AppKit work on the main thread.