Documentation
¶
Overview ¶
Package system holds the few OS integrations the frontend needs that are not tied to any domain service — opening a URL in the user's default browser, opening a work-tree file in their editor, raising a desktop notification, and the handful of facts a bug report needs (version, platform, where the log lives).
Index ¶
- Constants
- func OpenURL(rawURL string) error
- func SwitchesToNative(version, lastSwitched string, nativeShipped bool) bool
- func ValidateExternalURL(rawURL string) error
- type AttachNativeOptions
- type CloseWindowOptions
- type Diagnostics
- type NativeHooks
- type OpenWindowOptions
- type QuitOptions
- type Service
- func (s *Service) AttachNative(opts AttachNativeOptions)
- func (s *Service) CloseWindow(CloseWindowOptions) error
- func (s *Service) Diagnostics() Diagnostics
- func (s *Service) Notify(summary, detail string) error
- func (s *Service) OpenExternal(rawURL string) error
- func (s *Service) OpenFile(dir, rel string) error
- func (s *Service) OpenFolder(dir string) error
- func (s *Service) OpenFolderInEditor(dir string) (string, error)
- func (s *Service) OpenInEditor(dir, rel string) (string, error)
- func (s *Service) OpenWindow(opts OpenWindowOptions) error
- func (s *Service) Quit(QuitOptions) error
- func (s *Service) RevealLog() error
- func (s *Service) SSHAgentKeys() []string
- func (s *Service) SandboxBackend() string
- func (s *Service) SetCloseWindow(closeWindow func() error)
- func (s *Service) SetEnv(env []string)
- func (s *Service) SetNativeWindow(hooks NativeHooks)
- func (s *Service) SetQuit(quit func() error)
- func (s *Service) SetShowWindow(show func())
- func (s *Service) SetWindowChoice(chosen func() string)
- func (s *Service) ShowWindow(ShowWindowOptions) error
- func (s *Service) TakeUncleanExit() bool
- func (s *Service) TakeWindowFallback() string
- type ShowWindowOptions
Constants ¶
const ( WindowWeb = "web" WindowNative = "native" WindowKindKey = "window.kind" // NativeReleaseKey is the release that last put lich on the native window. NativeReleaseKey = "window.nativeRelease" )
The windows lich can open, and the setting that picks the one opened when lich is asked for its window.
Variables ¶
This section is empty.
Functions ¶
func OpenURL ¶
OpenURL hands a URL to the desktop's default browser, through the same per-OS launcher OpenExternal uses. It is package-level because the launch path needs it before any service exists: a Mac with no window of its own degrades to a plain tab in whatever browser it does have (main.go). No scheme gate here — the only caller passes lich's own loopback URL, not one a page handed it.
func SwitchesToNative ¶
SwitchesToNative reports whether a launch of version puts lich on the native window, whatever was chosen before: once per release, so every update is tried on it while it is experimental, and a user who switched back keeps the web window until the next one. A dev build never does, nor an install without the native binary, which would only fall back.
func ValidateExternalURL ¶
ValidateExternalURL accepts absolute http/https URLs only.
Types ¶
type AttachNativeOptions ¶
type AttachNativeOptions struct {
// Executable is the native window's own binary, the one started again when
// lich is asked for its window after that window closed.
Executable string `json:"executable"`
}
AttachNativeOptions is the native window announcing itself.
type CloseWindowOptions ¶
type CloseWindowOptions struct{}
CloseWindowOptions is one CloseWindow call, an object for the reason ShowWindowOptions is.
type Diagnostics ¶
type Diagnostics struct {
Version string `json:"version"`
Platform string `json:"platform"`
LogPath string `json:"logPath"`
}
Diagnostics is what a bug report opens with: the three facts that decide whether a report is actionable, and the log path the user attaches.
type NativeHooks ¶
type NativeHooks struct {
// Raise brings an open native window forward, false when none is connected.
Raise func() bool
// Launch starts the native window on this backend; exited hears how the
// process ended once it does.
Launch func(executable string, exited func(state string)) error
// Close asks an open native window to close.
Close func()
// Locate is the native window's binary, shipped beside lich's.
Locate func() (string, error)
}
NativeHooks are how lich drives the native window (`lich native`), wired by main.
type OpenWindowOptions ¶
type OpenWindowOptions struct {
// Kind is WindowWeb or WindowNative.
Kind string `json:"kind"`
}
OpenWindowOptions is one OpenWindow call.
type QuitOptions ¶
type QuitOptions struct{}
QuitOptions is one Quit call, an object for the reason ShowWindowOptions is.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) AttachNative ¶
func (s *Service) AttachNative(opts AttachNativeOptions)
AttachNative makes the native window lich's window until a web window takes its place.
func (*Service) CloseWindow ¶
func (s *Service) CloseWindow(CloseWindowOptions) error
CloseWindow closes lich's window and leaves lich running with its sessions: the page's answer when the user chose to keep it running in the background. The page is not asked again on the way out.
func (*Service) Diagnostics ¶
func (s *Service) Diagnostics() Diagnostics
func (*Service) Notify ¶
Notify raises a desktop notification through the OS's own notification service — the one channel that still reaches the user after they leave the lich window. summary is the headline, detail the second line (empty omits it).
Delivery only: the page decides when a notification is warranted, because it is the side that knows whether the window has focus and which session the user is looking at.
func (*Service) OpenExternal ¶
OpenExternal opens an http(s) URL in the default browser. Scheme-gated so a crafted terminal escape can never turn a click into a file:// or custom scheme launch. The launcher itself is per-OS (see the open_* files).
func (*Service) OpenFile ¶
OpenFile hands one work-tree file to the application the desktop opens its type with: an image viewer, a PDF reader. Unlike OpenInEditor it never consults $VISUAL/$EDITOR, which would open a PNG in vim. rel goes through relpath.Resolve, as project.ReadFile does, so a symlink out of the checkout is refused rather than opened. The launcher is openFolder's: xdg-open, open and explorer each hand any path, file or folder, to its default handler.
func (*Service) OpenFolder ¶
OpenFolder shows a checkout in the platform's file manager. It never consults $VISUAL/$EDITOR: this is the way out of lich to the OS's own view of the folder, which is the one thing opening it in an editor does not give.
func (*Service) OpenFolderInEditor ¶
OpenFolderInEditor opens a session's checkout — the directory itself, not a file under it — exactly the way OpenInEditor opens one of its files, terminal editors included.
func (*Service) OpenInEditor ¶
OpenInEditor decides how to open a work-tree file. rel is validated against traversal (internal/relpath, the same guard project.ReadFile answers to), then joined onto dir. It prefers $VISUAL, then $EDITOR — resolved from the login shell, so a GUI launch still sees rc exports.
When the editor is a terminal editor (vim, nvim, nano, …) it launches nothing and returns the shell command line to run in a lich terminal session: a detached launch would give it no controlling terminal. Otherwise it launches the GUI editor — or, with no editor set, the platform's default opener — detached, and returns "". The caller runs the returned command in a terminal only when it is non-empty.
func (*Service) OpenWindow ¶
func (s *Service) OpenWindow(opts OpenWindowOptions) error
OpenWindow opens the window of opts.Kind, closing the other one, without changing which one WindowKindKey picks: one window at a time, as both endpoints the windows live on take one client. A native window that cannot start leaves the web one open in its place, never no window.
func (*Service) Quit ¶
func (s *Service) Quit(QuitOptions) error
Quit ends lich: the window closes, every session's process ends with it, and the process exits. It returns once the exit is under way, so the reply can be lost to the exit it announces.
func (*Service) RevealLog ¶
RevealLog opens the log's directory with the platform's file manager, not the file itself: the rotated generation (*.old) is often the one holding the bug, and a log file handed to its default handler opens in an editor, not beside the sibling the reporter also needs.
func (*Service) SSHAgentKeys ¶
SSHAgentKeys lists the identities loaded in the user's ssh agent, one line each ("me@example.com (ED25519 256)"), in the order the agent holds them.
It exists for one sentence in the UI. The setting that hands a confined session the ssh agent is read as "let it push with my GitHub key", and what it actually hands over is every identity in the agent, usable against any host — so the control shows the list instead of asking the user to remember it. A choice made without seeing this is a choice about a different thing.
Empty for everything that is not a list of keys: no agent in the environment, no ssh-add on the machine, an agent holding nothing, output this cannot read. The caller draws "nothing loaded", which is the truthful reading of all of them — the flag hands over whatever is there, and nothing is a real answer.
func (*Service) SandboxBackend ¶
SandboxBackend names what confines a session on this machine — "bubblewrap", "sandbox-exec" — or "" when nothing can (internal/sandbox). It answers here rather than beside the provider list because it is a fact about the machine, and the same answer for every provider on it.
The name rather than a yes: the two backends have different holes, and the Sandbox pane says which one is in play so a report about a confined session starts a round ahead. "" is what the pane draws its "cannot confine" state from, and what the new-session dialog reads as "do not offer the choice".
func (*Service) SetCloseWindow ¶
SetCloseWindow wires how lich closes its window and keeps running. Called at startup.
func (*Service) SetEnv ¶
SetEnv replaces the resolved environment after a re-read of the login shell (internal/providers.Service.RefreshPath): an $EDITOR exported by an rc file the user edited while lich was open is found from the same re-check that finds a newly installed agent, rather than from the next launch.
func (*Service) SetNativeWindow ¶
func (s *Service) SetNativeWindow(hooks NativeHooks)
SetNativeWindow wires the native window. Called at startup.
func (*Service) SetShowWindow ¶
func (s *Service) SetShowWindow(show func())
SetShowWindow wires how lich opens its window, or brings the open one to the front. Called at startup.
func (*Service) SetWindowChoice ¶
SetWindowChoice wires how the chosen window is read. Called at startup.
func (*Service) ShowWindow ¶
func (s *Service) ShowWindow(ShowWindowOptions) error
ShowWindow opens the window WindowKindKey picks on the running backend, or brings it forward when it is open (OpenWindow). It returns as soon as the window is asked for, not when it is on screen.
func (*Service) TakeUncleanExit ¶
TakeUncleanExit reports whether the run before this one ended without quitting cleanly, and clears the flag. It is consumed rather than read because the notice belongs to the launch that followed the bad exit, not to every page reload of it: the page mounts its gate again on each reload, the process does not start again with it.
func (*Service) TakeWindowFallback ¶
TakeWindowFallback is why lich opened the web window in place of the native one, "" when it did not; reading it clears it, so a reload does not tell it again.
type ShowWindowOptions ¶
type ShowWindowOptions struct{}
ShowWindowOptions is one ShowWindow call. It carries nothing yet; it is an object so a newer launch can still reach an older running lich the day it does (the CLI's options-object rule).