settings

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	SectionReviewRequested = "reviewRequested"
	SectionAuthored        = "authored"
	SectionAssigned        = "assigned"
)

Inbox sections, named as the inbox snapshot names its lists.

View Source
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.

View Source
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.

View Source
const (
	DefaultProfile         = profiles.DefaultName
	DefaultWorktreeDefault = true
	DefaultAutoCleanup     = true
	DefaultTerminal        = TerminalITerm2
	DefaultCloneRoot       = "~/projects"
	DefaultSnoozeDays      = snooze.DefaultDays
)

Defaults for a fresh database.

View Source
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.

View Source
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.

View Source
const DefaultMenuBar = true

DefaultMenuBar is the menu bar setting of a fresh database.

View Source
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.

View Source
const KeyTheme = "ui.theme"

KeyTheme is the theme the app shows, stored as ThemeSystem, ThemeLight, or ThemeDark.

View Source
const KeyWindowSize = "window.size"

KeyWindowSize is the size the window opens at, stored as "<width>x<height>".

Variables

View Source
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")
)
View Source
var ErrInvalidTheme = errors.New("unknown theme")

ErrInvalidTheme is returned for a theme that is not one of the choices.

View Source
var ErrInvalidWindowSize = errors.New("invalid window size")

ErrInvalidWindowSize is returned for a window size outside the bounds.

View Source
var ErrUnknownSection = errors.New("unknown inbox section")

ErrUnknownSection is returned for a section that is not one of the inbox lists.

Functions

func IsDark

func IsDark(theme string, systemDark bool) bool

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

func ValidTheme(theme string) bool

ValidTheme reports whether theme is one of the choices.

Types

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

func NewService(db *gorm.DB, home string, opts ...Option) *Service

NewService returns a Service over db. home expands a ~ clone root.

func (*Service) CollapsedSections

func (s *Service) CollapsedSections(ctx context.Context) ([]string, error)

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

func (s *Service) Get(ctx context.Context) (Settings, error)

Get returns every preference, with the default for any that is unset or holds a value that is no longer valid.

func (*Service) MatchSensitivePath

func (s *Service) MatchSensitivePath(ctx context.Context, path string) (sensitive.PathMatch, error)

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

func (s *Service) MenuBar(ctx context.Context) (bool, error)

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

func (s *Service) ResetTrustedBots(ctx context.Context) error

ResetTrustedBots goes back to the default trusted bots.

func (*Service) SetCloneRoot

func (s *Service) SetCloneRoot(ctx context.Context, root string) error

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

func (s *Service) SetDefaultProfile(ctx context.Context, name string) error

SetDefaultProfile stores the profile the launch dropdown preselects. It must name a stored profile.

func (*Service) SetMenuBar

func (s *Service) SetMenuBar(ctx context.Context, on bool) error

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

func (s *Service) SetNotificationBanner(ctx context.Context, kind string, on bool) error

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

func (s *Service) SetSectionCollapsed(ctx context.Context, section string, collapsed bool) error

SetSectionCollapsed stores whether an inbox section is collapsed, so the inbox opens the same way at the next launch.

func (*Service) SetSensitiveCategory

func (s *Service) SetSensitiveCategory(ctx context.Context, id string, on bool) error

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

func (s *Service) SetSensitivePatterns(ctx context.Context, patterns []string) error

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

func (s *Service) SetSensitiveScope(ctx context.Context, scope string) error

SetSensitiveScope stores whose pull requests have their changed files checked: sensitive.ScopeOutside, or sensitive.ScopeCollaborators to check collaborators' too.

func (*Service) SetSnoozeDays

func (s *Service) SetSnoozeDays(ctx context.Context, days int) error

SetSnoozeDays stores how many days the Snooze button hides an item: snooze.MinDays to snooze.MaxDays.

func (*Service) SetSnoozeWake

func (s *Service) SetSnoozeWake(ctx context.Context, rules snooze.Rules) error

SetSnoozeWake stores which new activity ends a snooze early. Every rule is stored together, so the rules never mix two saves.

func (*Service) SetTerminal

func (s *Service) SetTerminal(ctx context.Context, terminal string) error

SetTerminal stores the terminal launches open in: "iterm2" or "terminal".

func (*Service) SetTheme

func (s *Service) SetTheme(ctx context.Context, theme string) error

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

func (s *Service) SetTrustedBots(ctx context.Context, bots []string) error

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

func (s *Service) SetWorktreeAutoCleanup(ctx context.Context, on bool) error

SetWorktreeAutoCleanup stores whether finished worktrees are cleaned up on their own.

func (*Service) SetWorktreeDefault

func (s *Service) SetWorktreeDefault(ctx context.Context, on bool) error

SetWorktreeDefault stores whether launches start in a worktree unless unticked.

func (*Service) Theme

func (s *Service) Theme(ctx context.Context) (string, error)

Theme returns the stored theme, or DefaultTheme when none is stored or the stored value is no longer a choice.

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

type WindowSize struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

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.

Directories

Path Synopsis
Package model holds the persisted user preferences.
Package model holds the persisted user preferences.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL