Documentation
¶
Overview ¶
Package appwindow opens the user interface in its own window.
A Chromium-based browser in "app mode" gives a chromeless window with no tabs, address bar or bookmarks, which reads as a native application window while keeping the whole program a single dependency-free binary. If no such browser is available the page is opened in the default browser instead.
redirect.go keeps the one-time link WindowURL hands out off the browser's command line, where any other user of the machine could read it and, within its short life, redeem it before the person who started it does (R3.7.2). A small HTML page that redirects to the link is written into a directory only this user can use, and the browser is started at that file instead. The file is named unguessably and removed as soon as it has done its job -- see Window.arm and scheduleCleanup.
Index ¶
Constants ¶
const BrowserEnv = "FLOCKDECK_BROWSER"
BrowserEnv names the browser to use, overriding the search: a path, a program on PATH, or one of browserNames.
Variables ¶
var ErrHandedOff = errors.New("the window was handed to a browser already running")
ErrHandedOff is returned by Wait when the browser gave the window to a process of its own that was already running, and exited. The window is open, but nothing here can tell when it closes.
var ErrNoBrowser = errors.New("no browser found to display the interface")
ErrNoBrowser is returned when nothing could be found to display the UI.
Functions ¶
func OpenDefault ¶ added in v0.3.3
OpenDefault opens target in the user's default browser, as Open does when no app-mode browser will start. The tab it opens cannot be watched, so unlike Open's own use of this fallback there is no Window to remove a redirect file the moment its link stops working -- this relies on that file's own backstop timer alone (see redirectFileLife).
Types ¶
type StartError ¶ added in v0.3.3
type StartError struct {
// Program is the browser that was started, and Code what it exited with.
Program string
Code int
// Stderr is the last few lines the browser printed, which is where it
// says why.
Stderr string
}
StartError is returned by Wait when the browser failed so soon after it was started that its window cannot have opened: on Linux with no display to open it on, say, or a snap-packaged Chromium refused its profile folder.
func (*StartError) Error ¶ added in v0.3.3
func (e *StartError) Error() string
type Window ¶
type Window struct {
// AppMode reports whether the window is a dedicated app window rather than
// a tab in the user's ordinary browser.
AppMode bool
// Program is the browser that was launched, for diagnostics.
Program string
// contains filtered or unexported fields
}
Window is a running UI window.
func Open ¶
Open displays target in a window. profileDir holds the browser profile used for app mode, keeping it separate from the user's own browsing profile so the window opens clean and does not disturb their session.
target is not necessarily what the browser is started at: where a private place could be found for whichever browser this turns out to use, it is wrapped in a local redirect file first (see writeRedirectFile), so that target -- a one-time link, in practice -- never sits on that browser's own command line, for as long as it runs, where any other user of the machine could read it (R3.7.2). The returned Window's RedirectFile names that file, for a caller able to remove it the moment target itself stops working.
func (*Window) Close ¶
func (w *Window) Close()
Close closes an app-mode window.
The browser is asked first, with SIGTERM, which Chromium takes as being told to close: it saves the window's size and place as it goes, which is what the next window opens at (see placementArgs). Killed outright, as it always was, it saved nothing, and could count the run as a crash. Only one that has not gone after closeGrace is killed. A Windows process cannot be sent SIGTERM, so there it is killed, as before.
func (*Window) RedirectFile ¶ added in v0.3.5
RedirectFile is where the one-time link this window was opened at was written into a local redirect file for the browser to read, or "" where none was and the browser was started at the link itself. A caller that can say precisely when that link stops working -- see server.SetLinkFile -- should remove the file itself at that moment, rather than leave it to this package's own backstop timer.
func (*Window) Wait ¶
Wait blocks until an app-mode window is closed. It returns immediately for a tab opened in the default browser, whose lifetime cannot be observed, returns ErrHandedOff for a window another browser process took over, and a *StartError for a browser that failed before its window could have opened.
Such a browser used to come back as its own exit status, which reads the same as the window being closed, and the application stopped with it -- at once, and without a word, since what the browser had said went nowhere.