entity

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package entity defines domain entities for the browser.

Package entity contains domain entities representing core business concepts. These entities are pure Go types with no infrastructure dependencies.

Package entity defines domain entities for dumber.

Index

Constants

View Source
const (
	ZoomDefault = 1.0
	ZoomMin     = 0.25 // 25%
	ZoomMax     = 5.0  // 500%
	ZoomStep    = 0.1  // 10% increments
)

Default zoom constants

View Source
const SessionStateVersion = 1

SessionStateVersion is the current schema version for session state. Increment when making breaking changes to the serialization format.

Variables

View Source
var AccentMap = map[rune][]rune{
	'a': {'à', 'á', 'â', 'ä', 'ã', 'å', 'æ'},
	'c': {'ç', 'ć', 'č'},
	'e': {'è', 'é', 'ê', 'ë', 'ę', 'ė'},
	'i': {'ì', 'í', 'î', 'ï', 'į'},
	'n': {'ñ', 'ń'},
	'o': {'ò', 'ó', 'ô', 'ö', 'õ', 'ø', 'œ'},
	's': {'ß', 'ś', 'š'},
	'u': {'ù', 'ú', 'û', 'ü', 'ū'},
	'y': {'ÿ', 'ý'},
}

AccentMap maps base characters to their accented variants. The order determines display order in the accent picker.

View Source
var ErrInvalidSession = errors.New("invalid session")

Functions

func GetAccents added in v0.23.0

func GetAccents(char rune, uppercase bool) []rune

GetAccents returns the accent variants for a character. If uppercase is true, returns uppercase variants. Returns nil if the character has no accent variants.

func HasAccents added in v0.23.0

func HasAccents(char rune) bool

HasAccents returns true if the given character has accent variants.

Types

type ConfigKeyInfo added in v0.22.0

type ConfigKeyInfo struct {
	// Key is the full dotted path to the config key (e.g., "appearance.color_scheme")
	Key string `json:"key"`

	// Type is the Go type name (e.g., "string", "int", "bool", "float64")
	Type string `json:"type"`

	// Default is the default value as a string representation
	Default string `json:"default"`

	// Description explains the purpose of this config key
	Description string `json:"description"`

	// Values contains valid enum values (for string enums)
	// Empty if not an enum type
	Values []string `json:"values,omitempty"`

	// Range describes numeric constraints (e.g., "1-72", "0.1-5.0")
	// Empty if no range constraint
	Range string `json:"range,omitempty"`

	// Section groups related keys (e.g., "Appearance", "Logging")
	Section string `json:"section"`
}

ConfigKeyInfo describes a single configuration key for schema documentation.

type DailyVisitCount

type DailyVisitCount struct {
	Day     string `json:"day"`
	Entries int64  `json:"entries"`
	Visits  int64  `json:"visits"`
}

DailyVisitCount contains visit counts by day.

type DomainStat

type DomainStat struct {
	Domain      string    `json:"domain"`
	PageCount   int64     `json:"page_count"`
	TotalVisits int64     `json:"total_visits"`
	LastVisit   time.Time `json:"last_visit"`
}

DomainStat contains per-domain visit statistics.

type Favorite

