services

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package services contains application services that orchestrate business logic.

Package services contains application services that orchestrate business logic.

Package services defines the service interface and common service patterns

Index

Constants

View Source
const (
	// DefaultFaviconSize is the target size for exported favicons (32x32 for high quality)
	DefaultFaviconSize = 32
	// FaviconTimeout is the maximum time to wait for a favicon to be available
	FaviconTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

func GetExportedFaviconPath added in v0.12.1

func GetExportedFaviconPath(dataDir, pageURL string) string

GetExportedFaviconPath returns the expected export path for a page URL.

func ZoomKeyForLog

func ZoomKeyForLog(raw string) string

ZoomKeyForLog exposes the derived zoom key (host or raw URL) for logging from other packages.

Types

type BrowserService

type BrowserService struct {
	// contains filtered or unexported fields
}

BrowserService handles browser-related operations for the built-in browser.

func NewBrowserService

func NewBrowserService(cfg *config.Config, queries db.DatabaseQuerier) *BrowserService

NewBrowserService creates a new BrowserService instance.

func (*BrowserService) AttachWebView

func (s *BrowserService) AttachWebView(view *webkit.WebView)

AttachWebView connects a native WebKit WebView to this service for integration.

func (*BrowserService) ClearHistory

func (s *BrowserService) ClearHistory(ctx context.Context) error

ClearHistory removes all history entries.

func (*BrowserService) CopyCurrentURL

func (s *BrowserService) CopyCurrentURL(ctx context.Context, url string) error

CopyCurrentURL copies the current URL to clipboard (frontend-initiated)

func (*BrowserService) DeleteHistoryEntry

func (s *BrowserService) DeleteHistoryEntry(ctx context.Context, id int64) error

DeleteHistoryEntry removes a specific history entry.

func (*BrowserService) GetColorPalettesForMessaging added in v0.11.0

func (s *BrowserService) GetColorPalettesForMessaging() ColorPalettesResponse

GetColorPalettesForMessaging returns the color palettes from config

func (*BrowserService) GetConfig

func (s *BrowserService) GetConfig(ctx context.Context) (*config.Config, error)

GetConfig returns the current browser configuration.

func (*BrowserService) GetCurrentURL

func (s *BrowserService) GetCurrentURL(ctx context.Context) (string, error)

GetCurrentURL returns the current URL (this would be implemented by the frontend)

func (*BrowserService) GetGUIBundle

func (s *BrowserService) GetGUIBundle() string

GetGUIBundle returns the loaded GUI bundle string

func (*BrowserService) GetHistoryStats

func (s *BrowserService) GetHistoryStats(ctx context.Context) (map[string]interface{}, error)

GetHistoryStats returns statistics about browser history.

func (*BrowserService) GetInitialURL

func (s *BrowserService) GetInitialURL(ctx context.Context) (string, error)

GetInitialURL returns the initially navigated URL for frontend synchronization

func (*BrowserService) GetRecentHistory

func (s *BrowserService) GetRecentHistory(ctx context.Context, limit int) ([]HistoryEntry, error)

GetRecentHistory returns recent browser history entries.

func (*BrowserService) GetRecentHistoryWithOffset

func (s *BrowserService) GetRecentHistoryWithOffset(ctx context.Context, limit, offset int) ([]HistoryEntry, error)

GetRecentHistoryWithOffset returns recent browser history entries with pagination support.

func (*BrowserService) GetSearchShortcuts

func (s *BrowserService) GetSearchShortcuts(ctx context.Context) (map[string]config.SearchShortcut, error)

GetSearchShortcuts returns available search shortcuts.

func (*BrowserService) GetZoomLevel

func (s *BrowserService) GetZoomLevel(ctx context.Context, url string) (float64, error)

GetZoomLevel retrieves the saved zoom level for a URL.

func (*BrowserService) GoBack

func (s *BrowserService) GoBack(ctx context.Context) error

GoBack provides navigation back functionality

func (*BrowserService) GoForward

func (s *BrowserService) GoForward(ctx context.Context) error

GoForward provides navigation forward functionality

func (*BrowserService) InjectToastSystem

func (s *BrowserService) InjectToastSystem(ctx context.Context, theme string) error

InjectToastSystem injects the GUI bundle and initializes the toast system

func (*BrowserService) LoadGUIBundle

func (s *BrowserService) LoadGUIBundle(assets embed.FS) error

LoadGUIBundle loads the unified GUI bundle from assets

func (*BrowserService) Navigate

func (s *BrowserService) Navigate(ctx context.Context, url string) (*NavigationResult, error)

Navigate handles navigation to a URL and records it in history.

func (*BrowserService) ResetZoom

func (s *BrowserService) ResetZoom(ctx context.Context, url string) (float64, error)

ResetZoom resets the zoom level to 1.0 for the current URL.

func (*BrowserService) SearchHistory

func (s *BrowserService) SearchHistory(ctx context.Context, query string, limit int) ([]HistoryEntry, error)

SearchHistory searches browser history.

func (*BrowserService) ServiceName

func (s *BrowserService) ServiceName() string

ServiceName returns the service name for frontend binding

func (*BrowserService) SetWindowTitleUpdater

func (s *BrowserService) SetWindowTitleUpdater(updater WindowTitleUpdater)

SetWindowTitleUpdater sets the window title updater interface

func (*BrowserService) SetZoomLevel

func (s *BrowserService) SetZoomLevel(ctx context.Context, url string, zoomLevel float64) error

SetZoomLevel sets the zoom level for a URL.

func (*BrowserService) UpdateConfig

func (s *BrowserService) UpdateConfig(ctx context.Context, newConfig *config.Config) error

UpdateConfig updates the browser configuration.

func (*BrowserService) UpdatePageTitle

func (s *BrowserService) UpdatePageTitle(ctx context.Context, url, title string) error

UpdatePageTitle updates the title of the current page in history and the window title.

func (*BrowserService) ZoomIn

func (s *BrowserService) ZoomIn(ctx context.Context, url string) (float64, error)

ZoomIn increases the zoom level to the next Firefox zoom level.

func (*BrowserService) ZoomOut

func (s *BrowserService) ZoomOut(ctx context.Context, url string) (float64, error)

ZoomOut decreases the zoom level to the previous Firefox zoom level.

type Cleanable added in v0.12.1

type Cleanable interface {
	Service
	// Cleanup releases any resources held by the service
	// Should be idempotent and safe to call multiple times
	Cleanup() error
}

Cleanable services can cleanup resources on shutdown

type ColorPalettesResponse added in v0.11.0

type ColorPalettesResponse struct {
	Light config.ColorPalette `json:"light"`
	Dark  config.ColorPalette `json:"dark"`
}

ColorPalettesResponse holds light and dark palettes for JSON marshaling

type DatabaseHistoryProvider

type DatabaseHistoryProvider struct {
	// contains filtered or unexported fields
}

DatabaseHistoryProvider implements HistoryProvider using the database.

func (*DatabaseHistoryProvider) GetAllHistory

func (h *DatabaseHistoryProvider) GetAllHistory() ([]*db.History, error)

GetAllHistory returns all history entries for fuzzy search.

func (*DatabaseHistoryProvider) GetHistoryByURL

func (h *DatabaseHistoryProvider) GetHistoryByURL(url string) (*db.History, error)

GetHistoryByURL retrieves history entry by exact URL match.

func (*DatabaseHistoryProvider) GetRecentHistory

func (h *DatabaseHistoryProvider) GetRecentHistory(limit int) ([]*db.History, error)

GetRecentHistory returns recent history entries limited by count.

func (*DatabaseHistoryProvider) SearchHistory

func (h *DatabaseHistoryProvider) SearchHistory(query string, limit int) ([]*db.History, error)

SearchHistory performs a basic text search in history.

type FaviconService added in v0.12.1

type FaviconService struct {
	// contains filtered or unexported fields
}

FaviconService provides unified favicon access using WebKitGTK's native database. The service keeps WebKit's FaviconDatabase as the source of truth and augments it with fallback rasterisation for SVG favicons so that callers always receive a 32x32 texture or an explicit error.

func NewFaviconService added in v0.12.1

func NewFaviconService(faviconDB *webkit.FaviconDatabase, queries db.DatabaseQuerier, dataDir string) (*FaviconService, error)

NewFaviconService creates a new favicon service

func (*FaviconService) CleanOldExports added in v0.12.1

func (fs *FaviconService) CleanOldExports() error

CleanOldExports removes exported favicons older than 30 days

func (*FaviconService) GetFaviconPath added in v0.12.1

func (fs *FaviconService) GetFaviconPath(pageURL string) (string, error)

GetFaviconPath returns the exported PNG path for CLI tools (dmenu, etc.) This allows CLI tools to display favicons without WebKitGTK API access.

func (*FaviconService) GetFaviconTexture added in v0.12.1

func (fs *FaviconService) GetFaviconTexture(pageURL string, callback func(*gdk.Texture, error))

GetFaviconTexture loads a favicon texture asynchronously and calls the callback with the result. The callback receives a 32x32 GdkTexture suitable for display in GTK widgets, or an error.

func (*FaviconService) OnFaviconChanged added in v0.12.1

func (fs *FaviconService) OnFaviconChanged(pageURL, faviconURI string) error

OnFaviconChanged handles favicon URI changes from WebKit's favicon database. We store the URI (PNG, SVG, etc.) so that callers can later load an appropriate texture.

func (*FaviconService) ServiceName added in v0.12.1

func (fs *FaviconService) ServiceName() string

ServiceName returns the service name for identification

type HistoryEntry

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

HistoryEntry represents a simplified history entry for frontend.

type Initializable added in v0.12.1

type Initializable interface {
	Service
	// Initialize performs any setup required after construction
	// Returns an error if initialization fails
	Initialize() error
}

Initializable services can be initialized after construction

type LifecycleService added in v0.12.1

type LifecycleService interface {
	Initializable
	Cleanable
}

LifecycleService implements both Initializable and Cleanable Use this for services that need both initialization and cleanup

type NavigationResult struct {
	URL           string        `json:"url"`
	Title         string        `json:"title"`
	Success       bool          `json:"success"`
	Error         string        `json:"error,omitempty"`
	LoadTime      time.Duration `json:"load_time"`
	RedirectChain []string      `json:"redirect_chain,omitempty"`
}

NavigationResult represents the result of a navigation operation.

type ParserService

type ParserService struct {
	// contains filtered or unexported fields
}

ParserService wraps the parser functionality for the application.

func NewParserService

func NewParserService(cfg *config.Config, queries *db.Queries) *ParserService

NewParserService creates a new ParserService instance.

func (*ParserService) CalculateSimilarity

func (s *ParserService) CalculateSimilarity(ctx context.Context, s1, s2 string) (float64, error)

CalculateSimilarity calculates similarity between two strings.

func (*ParserService) FuzzySearchHistory

func (s *ParserService) FuzzySearchHistory(
	ctx context.Context, query string, threshold float64,
) ([]parser.FuzzyMatch, error)

FuzzySearchHistory performs fuzzy search on history entries.

func (*ParserService) GetCompletions

func (s *ParserService) GetCompletions(ctx context.Context, input string, limit int) ([]string, error)

GetCompletions provides URL/search completions based on input.

func (*ParserService) GetFuzzyConfig

func (s *ParserService) GetFuzzyConfig(ctx context.Context) (*parser.FuzzyConfig, error)

GetFuzzyConfig returns current fuzzy matching configuration.

func (*ParserService) GetSupportedShortcuts

func (s *ParserService) GetSupportedShortcuts(ctx context.Context) (map[string]config.SearchShortcut, error)

GetSupportedShortcuts returns configured search shortcuts.

func (*ParserService) ParseInput

func (s *ParserService) ParseInput(ctx context.Context, input string) (*parser.ParseResult, error)

ParseInput parses user input and returns navigation result.

func (*ParserService) PreviewParse

func (s *ParserService) PreviewParse(ctx context.Context, input string) (*parser.ParseResult, error)

PreviewParse provides a preview of what ParseInput would return.

func (*ParserService) ProcessShortcut

func (s *ParserService) ProcessShortcut(ctx context.Context, shortcut, query string) (string, error)

ProcessShortcut processes a shortcut and returns the resulting URL.

func (*ParserService) UpdateFuzzyConfig

func (s *ParserService) UpdateFuzzyConfig(ctx context.Context, config *parser.FuzzyConfig) error

UpdateFuzzyConfig updates the fuzzy matching configuration.

func (*ParserService) ValidateURL

func (s *ParserService) ValidateURL(ctx context.Context, input string) (bool, error)

ValidateURL checks if the input represents a valid URL.

type Service added in v0.12.1

type Service interface {
	// ServiceName returns the unique identifier for this service
	// Used for logging, debugging, and service registration
	ServiceName() string
}

Service is the base interface that all application services must implement This allows for consistent service management, lifecycle control, and dependency injection

type WindowTitleUpdater

type WindowTitleUpdater interface {
	SetTitle(title string)
}

WindowTitleUpdater interface allows the service to update the window title Decoupled from any specific GUI framework.

Jump to

Keyboard shortcuts

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