Documentation
¶
Overview ¶
Package core is the application's root package: it defines the module system that wires optional features into the GUI, plus the cross-cutting helpers those features share (application identity, path redaction, the file-browser privacy prompt). It depends only on Fyne and the standard library, so any feature subpackage can import it without creating a cycle back into package main.
A feature is a Module: a plain struct bundling the tabs, settings sections, start handlers, and background-activity checks it used to register through separate calls. A feature registers itself once, from an init function, via Register. Whether a feature is present at all is still a compile-time decision (Go build tags on the file that imports the feature's package), so there is no runtime feature flag here — an absent module simply never runs its init.
Index ¶
- Constants
- Variables
- func BuildSettingsSections(w fyne.Window) fyne.CanvasObject
- func BuildTabs(w fyne.Window) []*container.TabItem
- func DisplayPath(p string) string
- func HasBackgroundActivity() bool
- func MarkAutoUpdaterActive()
- func MarkUpdateInstalled()
- func OpenFilePicker(w fyne.Window, open func())
- func OpenFolder(dir string)
- func PathExposureWarningEnabled() bool
- func RedactHome(s string) string
- func Register(m Module)
- func RegisterActivityCheck(f func() bool)
- func RequestRestart()
- func RestartRequested() bool
- func RunStart(ctx StartContext)
- func RunStop(ctx StopContext)
- func SetPathExposureWarning(on bool)
- func ShowError(err error, win fyne.Window)
- func ShowFileOpen(w fyne.Window, exts []string, dir string, onPick func(rc fyne.URIReadCloser))
- func ShowFileSave(w fyne.Window, exts []string, dir, defaultName string, ...)
- func UpdateInstalled() bool
- func WriteFileAtomic(path, content string) error
- type Module
- type SaveStatus
- type Saver
- type SettingsSection
- type StartContext
- type StartHandler
- type StopContext
- type StopHandler
- type Tab
- type Write
Constants ¶
const AppID = "capystreama"
AppID is the Fyne application ID, also used to scope the log and cache directories. Feature subpackages use it to name their own state under the per-user cache/config dirs.
Variables ¶
var Version = "dev"
Version is the running build's release version, mirrored here from the main package at startup so feature subpackages (notably the updater) can read it without importing package main. The value originates in main.version, which the mage Build target injects under `moneta release` (-X .../src.version=...); local `go build` binaries keep the "dev" default, which the updater treats as older than every published release.
Functions ¶
func BuildSettingsSections ¶
func BuildSettingsSections(w fyne.Window) fyne.CanvasObject
BuildSettingsSections renders every registered section, sorted by Order then Title, into the Settings tab body. Sections after the first are separated by a rule, and any section with a Title gets a bold heading above it. Call once on the UI goroutine at startup; it is the Settings tab's Render.
func BuildTabs ¶
BuildTabs renders every registered tab, sorted by Order then Title, into the TabItems that make up the window's tab bar. Call once on the UI goroutine at startup.
func DisplayPath ¶
DisplayPath returns the final path element for showing in the GUI. Full paths contain the OS home directory (and thus the user's account name), which would leak to viewers when the streamer shares their screen; the basename is enough to identify the file or folder, and Open buttons still act on the full path.
func HasBackgroundActivity ¶
func HasBackgroundActivity() bool
HasBackgroundActivity reports whether any registered check is currently active. The main package's window-close handler uses it to decide between hiding to the system tray (work still running) and quitting.
func MarkAutoUpdaterActive ¶
func MarkAutoUpdaterActive()
MarkAutoUpdaterActive records that a self-updater is wired into this build. Call once from the updater's init; it must run before the Settings tab is rendered, which it does since both happen before the window is assembled.
func MarkUpdateInstalled ¶ added in v0.4.13
func MarkUpdateInstalled()
MarkUpdateInstalled records that the executable on disk is now newer than the running process. From then on a second launch restarts this instance into the new binary instead of just raising its window.
func OpenFilePicker ¶
OpenFilePicker warns that the file browser reveals full folder paths — which include the OS account name in the home directory — and then runs open to present the picker. Unlike the labels we redact elsewhere, the browser is the OS/Fyne dialog we can't fully sanitize, so we give the user a heads-up in case they're sharing a screen. The warning carries a "Don't show again" checkbox and is skipped entirely once the user has opted out (via the checkbox or the Settings tab), in which case open runs immediately.
func OpenFolder ¶
func OpenFolder(dir string)
OpenFolder hands dir to the OS's standard file-manager handler (Finder/Explorer/xdg-open) via a well-formed file:// URI, so there is no per-platform code here. Errors are logged, not surfaced.
func PathExposureWarningEnabled ¶
func PathExposureWarningEnabled() bool
PathExposureWarningEnabled reports whether the file-browser warning should be shown, defaulting to true when unset.
func RedactHome ¶
RedactHome replaces occurrences of the user's home directory with "~" so that free-form text (e.g. streamed build output) doesn't leak the OS account name to viewers when the streamer shares their screen. Unlike DisplayPath it keeps the rest of each path intact, so log lines stay readable. If the home directory can't be resolved, the text is returned unchanged.
func Register ¶
func Register(m Module)
Register adds every contribution in m to the registries. Call it once from a feature's init function.
func RegisterActivityCheck ¶
func RegisterActivityCheck(f func() bool)
RegisterActivityCheck adds a single background-activity predicate to the registry. Unlike the other contributions, an activity check is sometimes only knowable while a tab renders (e.g. the overlay server, created inside the Item List tab), so this may be called from a tab's Render — still on the UI goroutine, before the window's close handler can fire — rather than from init.
func RequestRestart ¶ added in v0.4.13
func RequestRestart()
RequestRestart quits the app outright, bypassing hide-to-tray, and asks the main package to relaunch the executable once it has shut down. Safe to call from any goroutine.
func RestartRequested ¶ added in v0.4.13
func RestartRequested() bool
RestartRequested reports whether RequestRestart has been called.
func RunStart ¶
func RunStart(ctx StartContext)
RunStart invokes every registered start handler with ctx, in registration order. Call once on the UI goroutine after the window is assembled and before ShowAndRun.
func RunStop ¶
func RunStop(ctx StopContext)
RunStop invokes every registered stop handler with ctx, in registration order. Wire it to Fyne's App.Lifecycle().SetOnStopped so it runs once on every exit path (window close, tray quit, OS signal).
func SetPathExposureWarning ¶
func SetPathExposureWarning(on bool)
SetPathExposureWarning persists whether the file-browser warning should be shown. It is the write side of PathExposureWarningEnabled, used by the Settings toggle.
func ShowError ¶
ShowError displays err in a word-wrapped dialog with a sane minimum width. Prefer it over dialog.ShowError, whose width can collapse on long messages.
func ShowFileOpen ¶
ShowFileOpen presents a file picker filtered to exts (e.g. ".txt"), after running the path-exposure warning that precedes every file browser here (see OpenFilePicker). onPick receives the opened reader — never nil — and owns closing it; a cancelled dialog is ignored and a picker error is reported. A non-empty dir starts the dialog there (see setDialogDir).
func ShowFileSave ¶ added in v0.4.14
func ShowFileSave(w fyne.Window, exts []string, dir, defaultName string, onPick func(wc fyne.URIWriteCloser))
ShowFileSave presents a save-file picker filtered to exts and pre-filled with defaultName, after the same path-exposure warning as ShowFileOpen. Fyne's dialog confirms before overwriting an existing file. onPick receives the writer — never nil — and owns closing it; a cancelled dialog is ignored and a picker error is reported. A non-empty dir starts the dialog there (see setDialogDir).
func UpdateInstalled ¶ added in v0.4.13
func UpdateInstalled() bool
UpdateInstalled reports whether MarkUpdateInstalled has been called.
func WriteFileAtomic ¶
WriteFileAtomic writes content to path atomically (temp file + rename) so a watcher never observes a half-written file. Both the item list and the website editors write files that are being watched, so the atomic write lives here.
Types ¶
type Module ¶
type Module struct {
// Tabs are the top-level tabs the feature adds to the window's tab bar.
Tabs []Tab
// SettingsSections are the blocks the feature adds to the Settings tab.
SettingsSections []SettingsSection
// StartHandlers are startup jobs run once the window is assembled.
StartHandlers []StartHandler
// StopHandlers are shutdown jobs run once as the application is shutting down.
StopHandlers []StopHandler
// ActivityChecks report whether the feature has background work that should
// keep the app alive (hidden to the tray) after the window is closed. Use this
// for checks knowable at registration time; features whose state is created
// while rendering a tab can instead call RegisterActivityCheck later.
ActivityChecks []func() bool
}
Module bundles everything a feature contributes to the application. Every field is optional; a feature sets only what it provides. Register fans the contents out into the process-wide registries that the main package consumes at startup.
type SaveStatus ¶
type SaveStatus struct {
// contains filtered or unexported fields
}
SaveStatus is a small status line reporting the outcome of autosaving: idle, saving, saved, unsaved (edits present but not written — e.g. currently invalid), or failed. A single shared instance (SharedSaveStatus) is rendered in the window footer and driven by every tab's Saver. It hides itself once a "Saved" state has lingered (see savedLinger) and re-shows on the next activity; Unsaved/Failed stay visible since they want attention. All methods must be called on the UI goroutine.
func SharedSaveStatus ¶
func SharedSaveStatus() *SaveStatus
SharedSaveStatus returns the process-wide save status rendered in the footer, creating it on first call. Tabs pass it to NewSaver so their autosaves report to the footer; the main package places SharedSaveStatus().Widget() there. Call on the UI goroutine.
func (*SaveStatus) Failed ¶
func (s *SaveStatus) Failed(err error)
Failed shows that a write attempt errored.
func (*SaveStatus) Idle ¶
func (s *SaveStatus) Idle()
Idle clears the status to blank (no pending or reported state).
func (*SaveStatus) Saved ¶
func (s *SaveStatus) Saved()
Saved shows that the latest edits are written, then blanks the status after it has lingered (savedLinger) with no further activity. It clears the icon and text rather than hiding the bar, so the footer keeps the space it occupies and the layout doesn't shift when the status comes and goes.
func (*SaveStatus) Unsaved ¶
func (s *SaveStatus) Unsaved(reason string)
Unsaved shows that edits exist but were not written, with a human reason (typically a validation message). Use it for a recoverable, expected state like a half-typed value, not a write failure.
func (*SaveStatus) Widget ¶
func (s *SaveStatus) Widget() fyne.CanvasObject
Widget returns the status line for placement in a layout.
type Saver ¶
type Saver struct {
// contains filtered or unexported fields
}
Saver throttles and performs autosave writes for one tab, driving the shared app-level SaveStatus (shown in the footer) through the Saving→Saved/Failed lifecycle. It coalesces a burst of Save calls into a single flush, skips paths whose content is unchanged since it last wrote them, and runs the writes off the UI goroutine. Create one per tab with NewSaver.
func NewSaver ¶
func NewSaver() *Saver
NewSaver returns a Saver that reports through the shared app-level SaveStatus.
func (*Saver) Save ¶
Save records the desired file states and schedules a debounced flush. writes is the full set of files this save touches (later calls replace the pending set, since each reflects a complete current snapshot). after, if non-nil, runs on the UI goroutine after a successful flush — use it for non-file side effects such as pushing to a live preview. Call on the UI goroutine.
type SettingsSection ¶
type SettingsSection struct {
// Title is the bold heading shown above the section. Empty means no heading,
// used by the leading "general" section whose controls need no label.
Title string
// Order is the sort index: lower numbers appear first. Ties break on Title.
Order int
// Render builds the section's body (without its heading or separator, which
// BuildSettingsSections supplies). Called once on the UI goroutine while the
// window is assembled.
Render func(w fyne.Window) fyne.CanvasObject
}
SettingsSection is a single block of controls contributed to the Settings tab by a module. BuildSettingsSections assembles the registered sections into the tab body, sorted by Order.
type StartContext ¶
type StartContext struct {
// Window is the main application window.
Window fyne.Window
// Prefs is the application's preference store.
Prefs fyne.Preferences
// TopBar is a vertical container pinned above the tab bar. Handlers may add
// notification widgets to it (e.g. the update banner); anything hidden takes
// no vertical space, so an empty TopBar is invisible.
TopBar *fyne.Container
// app-level status (e.g. the shared save status). Empty and thus invisible
// unless a handler populates it.
Footer *fyne.Container
}
StartContext carries the shared references a start handler needs. It is passed to every registered handler once the window is assembled but before it is shown.
type StartHandler ¶
type StartHandler func(StartContext)
StartHandler is a piece of startup work contributed by a module: background checks, banners, or anything else that needs the assembled window. RunStart invokes every registered handler at launch.
type StopContext ¶
type StopContext struct {
// Window is the main application window.
Window fyne.Window
// Prefs is the application's preference store.
Prefs fyne.Preferences
}
StopContext carries the shared references a stop handler needs. It is passed to every registered handler once, as the application is shutting down.
type StopHandler ¶
type StopHandler func(StopContext)
StopHandler is a piece of shutdown work contributed by a module: flushing state, closing servers, or anything else that must run before the process exits. RunStop invokes every registered handler at shutdown.
type Tab ¶
type Tab struct {
// Title is the label shown on the tab.
Title string
// Order is the sort index: lower numbers appear first. Ties break on Title.
Order int
// Render builds the tab's content. Called once on the UI goroutine while the
// window is assembled.
Render func(w fyne.Window) fyne.CanvasObject
}
Tab is a single top-level tab contributed by a module. BuildTabs assembles the registered tabs into the window's tab bar, sorted by Order.
type Write ¶
type Write struct {
// Path is the file to write or remove.
Path string
// Content is written to Path when Remove is false.
Content string
// Remove deletes Path (ignoring a missing file) instead of writing it, so a
// now-empty section leaves no stale file behind.
Remove bool
}
Write is one file's desired state within a save: its content, or its absence.