type Favorite struct {
	ID          FavoriteID `json:"id"`
	URL         string     `json:"url"`
	Title       string     `json:"title"`
	FaviconURL  string     `json:"favicon_url"`
	FolderID    *FolderID  `json:"folder_id"`    // nil = root level
	ShortcutKey *int       `json:"shortcut_key"` // 1-9 for quick access (Alt+1 through Alt+9)
	Position    int        `json:"position"`     // Order within folder
	Tags        []Tag      `json:"tags,omitempty"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

Favorite represents a bookmarked URL.

func NewFavorite

func NewFavorite(url, title string) *Favorite

NewFavorite creates a new favorite for a URL.

func (*Favorite) HasShortcut

func (f *Favorite) HasShortcut() bool

HasShortcut returns true if this favorite has a keyboard shortcut.

func (*Favorite) HasTag

func (f *Favorite) HasTag(tagID TagID) bool

HasTag returns true if this favorite has the given tag.

func (*Favorite) InFolder

func (f *Favorite) InFolder() bool

InFolder returns true if this favorite is in a folder.

type FavoriteID

type FavoriteID int64

FavoriteID uniquely identifies a favorite/bookmark.

type FavoriteTree

type FavoriteTree struct {
	RootFolders    []*Folder
	RootFavorites  []*Favorite
	FolderMap      map[FolderID]*Folder     // Quick lookup
	ChildFolders   map[FolderID][]*Folder   // Children of each folder
	ChildFavorites map[FolderID][]*Favorite // Favorites in each folder
}

FavoriteTree represents a hierarchical view of folders and favorites.

func NewFavoriteTree

func NewFavoriteTree() *FavoriteTree

NewFavoriteTree creates an empty favorite tree.

type Folder

type Folder struct {
	ID        FolderID  `json:"id"`
	Name      string    `json:"name"`
	Icon      string    `json:"icon"`      // Optional icon identifier
	ParentID  *FolderID `json:"parent_id"` // nil = root level
	Position  int       `json:"position"`  // Order within parent
	CreatedAt time.Time `json:"created_at"`
}

Folder represents a container for organizing favorites.

func NewFolder

func NewFolder(name string) *Folder

NewFolder creates a new folder.

func (*Folder) IsRoot

func (f *Folder) IsRoot() bool

IsRoot returns true if this folder is at root level.

type FolderID

type FolderID int64

FolderID uniquely identifies a bookmark folder.

type HistoryAnalytics

type HistoryAnalytics struct {
	TotalEntries       int64                 `json:"total_entries"`
	TotalVisits        int64                 `json:"total_visits"`
	UniqueDays         int64                 `json:"unique_days"`
	TopDomains         []*DomainStat         `json:"top_domains"`
	DailyVisits        []*DailyVisitCount    `json:"daily_visits"`
	HourlyDistribution []*HourlyDistribution `json:"hourly_distribution"`
}

HistoryAnalytics contains all analytics data for the homepage.

type HistoryEntry

type HistoryEntry struct {
	ID          int64     `json:"id"`
	URL         string    `json:"url"`
	Title       string    `json:"title"`
	FaviconURL  string    `json:"favicon_url"`
	VisitCount  int64     `json:"visit_count"`
	LastVisited time.Time `json:"last_visited"`
	CreatedAt   time.Time `json:"created_at"`
}

HistoryEntry represents a visited URL in browsing history.

func NewHistoryEntry

func NewHistoryEntry(url, title string) *HistoryEntry

NewHistoryEntry creates a new history entry for a URL.

func (*HistoryEntry) IncrementVisit

func (h *HistoryEntry) IncrementVisit()

IncrementVisit updates the entry for a new visit.

type HistoryMatch

type HistoryMatch struct {
	Entry *HistoryEntry
	Score float64 // Match score (higher is better)
}

HistoryMatch represents a history entry that matched a search query. Used for fuzzy search results with scoring.

type HistoryStats

type HistoryStats struct {
	TotalEntries int64 `json:"total_entries"`
	TotalVisits  int64 `json:"total_visits"`
	UniqueDays   int64 `json:"unique_days"`
}

HistoryStats contains aggregated history statistics.

type HourlyDistribution

type HourlyDistribution struct {
	Hour       int   `json:"hour"`
	VisitCount int64 `json:"visit_count"`
}

HourlyDistribution contains visit counts by hour of day.

type IDGenerator added in v0.21.0

type IDGenerator func() string

IDGenerator is a function that generates unique IDs.

type Pane

type Pane struct {
	ID         PaneID
	URI        string
	Title      string
	FaviconURL string
	WindowType WindowType
	ZoomFactor float64
	CanGoBack  bool
	CanForward bool
	IsLoading  bool
	CreatedAt  time.Time

	// Popup-specific fields
	IsRelated    bool    // Shares context with parent
	ParentPaneID *PaneID // Parent pane if this is a related popup
	AutoClose    bool    // Auto-close on OAuth success
	RequestID    string  // Request ID for popup tracking
}

Pane represents a single browsing context (a WebView container). This is the leaf-level entity that holds navigation state.

func NewPane

func NewPane(id PaneID) *Pane

NewPane creates a new pane with default values.

type PaneID

type PaneID string

PaneID uniquely identifies a pane within the browser.

type PaneNode

type PaneNode struct {
	ID       string
	Pane     *Pane     // Non-nil for leaf nodes
	Parent   *PaneNode // nil for root
	Children []*PaneNode

	// Layout
	SplitDir   SplitDirection
	SplitRatio float64 // 0.0-1.0, position of divider

	// Stacked panes (alternative to split)
	IsStacked        bool
	ActiveStackIndex int
}

PaneNode represents a node in the workspace pane tree structure. It can be either:

  • Leaf node: Contains a single Pane
  • Split node: Contains two children (left/right or top/bottom)
  • Stacked node: Contains multiple panes in a tabbed view

func (*PaneNode) ActivePane

func (n *PaneNode) ActivePane() *PaneNode

ActivePane returns the currently visible pane in a stacked container.

func (*PaneNode) FindPane

func (n *PaneNode) FindPane(id PaneID) *PaneNode

FindPane searches the tree for a pane with the given ID.

func (*PaneNode) IsContainer

func (n *PaneNode) IsContainer() bool

IsContainer returns true if this is a split or stacked container.

func (*PaneNode) IsLeaf

func (n *PaneNode) IsLeaf() bool

IsLeaf returns true if this node contains a pane (no children).

func (*PaneNode) IsSplit

func (n *PaneNode) IsSplit() bool

IsSplit returns true if this node splits into two children.

func (*PaneNode) LeafCount

func (n *PaneNode) LeafCount() int

LeafCount returns the number of leaf nodes (panes) in the tree.

func (*PaneNode) Left

func (n *PaneNode) Left() *PaneNode

Left returns the left/top child in a split node.

func (*PaneNode) Right

func (n *PaneNode) Right() *PaneNode

Right returns the right/bottom child in a split node.

func (*PaneNode) StackedPanes

func (n *PaneNode) StackedPanes() []*PaneNode

StackedPanes returns the list of panes if this is a stacked container.

func (*PaneNode) VisibleAreaCount added in v0.25.0

func (n *PaneNode) VisibleAreaCount() int

VisibleAreaCount returns the number of visible pane areas in the tree. A stacked node counts as 1 visible area (only one pane visible at a time). A leaf node counts as 1 visible area. A split node's visible areas are the sum of its children's visible areas.

func (*PaneNode) Walk

func (n *PaneNode) Walk(fn func(*PaneNode) bool)

Walk traverses the tree calling fn for each node. Returns early if fn returns false.

type PaneNodeSnapshot added in v0.21.0

type PaneNodeSnapshot struct {
	ID               string              `json:"id"`
	Pane             *PaneSnapshot       `json:"pane,omitempty"`     // Non-nil for leaf nodes
	Children         []*PaneNodeSnapshot `json:"children,omitempty"` // Non-nil for containers
	SplitDir         SplitDirection      `json:"split_dir"`
	SplitRatio       float64             `json:"split_ratio"`
	IsStacked        bool                `json:"is_stacked"`
	ActiveStackIndex int                 `json:"active_stack_index"`
}

PaneNodeSnapshot captures a node in the pane tree.

type PaneRect

type PaneRect struct {
	PaneID PaneID
	X, Y   int // Top-left position relative to workspace container
	W, H   int // Width and height
}

PaneRect represents a pane's screen position and size. Used for geometric navigation to find adjacent panes by position.

func (PaneRect) Center

func (r PaneRect) Center() (cx, cy int)

Center returns the center point of the rectangle.

func (PaneRect) OverlapsHorizontally added in v0.24.0

func (r PaneRect) OverlapsHorizontally(other PaneRect) bool

OverlapsHorizontally returns true if the two rectangles overlap in the X axis. Used for up/down navigation to prefer panes at the same horizontal level.

func (PaneRect) OverlapsVertically added in v0.24.0

func (r PaneRect) OverlapsVertically(other PaneRect) bool

OverlapsVertically returns true if the two rectangles overlap in the Y axis. Used for left/right navigation to prefer panes at the same vertical level.

type PaneSnapshot added in v0.21.0

type PaneSnapshot struct {
	ID         PaneID  `json:"id"`
	URI        string  `json:"uri"`
	Title      string  `json:"title"`
	ZoomFactor float64 `json:"zoom_factor"`
}

PaneSnapshot captures the essential state of a pane.

type PurgeResult

type PurgeResult struct {
	Target  PurgeTarget
	Success bool
	Error   error
}

PurgeResult represents the outcome of purging a single target.

type PurgeTarget

type PurgeTarget struct {
	Type        PurgeTargetType
	Path        string
	Description string
	Size        int64
	Exists      bool
}

PurgeTarget represents something that can be purged.

type PurgeTargetType

type PurgeTargetType int

PurgeTargetType identifies what kind of purgeable item this is.

const (
	PurgeTargetConfig PurgeTargetType = iota
	PurgeTargetData
	PurgeTargetState
	PurgeTargetCache
	PurgeTargetFilterJSON
	PurgeTargetFilterStore
	PurgeTargetFilterCache
	PurgeTargetDesktopFile
	PurgeTargetIcon
)

type Session

type Session struct {
	ID        SessionID
	Type      SessionType
	StartedAt time.Time
	EndedAt   *time.Time
}

Session captures metadata about a dumber run. A browser session is expected to have a corresponding log file.

func (*Session) End

func (s *Session) End(endedAt time.Time)

func (*Session) IsActive

func (s *Session) IsActive() bool

func (*Session) ShortID

func (s *Session) ShortID() string

func (*Session) Validate

func (s *Session) Validate() error

type SessionID

type SessionID string

SessionID uniquely identifies an application session. For now it matches the log session ID format (YYYYMMDD_HHMMSS_xxxx).

type SessionInfo added in v0.21.0

type SessionInfo struct {
	Session   *Session
	State     *SessionState
	TabCount  int
	PaneCount int
	IsActive  bool      // Has active lock file
	IsCurrent bool      // Is the current session
	UpdatedAt time.Time // When the state was last saved
}

SessionInfo provides summary information for the session manager UI.

type SessionPurgeItem added in v0.21.0

type SessionPurgeItem struct {
	Info     SessionInfo
	Selected bool
}

SessionPurgeItem represents an inactive session in the purge selection UI.

type SessionState added in v0.21.0

type SessionState struct {
	Version        int           `json:"version"`
	SessionID      SessionID     `json:"session_id"`
	Tabs           []TabSnapshot `json:"tabs"`
	ActiveTabIndex int           `json:"active_tab_index"`
	SavedAt        time.Time     `json:"saved_at"`
}

SessionState represents a complete snapshot of a browser session. This is serialized to JSON and stored in the database.

func SnapshotFromTabList added in v0.21.0

func SnapshotFromTabList(sessionID SessionID, tabs *TabList) *SessionState

SnapshotFromTabList creates a SessionState from a live TabList.

func (*SessionState) CountPanes added in v0.21.0

func (s *SessionState) CountPanes() int

CountPanes returns the total number of panes in the session state.

type SessionType

type SessionType string

SessionType distinguishes long-running browser sessions from ephemeral CLI invocations.

const (
	SessionTypeBrowser SessionType = "browser"
	SessionTypeCLI     SessionType = "cli"
)

type SplitDirection

type SplitDirection int

SplitDirection indicates how a pane container splits its children.

const (
	SplitNone       SplitDirection = iota // Leaf node or stacked container
	SplitHorizontal                       // Left/right split
	SplitVertical                         // Top/bottom split
)

type Tab

type Tab struct {
	ID        TabID
	Name      string     // Display name (often derived from active pane title)
	Workspace *Workspace // The workspace this tab contains
	Position  int        // Position in the tab bar (0-indexed)
	IsPinned  bool       // Pinned tabs stay at the left
	CreatedAt time.Time
}

Tab represents a browser tab containing a workspace. Tabs are the top-level container in the browser's tab bar.

func NewTab

func NewTab(tabID TabID, workspaceID WorkspaceID, initialPane *Pane) *Tab

NewTab creates a new tab with an initial pane.

func (*Tab) PaneCount

func (t *Tab) PaneCount() int

PaneCount returns the number of panes in this tab's workspace.

func (*Tab) Title

func (t *Tab) Title() string

Title returns the display title for the tab. Uses the tab's Name if set, otherwise returns "Tab N" based on position.

type TabID

type TabID string

TabID uniquely identifies a tab.

type TabList

type TabList struct {
	Tabs                []*Tab
	ActiveTabID         TabID
	PreviousActiveTabID TabID // Tracks last active tab for Alt+Tab style switching
}

TabList manages an ordered collection of tabs.

func NewTabList

func NewTabList() *TabList

NewTabList creates an empty tab list.

func TabListFromSnapshot added in v0.21.0

func TabListFromSnapshot(state *SessionState, idGen IDGenerator) *TabList

TabListFromSnapshot reconstructs a TabList from a SessionState snapshot. Generates new IDs for all entities using the provided generator. This is the inverse of SnapshotFromTabList.

func (*TabList) ActiveTab

func (tl *TabList) ActiveTab() *Tab

ActiveTab returns the currently active tab.

func (*TabList) Add

func (tl *TabList) Add(tab *Tab)

Add appends a tab to the list.

func (*TabList) Count

func (tl *TabList) Count() int

Count returns the number of tabs.

func (*TabList) Find

func (tl *TabList) Find(id TabID) *Tab

Find returns a tab by ID.

func (*TabList) Move

func (tl *TabList) Move(id TabID, newPos int) bool

Move moves a tab to a new position.

func (*TabList) Remove

func (tl *TabList) Remove(id TabID) bool

Remove removes a tab by ID and reindexes positions.

func (*TabList) ReplaceFrom added in v0.21.0

func (tl *TabList) ReplaceFrom(other *TabList)

ReplaceFrom replaces this TabList's contents with those from another TabList. This modifies in-place so existing references to this TabList remain valid.

func (*TabList) SetActive

func (tl *TabList) SetActive(id TabID)

SetActive sets the active tab and updates the previous active tab.

func (*TabList) TabAt

func (tl *TabList) TabAt(index int) *Tab

TabAt returns the tab at the given 0-based index.

type TabSnapshot added in v0.21.0

type TabSnapshot struct {
	ID        TabID             `json:"id"`
	Name      string            `json:"name"`
	Position  int               `json:"position"`
	IsPinned  bool              `json:"is_pinned"`
	Workspace WorkspaceSnapshot `json:"workspace"`
}

TabSnapshot captures the state of a single tab.

type Tag

type Tag struct {
	ID        TagID     `json:"id"`
	Name      string    `json:"name"`
	Color     string    `json:"color"` // Hex color code (e.g., "#FF5733")
	CreatedAt time.Time `json:"created_at"`
}

Tag represents a label that can be applied to favorites.

func NewTag

func NewTag(name string) *Tag

NewTag creates a new tag with default color.

type TagID

type TagID int64

TagID uniquely identifies a tag.

type UpdateInfo added in v0.21.0

type UpdateInfo struct {
	// CurrentVersion is the version of the running binary.
	CurrentVersion string
	// LatestVersion is the latest available version from GitHub.
	LatestVersion string
	// IsNewer is true if LatestVersion is newer than CurrentVersion.
	IsNewer bool
	// ReleaseURL is the URL to the GitHub release page.
	ReleaseURL string
	// DownloadURL is the direct download URL for the binary archive.
	DownloadURL string
	// PublishedAt is when the release was published.
	PublishedAt time.Time
	// ReleaseNotes contains the release changelog (optional).
	ReleaseNotes string
}

UpdateInfo holds information about an available update.

type UpdateStatus added in v0.21.0

type UpdateStatus int

UpdateStatus represents the current state of the update process.

const (
	// UpdateStatusUnknown means update status hasn't been checked yet.
	UpdateStatusUnknown UpdateStatus = iota
	// UpdateStatusUpToDate means the current version is the latest.
	UpdateStatusUpToDate
	// UpdateStatusAvailable means a newer version is available.
	UpdateStatusAvailable
	// UpdateStatusDownloading means the update is being downloaded.
	UpdateStatusDownloading
	// UpdateStatusReady means the update is downloaded and staged for exit.
	UpdateStatusReady
	// UpdateStatusFailed means the update check or download failed.
	UpdateStatusFailed
)

func (UpdateStatus) String added in v0.21.0

func (s UpdateStatus) String() string

String returns a human-readable string for the update status.

type WindowType

type WindowType int

WindowType indicates the type of browser window.

const (
	WindowMain  WindowType = iota // Regular browser tab
	WindowPopup                   // Popup window (OAuth, feature-restricted)
)

type Workspace

type Workspace struct {
	ID           WorkspaceID
	Name         string
	Root         *PaneNode // Root of the pane tree
	ActivePaneID PaneID    // Currently focused pane
	CreatedAt    time.Time
}

Workspace represents a collection of panes arranged in a tree layout. Each tab contains exactly one workspace.

func NewWorkspace

func NewWorkspace(id WorkspaceID, initialPane *Pane) *Workspace

NewWorkspace creates a new workspace with an initial pane.

func (*Workspace) ActivePane

func (w *Workspace) ActivePane() *PaneNode

ActivePane returns the currently active pane node.

func (*Workspace) AllPanes

func (w *Workspace) AllPanes() []*Pane

AllPanes returns all leaf panes in the workspace.

func (*Workspace) FindPane

func (w *Workspace) FindPane(id PaneID) *PaneNode

FindPane searches for a pane by ID in the workspace.

func (*Workspace) PaneCount

func (w *Workspace) PaneCount() int

PaneCount returns the number of panes in the workspace.

func (*Workspace) VisibleAreaCount added in v0.25.0

func (w *Workspace) VisibleAreaCount() int

VisibleAreaCount returns the number of visible pane areas. Stacked panes count as 1 (only one visible at a time).

type WorkspaceID

type WorkspaceID string

WorkspaceID uniquely identifies a workspace.

type WorkspaceSnapshot added in v0.21.0

type WorkspaceSnapshot struct {
	ID           WorkspaceID       `json:"id"`
	Root         *PaneNodeSnapshot `json:"root"`
	ActivePaneID PaneID            `json:"active_pane_id"`
}

WorkspaceSnapshot captures the pane tree layout.

type ZoomLevel

type ZoomLevel struct {
	Domain     string  // Domain name (e.g., "github.com")
	ZoomFactor float64 // Zoom factor (1.0 = 100%, 1.5 = 150%)
	UpdatedAt  time.Time
}

ZoomLevel represents the zoom factor for a specific domain. Allows users to set persistent zoom levels per-site.

func NewZoomLevel

func NewZoomLevel(domain string, factor float64) *ZoomLevel

NewZoomLevel creates a new zoom level for a domain.

func (*ZoomLevel) IsDefault

func (z *ZoomLevel) IsDefault() bool

IsDefault returns true if the zoom is at default level.

func (*ZoomLevel) Percentage

func (z *ZoomLevel) Percentage() int

Percentage returns the zoom factor as a percentage (e.g., 150 for 1.5).

func (*ZoomLevel) Reset

func (z *ZoomLevel) Reset()

Reset restores the zoom factor to default.

func (*ZoomLevel) SetFactor

func (z *ZoomLevel) SetFactor(factor float64)

SetFactor updates the zoom factor, clamping to valid range.

func (*ZoomLevel) ZoomIn

func (z *ZoomLevel) ZoomIn()

ZoomIn increases the zoom factor by one step.

func (*ZoomLevel) ZoomOut

func (z *ZoomLevel) ZoomOut()

ZoomOut decreases the zoom factor by one step.

Jump to

Keyboard shortcuts

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