Documentation
¶
Overview ¶
Package settings stores the user's preferences in the prefs table and serves them to the UI.
Each preference is a typed key with a default, so a fresh database already has a complete set of settings. Setters validate their value before storing it and reject anything unknown with a sentinel error.
Index ¶
- Constants
- Variables
- func IsDark(theme string, systemDark bool) bool
- func Sections() []string
- func Themes() []string
- func ValidTheme(theme string) bool
- type MenuBarNotifier
- type Option
- type Service
- func (s *Service) CollapsedSections(ctx context.Context) ([]string, error)
- func (s *Service) Get(ctx context.Context) (Settings, error)
- func (s *Service) MatchSensitivePath(ctx context.Context, path string) (sensitive.PathMatch, error)
- func (s *Service) MenuBar(ctx context.Context) (bool, error)
- func (s *Service) ResetTrustedBots(ctx context.Context) error
- func (s *Service) SetCloneRoot(ctx context.Context, root string) error
- func (s *Service) SetDefaultProfile(ctx context.Context, name string) error
- func (s *Service) SetMenuBar(ctx context.Context, on bool) error
- func (s *Service) SetNotificationBanner(ctx context.Context, kind string, on bool) error
- func (s *Service) SetSectionCollapsed(ctx context.Context, section string, collapsed bool) error
- func (s *Service) SetSensitiveCategory(ctx context.Context, id string, on bool) error
- func (s *Service) SetSensitivePatterns(ctx context.Context, patterns []string) error
- func (s *Service) SetSensitiveScope(ctx context.Context, scope string) error
- func (s *Service) SetSnoozeDays(ctx context.Context, days int) error
- func (s *Service) SetSnoozeWake(ctx context.Context, rules snooze.Rules) error
- func (s *Service) SetTerminal(ctx context.Context, terminal string) error
- func (s *Service) SetTheme(ctx context.Context, theme string) error
- func (s *Service) SetTrustedBots(ctx context.Context, bots []string) error
- func (s *Service) SetWindowSize(ctx context.Context, size WindowSize) error
- func (s *Service) SetWorktreeAutoCleanup(ctx context.Context, on bool) error
- func (s *Service) SetWorktreeDefault(ctx context.Context, on bool) error
- func (s *Service) Theme(ctx context.Context) (string, error)
- type Settings
- type ThemeNotifier
- type WindowSize
Constants ¶
const ( SectionReviewRequested = "reviewRequested" SectionAuthored = "authored" SectionAssigned = "assigned" )
Inbox sections, named as the inbox snapshot names its lists.
const ( // KeyDefaultProfile names the profile the launch dropdown preselects. KeyDefaultProfile = "profile.default" // KeyWorktreeDefault is whether launches start in a worktree unless unticked. KeyWorktreeDefault = "launch.worktree" // KeyWorktreeAutoCleanup is whether a worktree is cleaned up on its own once its pull // request merges or its issue closes (see the worktrees package for what is checked). KeyWorktreeAutoCleanup = "worktrees.autoCleanup" // KeyTerminal is the terminal app launches open in. KeyTerminal = "launch.terminal" // KeyCloneRoot is the directory whose children are the user's local clones. KeyCloneRoot = "clones.root" // KeyTrustedBots lists the bots whose items are trusted (see the trust package). KeyTrustedBots = trust.PrefBots // KeySnoozeDays is how many days an inbox row's Snooze button hides an item. The // wake rules are stored under the other snooze.* keys (see the snooze package). KeySnoozeDays = snooze.PrefDays )
Preference keys.
const ( // TerminalITerm2 opens launches in a new iTerm2 tab or window. TerminalITerm2 = "iterm2" // TerminalApp opens launches in a new Terminal.app window. TerminalApp = "terminal" )
Terminal choices.
const ( DefaultProfile = profiles.DefaultName DefaultWorktreeDefault = true DefaultAutoCleanup = true DefaultTerminal = TerminalITerm2 DefaultCloneRoot = "~/projects" DefaultSnoozeDays = snooze.DefaultDays )
Defaults for a fresh database.
const ( // ThemeSystem follows the system's light or dark appearance as it changes. ThemeSystem = "system" // ThemeLight always shows the light palette. ThemeLight = "light" // ThemeDark always shows the dark palette. ThemeDark = "dark" // DefaultTheme is the theme of a fresh database. DefaultTheme = ThemeSystem )
Theme choices.
const ( DefaultWindowWidth = 1280 DefaultWindowHeight = 800 MinWindowWidth = 800 MinWindowHeight = 520 MaxWindowWidth = 7680 MaxWindowHeight = 4320 )
Window sizes, in points. A fresh database opens the window at the default size; the minimum is also the smallest the window can be resized to.
const DefaultMenuBar = true
DefaultMenuBar is the menu bar setting of a fresh database.
const KeyMenuBar = "ui.menuBar"
KeyMenuBar is whether the app shows its icon, with how many items need the user, in the menu bar; closing the window then keeps the app running there.
const KeyTheme = "ui.theme"
KeyTheme is the theme the app shows, stored as ThemeSystem, ThemeLight, or ThemeDark.
const KeyWindowSize = "window.size"
KeyWindowSize is the size the window opens at, stored as "<width>x<height>".
Variables ¶
var ( // ErrInvalidTerminal is returned for a terminal that is not one of the choices. ErrInvalidTerminal = errors.New("unknown terminal") // ErrUnknownProfile is returned when the default profile names no stored profile. ErrUnknownProfile = errors.New("unknown profile") // ErrInvalidCloneRoot is returned for a clone root that is not an existing directory. ErrInvalidCloneRoot = errors.New("invalid clone root") )
var ErrInvalidTheme = errors.New("unknown theme")
ErrInvalidTheme is returned for a theme that is not one of the choices.
var ErrInvalidWindowSize = errors.New("invalid window size")
ErrInvalidWindowSize is returned for a window size outside the bounds.
var ErrUnknownSection = errors.New("unknown inbox section")
ErrUnknownSection is returned for a section that is not one of the inbox lists.
Functions ¶
func IsDark ¶
IsDark reports whether a theme shows the dark palette while the system appearance is dark (systemDark) or light. A theme that is not one of the choices counts as DefaultTheme.
func Sections ¶
func Sections() []string
Sections returns the inbox sections in the order the inbox shows them.
func Themes ¶
func Themes() []string
Themes returns the theme choices in the order Settings offers them.
func ValidTheme ¶
ValidTheme reports whether theme is one of the choices.
Types ¶
type MenuBarNotifier ¶
type MenuBarNotifier interface {
MenuBarChanged(on bool)
}
MenuBarNotifier is told when the menu bar setting was changed and stored, so the desktop shell can add or remove its icon.
type Option ¶
type Option func(*Service)
Option configures a Service.
func WithMenuBarNotifier ¶
func WithMenuBarNotifier(n MenuBarNotifier) Option
WithMenuBarNotifier tells n about every change of the menu bar setting once it is stored.
func WithThemeNotifier ¶
func WithThemeNotifier(n ThemeNotifier) Option
WithThemeNotifier tells n about every theme change once it is stored.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service reads and writes the preferences.
func NewService ¶
NewService returns a Service over db. home expands a ~ clone root.
func (*Service) CollapsedSections ¶
CollapsedSections returns the inbox sections the user collapsed, in the order the inbox shows them. None is collapsed on a fresh database, and a stored value that is not a boolean counts as open.
func (*Service) Get ¶
Get returns every preference, with the default for any that is unset or holds a value that is no longer valid.
func (*Service) MatchSensitivePath ¶
MatchSensitivePath reports whether a path would count as sensitive under the stored settings, and which category and pattern it matches, for trying patterns out.
func (*Service) MenuBar ¶
MenuBar returns whether the app shows its menu bar icon: the stored setting, or DefaultMenuBar when none is stored or the stored value cannot be read.
func (*Service) ResetTrustedBots ¶
ResetTrustedBots goes back to the default trusted bots.
func (*Service) SetCloneRoot ¶
SetCloneRoot stores the clone root. It must be an absolute or ~-relative path to an existing directory; it is stored as entered (trimmed and cleaned), so "~/projects" stays portable across machines.
func (*Service) SetDefaultProfile ¶
SetDefaultProfile stores the profile the launch dropdown preselects. It must name a stored profile.
func (*Service) SetMenuBar ¶
SetMenuBar stores whether the app shows its menu bar icon. Once it is stored, the menu bar notifier, if any, is told.
func (*Service) SetNotificationBanner ¶
SetNotificationBanner turns the banners of one kind of notification on or off (see the notify package for the kinds). The notification history keeps every kind either way.
func (*Service) SetSectionCollapsed ¶
SetSectionCollapsed stores whether an inbox section is collapsed, so the inbox opens the same way at the next launch.
func (*Service) SetSensitiveCategory ¶
SetSensitiveCategory turns a built-in category of sensitive files on or off. The agent configuration category cannot be turned off, since launches are held back by it.
func (*Service) SetSensitivePatterns ¶
SetSensitivePatterns stores the user's own patterns of sensitive files, in order. Each is trimmed, empty ones and repeats are dropped, and a pattern that cannot be used is refused with the reason (see the sensitive package for the syntax).
func (*Service) SetSensitiveScope ¶
SetSensitiveScope stores whose pull requests have their changed files checked: sensitive.ScopeOutside, or sensitive.ScopeCollaborators to check collaborators' too.
func (*Service) SetSnoozeDays ¶
SetSnoozeDays stores how many days the Snooze button hides an item: snooze.MinDays to snooze.MaxDays.
func (*Service) SetSnoozeWake ¶
SetSnoozeWake stores which new activity ends a snooze early. Every rule is stored together, so the rules never mix two saves.
func (*Service) SetTerminal ¶
SetTerminal stores the terminal launches open in: "iterm2" or "terminal".
func (*Service) SetTheme ¶
SetTheme stores the theme the app shows: ThemeSystem, ThemeLight, or ThemeDark. Once it is stored, the theme notifier, if any, is told.
func (*Service) SetTrustedBots ¶
SetTrustedBots stores the bots whose items are trusted. Each login may be written as GitHub shows it ("dependabot", "dependabot[bot]", or "app/dependabot"); the list is stored normalized and sorted, and may be empty to trust no bot.
func (*Service) SetWindowSize ¶
func (s *Service) SetWindowSize(ctx context.Context, size WindowSize) error
SetWindowSize stores the size the window opens at, which takes effect at the next launch: MinWindowWidth by MinWindowHeight up to MaxWindowWidth by MaxWindowHeight.
func (*Service) SetWorktreeAutoCleanup ¶
SetWorktreeAutoCleanup stores whether finished worktrees are cleaned up on their own.
func (*Service) SetWorktreeDefault ¶
SetWorktreeDefault stores whether launches start in a worktree unless unticked.
type Settings ¶
type Settings struct {
// DefaultProfile is the profile the launch dropdown preselects.
DefaultProfile string `json:"defaultProfile"`
// WorktreeDefault presets each row's "Start in a worktree" checkbox.
WorktreeDefault bool `json:"worktreeDefault"`
// WorktreeAutoCleanup cleans up a finished worktree on its own once its pull request
// merges or its issue closes.
WorktreeAutoCleanup bool `json:"worktreeAutoCleanup"`
// Terminal is "iterm2" or "terminal".
Terminal string `json:"terminal"`
// CloneRoot is the clone root as entered, e.g. "~/projects".
CloneRoot string `json:"cloneRoot"`
// TrustedBots lists the bots (GitHub Apps) whose pull requests and issues are trusted
// like a collaborator's, by login, sorted. It starts as trust.DefaultBots.
TrustedBots []string `json:"trustedBots"`
// DefaultTrustedBots is the list ResetTrustedBots restores.
DefaultTrustedBots []string `json:"defaultTrustedBots"`
// SnoozeDays is how many days an inbox row's Snooze button hides an item; its menu
// offers other lengths for one snooze.
SnoozeDays int `json:"snoozeDays"`
// SnoozeWake is which new activity ends a snooze early.
SnoozeWake snooze.Rules `json:"snoozeWake"`
// WindowSize is the size the window opens at.
WindowSize WindowSize `json:"windowSize"`
// DefaultWindowSize is the size a fresh database opens the window at.
DefaultWindowSize WindowSize `json:"defaultWindowSize"`
// SensitiveFiles is whose pull requests have their changed files checked, which
// built-in categories are off, and the user's own patterns (see the sensitive
// package).
SensitiveFiles sensitive.Config `json:"sensitiveFiles"`
// SensitiveCategories are the built-in categories in matching order, with their
// patterns, for the settings page to describe.
SensitiveCategories []sensitive.Category `json:"sensitiveCategories"`
// MenuBar shows the app's icon in the menu bar, with how many items need the user and
// a short list of them; closing the window then keeps the app running there.
MenuBar bool `json:"menuBar"`
// BannersOff lists the kinds of notification (see the notify package) whose banners
// are off. The notification history keeps every kind either way.
BannersOff []string `json:"bannersOff"`
}
Settings is the full set of preferences as the UI shows them. Every field is a plain value.
type ThemeNotifier ¶
type ThemeNotifier interface {
ThemeChanged(theme string)
}
ThemeNotifier is told when the theme was changed and stored, so the desktop shell can bring the window's native appearance along with it.
type WindowSize ¶
WindowSize is the window's size, in points.
func DefaultWindowSize ¶
func DefaultWindowSize() WindowSize
DefaultWindowSize returns the size the window opens at on a fresh database.
func (WindowSize) Fit ¶
func (w WindowSize) Fit(width, height int) WindowSize
Fit returns the size shrunk, where needed, to fit a screen area of the given width and height, but never below the minimum. A zero or negative area leaves the size as it is.