Documentation
¶
Overview ¶
Package chromium launches the app window: lich's own Chromium (CEF, built out of shell/), pointed at the loopback listener that serves the frontend and the RPC/terminal transports (docs/chromium-shell.md).
Index ¶
- Constants
- Variables
- func Args(url, dataDir, class string, extra []string) []string
- func Focus(url, dataDir, class string) error
- func ParseFlags(args []string) (pinned string, noWindow bool, extra []string)
- func RelaunchArgs(extra []string) []string
- func Run(url, dataDir, class string, extra []string, onStart func(close func() error)) error
- func Why(err error) string
- type Ending
- type Env
- type ExitError
- type Result
Constants ¶
const NoWindowArg = "--no-window"
NoWindowArg starts lich without its window.
const OverrideEnv = "LICH_SHELL"
OverrideEnv pins the window to launch, by path. The --shell flag is carried in it rather than passed down as an argument, so the restart successor inherits the choice and `lich doctor` reports the window a launch here would actually open. `task dev` is the one caller: `go run` has no window beside its binary.
const TabFallback = false
TabFallback is macOS's alone (fallback_darwin.go): here a missing or dying window is the error the user sees.
Variables ¶
var ErrNoShell = errors.New(
"no window beside the lich binary: lich-shell is missing. Every release is a complete package, " +
"the binary and its shell folder together; install one from " +
"https://github.com/lichdotdev/lich/releases/latest, or point LICH_SHELL at a window build")
ErrNoShell is an install with no window of its own: nothing at shellPaths and no pin. It is a sentinel because the caller answers it differently from every other failure: on macOS lich still runs, in a plain tab of the default browser (main.go's openTab), while everywhere else it is the error the user has to see: a package missing its window, or a binary copied out of the package it shipped in.
Functions ¶
func Args ¶
Args builds the window's argv; shell/src/main.rs is the other side of the contract. The dedicated user-data-dir is load-bearing: the profile holds the frontend's localStorage (lich.* settings), so it must persist across runs. class is the WM_CLASS: the dev shell passes its own so compositor window rules targeting the daily driver never capture the dev window.
func Focus ¶
Focus hands url to the window a running lich has open and waits for the hand-off to end. The process is a second instance that Chromium's profile lock forwards to the first, and its exit is not a window failing to open — CEF reports the forward as a failed initialise, so the duplicate exits 1 by design.
func ParseFlags ¶
ParseFlags splits lich's own launch arguments: --shell <path> pins the window to open, --no-window starts the backend without one (`lich native` uses it), and everything after `--` passes through to the window as Chromium switches. The --shell flag wins over its environment variable because the caller writes it into the environment (main.go), which is also what carries it to the restart successor.
func RelaunchArgs ¶
RelaunchArgs are the arguments that launch lich again with the window switches extra came from: ParseFlags' inverse for them, nil for none. The --shell pin is not among them; it rides the environment (main.go).
func Run ¶
Run opens the window and blocks until it closes. The backend outlives it: the caller decides what the end means (EndingOf). ErrNoShell comes back untouched, because the answer to an install with no window is not this function's to give. Extra args pass through to Chromium (e.g. --ozone-platform=wayland). onStart, when non-nil, receives a func that closes the window once it is launched, before the blocking wait: lich's own close, for quitting and restarting, which the page is not asked about (a close the user makes is).
Types ¶
type Ending ¶
type Ending int
Ending is what a window that has ended means for the lich behind it. The backend outlives its window, so most endings leave it serving; only a launch that never put a window on screen has nobody to serve.
const ( // WindowClosed: the user closed it. The sessions keep running and the next // launch of lich opens a window on them. WindowClosed Ending = iota // WindowTabInstead: macOS's last rung (TabFallback). There is no window of // lich's own here, so the page opens in the default browser. WindowTabInstead // WindowFailed: the window died with an error, after this lich already had // one on screen or after its startup. Report it and keep serving: the // sessions behind it are alive and the next launch opens a window on them. WindowFailed // WindowNeverOpened: this launch's first window failed to come up. Report it // and exit, as a launch that shows nothing must not leave a lich nobody can // see holding the port. WindowNeverOpened )
type Env ¶
type Env struct {
LookPath func(name string) (string, error)
Getenv func(key string) string
// Shell is the path of the window this install bundles, "" when it has
// none (shell.go).
Shell func() string
}
Env is everything resolution reads from the machine. Every probe is a field so the ladder is table-testable on a machine with no window built.
type ExitError ¶
ExitError is the window exiting with an error, with the end of what it wrote to stderr: a launcher start has no terminal, so without it the log holds the signal the window died of and never the reason.
type Result ¶
type Result struct {
// Path is the executable to run.
Path string
// Step names the rung that answered, for `lich doctor` and `lich rage`.
Step string
}
Result is a resolved launch: which executable, and which rung named it.
func Resolve ¶
Resolve finds the window: the one the user pinned, else the one lich itself bundles. It returns ErrNoShell when the install has neither — see that variable for what the caller makes of it.
func (Result) Describe ¶
Describe is the resolution as a diagnostic prints it: the command, and the rung that produced it.
func (Result) ProfileDir ¶
ProfileDir is where this window's profile goes, given the directory lich would use: one keyed subdirectory per window. A Chromium profile is a particular build's own state, so handing one build's to another is a silent adoption at best, and at worst a window that refuses to start on a profile a newer one wrote.