Documentation
¶
Overview ¶
Package shell bootstraps the native desktop on MyGo: the application, the main window with native decorations, and the application menu. It owns the MyGo event loop, which must run on the main goroutine (cobra's RunE does, and MyGo's init keeps the main goroutine on the main OS thread).
Platform integration that comes later (P1: tray, notifications, Dock reopen, close/minimise to tray, single instance) belongs here too.
Index ¶
- Variables
- func AcquireSingleInstance(key string) bool
- func CustomFrame() bool
- func DefaultMenu(extra []*mygo.MenuItem) *mygo.Menu
- func Run(o Options) error
- type Controller
- func (c *Controller) CloseWindow()
- func (c *Controller) Focused() bool
- func (c *Controller) IsMaximized() bool
- func (c *Controller) Minimize()
- func (c *Controller) Notify(id, title, body string)
- func (c *Controller) Quit()
- func (c *Controller) Quitting() bool
- func (c *Controller) SetTitle(title string)
- func (c *Controller) SetTrayLabels(l TrayLabels)
- func (c *Controller) SetTrayOnClose(on bool)
- func (c *Controller) SetTrayProjects(p []TrayProject)
- func (c *Controller) Show()
- func (c *Controller) ToggleFullScreen()
- func (c *Controller) ToggleMaximize()
- func (c *Controller) TrayAvailable() bool
- func (c *Controller) UseTray() bool
- func (c *Controller) Window() *mygo.Window
- type Options
- type TrayLabels
- type TrayOptions
- type TrayProject
Constants ¶
This section is empty.
Variables ¶
var ErrNoDisplay = errors.New("no display available for the native desktop window")
ErrNoDisplay is returned by Run when no display server is reachable (an SSH session, WSL without WSLg, a headless CI): callers can suggest the browser UI instead.
Functions ¶
func AcquireSingleInstance ¶
AcquireSingleInstance makes sure one native desktop runs per key (the working directory): it returns false, after handing the command line to the running instance (which focuses its window), when another one owns the key. Different keys do not collide, so `pando desktop --cwd other` (how a project opens its own window) still starts. Call it before any server starts. PANDO_DESKTOP_MULTI=1 disables the lock (tests, several agents on one machine).
func CustomFrame ¶
func CustomFrame() bool
CustomFrame reports whether the window has no native title bar or menu bar and the UI draws its own title bar with minimise, maximise and close buttons: Linux and Windows. macOS keeps the native title bar (traffic lights) and menu bar.
func DefaultMenu ¶
DefaultMenu is the application menu: the app menu (macOS), File with the extra items, the Edit role menu (copy and paste keys need it on macOS), View and Window.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is the handle on the window, tray and notifications that services use. Methods are safe from any goroutine.
func (*Controller) CloseWindow ¶
func (c *Controller) CloseWindow()
CloseWindow is the custom title bar's close button. It closes the window as the native button would: the OnClose listener hides it into the tray when UseTray, otherwise the window closes and, being the last, quits the app.
func (*Controller) Focused ¶
func (c *Controller) Focused() bool
Focused reports whether the main window has the keyboard focus.
func (*Controller) IsMaximized ¶
func (c *Controller) IsMaximized() bool
IsMaximized reports whether the window is maximised.
func (*Controller) Minimize ¶
func (c *Controller) Minimize()
Minimize is the custom title bar's minimise button: it hides the window into the tray when Desktop.TrayOnMinimizeClose is on and a tray icon is live (UseTray), otherwise it minimises normally.
func (*Controller) Notify ¶
func (c *Controller) Notify(id, title, body string)
Notify shows an OS notification; clicking it shows the window. A notification with the id of one still shown replaces it. Errors (macOS outside an app bundle, permission denied, no service) are logged.
func (*Controller) Quit ¶
func (c *Controller) Quit()
Quit quits the app, whatever the tray setting.
func (*Controller) Quitting ¶
func (c *Controller) Quitting() bool
Quitting reports whether an explicit quit started.
func (*Controller) SetTitle ¶
func (c *Controller) SetTitle(title string)
SetTitle sets the main window title.
func (*Controller) SetTrayLabels ¶
func (c *Controller) SetTrayLabels(l TrayLabels)
SetTrayLabels replaces the tray menu labels (the UI language changed); empty ones keep the English default.
func (*Controller) SetTrayOnClose ¶
func (c *Controller) SetTrayOnClose(on bool)
SetTrayOnClose mirrors Desktop.TrayOnMinimizeClose: only then, and only with a live tray icon, do minimise and close hide the window.
func (*Controller) SetTrayProjects ¶
func (c *Controller) SetTrayProjects(p []TrayProject)
SetTrayProjects replaces the project workspaces of the tray menu.
func (*Controller) Show ¶
func (c *Controller) Show()
Show brings the main window back (from the tray, minimised or behind others), opening it again if it was closed.
func (*Controller) ToggleFullScreen ¶
func (c *Controller) ToggleFullScreen()
ToggleFullScreen toggles full screen (F11, the View menu role elsewhere).
func (*Controller) ToggleMaximize ¶
func (c *Controller) ToggleMaximize()
ToggleMaximize maximises the window or restores it.
func (*Controller) TrayAvailable ¶
func (c *Controller) TrayAvailable() bool
TrayAvailable reports whether a tray icon is live (it is not without libayatana-appindicator on Linux, or a tray host).
func (*Controller) UseTray ¶
func (c *Controller) UseTray() bool
UseTray reports whether minimise/close currently hide into the tray.
func (*Controller) Window ¶
func (c *Controller) Window() *mygo.Window
Window returns the main window, nil before it exists.
type Options ¶
type Options struct {
// Name is the application name (menu bar, notifications). Default Pando.
Name string
// Title of the main window.
Title string
// Width and Height of the main window in DIPs (default 1280x820).
Width, Height int
// View builds the window's content every frame.
View func(c *ui.Context)
// OnReady runs on the main thread once the app is ready, before the
// first window: wire the controller to services here.
OnReady func(c *Controller)
// OnWindow runs on the main thread once the main window exists: connect
// dispatchers (the window implements Update/Invalidate) here. It runs
// again if the window is recreated.
OnWindow func(w *mygo.Window)
// Menu adds items to the default application menu (see DefaultMenu).
Menu []*mygo.MenuItem
// Tray configures the tray icon; the zero value gives Show, Quit.
Tray TrayOptions
// OnSecondInstance runs when another `pando desktop` for the same
// working directory started and handed over its arguments.
OnSecondInstance func(args []string)
// Ctx, when canceled (SIGINT, server shutdown), quits the app.
Ctx context.Context
}
Options configures Run.
type TrayLabels ¶
type TrayLabels struct {
Show, Settings, Projects, Quit string
}
TrayLabels are the tray menu labels.
type TrayOptions ¶
type TrayOptions struct {
// Labels override the English menu labels.
Labels TrayLabels
// OnSettings runs when "Settings" is chosen (main thread, window shown).
OnSettings func()
// OnProject runs when a project workspace is chosen.
OnProject func(id string)
}
TrayOptions configures the tray icon and menu.
type TrayProject ¶
type TrayProject struct {
ID, Name string
// Current marks the workspace the window shows.
Current bool
}
TrayProject is an open project workspace listed in the tray menu.