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
- func GetExportedFaviconPath(dataDir, pageURL string) string
- func ZoomKeyForLog(raw string) string
- type BrowserService
- func (s *BrowserService) AttachWebView(view *webkit.WebView)
- func (s *BrowserService) ClearHistory(ctx context.Context) error
- func (s *BrowserService) CopyCurrentURL(ctx context.Context, url string) error
- func (s *BrowserService) DeleteHistoryEntry(ctx context.Context, id int64) error
- func (s *BrowserService) FlushAllCaches(ctx context.Context) error
- func (s *BrowserService) FlushHistoryQueue(ctx context.Context) error
- func (s *BrowserService) GetBestPrefixMatch(ctx context.Context, prefix string) string
- func (s *BrowserService) GetColorPalettesForMessaging() ColorPalettesResponse
- func (s *BrowserService) GetConfig(ctx context.Context) (*config.Config, error)
- func (s *BrowserService) GetCurrentURL(ctx context.Context) (string, error)
- func (s *BrowserService) GetFavorites(ctx context.Context) ([]FavoriteEntry, error)
- func (s *BrowserService) GetGUIBundle() string
- func (s *BrowserService) GetHistoryStats(ctx context.Context) (map[string]interface{}, error)
- func (s *BrowserService) GetInitialURL(ctx context.Context) (string, error)
- func (s *BrowserService) GetMostVisited(ctx context.Context, limit int) ([]HistoryEntry, error)
- func (s *BrowserService) GetRecentHistory(ctx context.Context, limit int) ([]HistoryEntry, error)
- func (s *BrowserService) GetRecentHistoryWithOffset(ctx context.Context, limit, offset int) ([]HistoryEntry, error)
- func (s *BrowserService) GetSearchShortcuts(ctx context.Context) (map[string]config.SearchShortcut, error)
- func (s *BrowserService) GetZoomLevel(ctx context.Context, url string) (float64, error)
- func (s *BrowserService) GoBack(ctx context.Context) error
- func (s *BrowserService) GoForward(ctx context.Context) error
- func (s *BrowserService) InjectToastSystem(ctx context.Context, theme string) error
- func (s *BrowserService) IsFavorite(ctx context.Context, url string) (bool, error)
- func (s *BrowserService) LoadCertCacheFromDB(ctx context.Context) error
- func (s *BrowserService) LoadFavoritesCacheFromDB(ctx context.Context) error
- func (s *BrowserService) LoadFuzzyCacheFromDB(ctx context.Context) error
- func (s *BrowserService) LoadGUIBundle(assets embed.FS) error
- func (s *BrowserService) LoadZoomCacheFromDB(ctx context.Context) error
- func (s *BrowserService) Navigate(ctx context.Context, url string) (*NavigationResult, error)
- func (s *BrowserService) ResetZoom(ctx context.Context, url string) (float64, error)
- func (s *BrowserService) SearchHistory(ctx context.Context, query string, limit int) ([]HistoryEntry, error)
- func (s *BrowserService) ServiceName() string
- func (s *BrowserService) SetWindowTitleUpdater(updater WindowTitleUpdater)
- func (s *BrowserService) SetZoomLevel(ctx context.Context, url string, zoomLevel float64) error
- func (s *BrowserService) ToggleFavorite(ctx context.Context, url, title, faviconURL string) (bool, error)
- func (s *BrowserService) UpdateConfig(ctx context.Context, newConfig *config.Config) error
- func (s *BrowserService) UpdatePageTitle(ctx context.Context, url, title string) error
- func (s *BrowserService) ZoomIn(ctx context.Context, url string) (float64, error)
- func (s *BrowserService) ZoomOut(ctx context.Context, url string) (float64, error)
- type Cleanable
- type ColorPalettesResponse
- type DatabaseHistoryProvider
- func (h *DatabaseHistoryProvider) GetAllHistory() ([]*db.History, error)
- func (h *DatabaseHistoryProvider) GetHistoryByURL(url string) (*db.History, error)
- func (h *DatabaseHistoryProvider) GetRecentHistory(limit int) ([]*db.History, error)
- func (h *DatabaseHistoryProvider) SearchHistory(query string, limit int) ([]*db.History, error)
- type FaviconService
- func (fs *FaviconService) CleanOldExports() error
- func (fs *FaviconService) GetFaviconPath(pageURL string) (string, error)
- func (fs *FaviconService) GetFaviconTexture(pageURL string, callback func(*gdk.Texture, error))
- func (fs *FaviconService) OnFaviconChanged(pageURL, faviconURI string) error
- func (fs *FaviconService) ServiceName() string
- type FavoriteEntry
- type HistoryEntry
- type Initializable
- type LifecycleService
- type NavigationResult
- type ParserService
- func (s *ParserService) CalculateSimilarity(ctx context.Context, s1, s2 string) (float64, error)
- func (s *ParserService) FuzzySearchHistory(ctx context.Context, query string, threshold float64) ([]parser.FuzzyMatch, error)
- func (s *ParserService) GetCompletions(ctx context.Context, input string, limit int) ([]string, error)
- func (s *ParserService) GetFuzzyConfig(ctx context.Context) (*parser.FuzzyConfig, error)
- func (s *ParserService) GetSupportedShortcuts(ctx context.Context) (map[string]config.SearchShortcut, error)
- func (s *ParserService) ParseInput(ctx context.Context, input string) (*parser.ParseResult, error)
- func (s *ParserService) PreviewParse(ctx context.Context, input string) (*parser.ParseResult, error)
- func (s *ParserService) ProcessShortcut(ctx context.Context, shortcut, query string) (string, error)
- func (s *ParserService) UpdateFuzzyConfig(ctx context.Context, config *parser.FuzzyConfig) error
- func (s *ParserService) ValidateURL(ctx context.Context, input string) (bool, error)
- type Service
- type WindowTitleUpdater
Constants ¶
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 // DeduplicationWindow is the time window for ignoring duplicate favicon changes DeduplicationWindow = 2 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func GetExportedFaviconPath ¶ added in v0.12.1
GetExportedFaviconPath returns the expected export path for a page URL.
func ZoomKeyForLog ¶
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) FlushAllCaches ¶ added in v0.13.0
func (s *BrowserService) FlushAllCaches(ctx context.Context) error
FlushAllCaches flushes all in-memory caches to ensure pending writes complete. This is typically called during shutdown to prevent data loss.
func (*BrowserService) FlushHistoryQueue ¶ added in v0.13.0
func (s *BrowserService) FlushHistoryQueue(ctx context.Context) error
FlushHistoryQueue flushes any pending history writes and stops the processor. Call this during graceful shutdown. Safe to call multiple times. Respects context cancellation with a timeout to prevent hanging.
func (*BrowserService) GetBestPrefixMatch ¶ added in v0.15.0
func (s *BrowserService) GetBestPrefixMatch(ctx context.Context, prefix string) string
GetBestPrefixMatch returns the highest-scoring URL that starts with the given prefix. Used for fish-style inline autosuggestions in the omnibox.
func (*BrowserService) GetColorPalettesForMessaging ¶ added in v0.11.0
func (s *BrowserService) GetColorPalettesForMessaging() ColorPalettesResponse
GetColorPalettesForMessaging returns the color palettes from config
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) GetFavorites ¶ added in v0.14.0
func (s *BrowserService) GetFavorites(ctx context.Context) ([]FavoriteEntry, error)
GetFavorites returns all favorites ordered by position.
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) GetMostVisited ¶ added in v0.15.0
func (s *BrowserService) GetMostVisited(ctx context.Context, limit int) ([]HistoryEntry, error)
GetMostVisited returns the most visited browser history entries.
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 ¶
GetZoomLevel retrieves the saved zoom level for a URL. Now reads from in-memory cache instead of database for instant access.
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) IsFavorite ¶ added in v0.14.0
IsFavorite checks if a URL is in the favorites list.
func (*BrowserService) LoadCertCacheFromDB ¶ added in v0.13.0
func (s *BrowserService) LoadCertCacheFromDB(ctx context.Context) error
LoadCertCacheFromDB loads all certificate validations from the database into the cache. This is typically called once at startup for fast RAM-first access.
func (*BrowserService) LoadFavoritesCacheFromDB ¶ added in v0.14.0
func (s *BrowserService) LoadFavoritesCacheFromDB(ctx context.Context) error
LoadFavoritesCacheFromDB loads all favorites from the database into the cache. This is typically called once at startup for fast RAM-first access.
func (*BrowserService) LoadFuzzyCacheFromDB ¶ added in v0.13.0
func (s *BrowserService) LoadFuzzyCacheFromDB(ctx context.Context) error
LoadFuzzyCacheFromDB builds or loads the fuzzy search cache from database history. This ensures dmenu has instant access to pre-built search structures.
func (*BrowserService) LoadGUIBundle ¶
func (s *BrowserService) LoadGUIBundle(assets embed.FS) error
LoadGUIBundle loads the unified GUI bundle from assets
func (*BrowserService) LoadZoomCacheFromDB ¶ added in v0.13.0
func (s *BrowserService) LoadZoomCacheFromDB(ctx context.Context) error
LoadZoomCacheFromDB loads all zoom levels from database into memory cache on startup. This eliminates database reads during page transitions.
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) 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 ¶
SetZoomLevel sets the zoom level for a URL. Updates cache immediately (instant) and persists to DB asynchronously.
func (*BrowserService) ToggleFavorite ¶ added in v0.14.0
func (s *BrowserService) ToggleFavorite(ctx context.Context, url, title, faviconURL string) (bool, error)
ToggleFavorite adds or removes a URL from favorites. Returns true if the URL was added, false if it was removed.
func (*BrowserService) UpdateConfig ¶
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.
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 ¶
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 FavoriteEntry ¶ added in v0.14.0
type FavoriteEntry struct {
ID int64 `json:"id"`
URL string `json:"url"`
Title string `json:"title"`
FaviconURL string `json:"favicon_url"`
Position int64 `json:"position"`
}
FavoriteEntry represents a favorite for the frontend (similar to HistoryEntry).
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 ¶
type NavigationResult struct {
}
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 ¶
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 ¶
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.