entity

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 3 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.

Index

Constants

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

Default zoom constants

Variables

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

Functions

This section is empty.

Types

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 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) 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 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.

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 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 (*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) 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 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 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.

type WorkspaceID

type WorkspaceID string

WorkspaceID uniquely identifies a workspace.

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