1package config
2
3import "github.com/bnema/dumber/internal/domain/entity"
4
5// Type aliases for config value types now defined in domain/entity.
6// These aliases keep all existing config-package callers working without
7// any changes to their import paths.
8
9// AppearanceConfig holds UI/rendering preferences.
10type AppearanceConfig = entity.AppearanceConfig
11
12// ColorPalette contains semantic color tokens for light/dark themes.
13type ColorPalette = entity.ColorPalette
14
15// ActionBinding defines a keybinding with optional description.
16type ActionBinding = entity.ActionBinding
17
18// PaneModeConfig defines modal behavior for pane management.
19type PaneModeConfig = entity.PaneModeConfig
20
21// TabModeConfig defines modal behavior for tab management (Zellij-style).
22type TabModeConfig = entity.TabModeConfig
23
24// ResizeModeConfig defines modal behavior for resizing panes (Zellij-style).
25type ResizeModeConfig = entity.ResizeModeConfig
26
27// SessionModeConfig defines modal behavior for session management.
28type SessionModeConfig = entity.SessionModeConfig
29
30// SessionConfig holds session persistence settings.
31type SessionConfig = entity.SessionConfig
32
33// GlobalShortcutsConfig defines global shortcuts (always active, not modal).
34type GlobalShortcutsConfig = entity.GlobalShortcutsConfig
35
36// FloatingPaneProfile defines a shortcut profile that opens a URL in the floating pane.
37type FloatingPaneProfile = entity.FloatingPaneProfile
38
39// FloatingPaneConfig defines persistent floating pane behavior.
40type FloatingPaneConfig = entity.FloatingPaneConfig
41
42// WorkspaceStylingConfig defines visual styling for workspace panes.
43type WorkspaceStylingConfig = entity.WorkspaceStylingConfig
44
45// PopupBehavior defines how popup windows should be opened.
46type PopupBehavior = entity.PopupBehavior
47
48const (
49 // PopupBehaviorSplit opens popups in a split pane (default)
50 PopupBehaviorSplit = entity.PopupBehaviorSplit
51 // PopupBehaviorStacked opens popups in a stacked pane
52 PopupBehaviorStacked = entity.PopupBehaviorStacked
53 // PopupBehaviorTabbed opens popups as a new tab
54 PopupBehaviorTabbed = entity.PopupBehaviorTabbed
55 // PopupBehaviorWindowed opens popups in a new workspace window
56 PopupBehaviorWindowed = entity.PopupBehaviorWindowed
57)
58
59// OmniboxInitialBehavior defines how omnibox history is ordered on open.
60type OmniboxInitialBehavior = entity.OmniboxInitialBehavior
61
62const (
63 // OmniboxInitialBehaviorRecent shows recent visits first.
64 OmniboxInitialBehaviorRecent = entity.OmniboxInitialBehaviorRecent
65 // OmniboxInitialBehaviorMostVisited shows most visited sites first.
66 OmniboxInitialBehaviorMostVisited = entity.OmniboxInitialBehaviorMostVisited
67 // OmniboxInitialBehaviorNone shows no initial history.
68 OmniboxInitialBehaviorNone = entity.OmniboxInitialBehaviorNone
69)
70
71// BrowsingContextConfig defines handling for browsing contexts (popups, tabs, new windows).
72type BrowsingContextConfig = entity.BrowsingContextConfig
73
74// Deprecated: PopupBehaviorConfig is a compatibility alias for BrowsingContextConfig.
75type PopupBehaviorConfig = entity.BrowsingContextConfig
76
77// WorkspaceConfig captures layout, pane, and tab behavior preferences.
78type WorkspaceConfig = entity.WorkspaceConfig
79
80// UpdateConfig holds automatic update settings.
81type UpdateConfig = entity.UpdateConfig
82
83// Config represents the complete configuration for dumber.
84type Config struct {
85 Database DatabaseConfig `mapstructure:"database" yaml:"database" toml:"database"`
86 History HistoryConfig `mapstructure:"history" yaml:"history" toml:"history"`
87 SearchShortcuts map[string]SearchShortcut `mapstructure:"search_shortcuts" yaml:"search_shortcuts" toml:"search_shortcuts"`
88 // DefaultSearchEngine is the URL template for the default search engine (must contain %s placeholder)
89 DefaultSearchEngine string `mapstructure:"default_search_engine" yaml:"default_search_engine" toml:"default_search_engine"`
90 Dmenu DmenuConfig `mapstructure:"dmenu" yaml:"dmenu" toml:"dmenu"`
91 Logging LoggingConfig `mapstructure:"logging" yaml:"logging" toml:"logging"`
92 Appearance AppearanceConfig `mapstructure:"appearance" yaml:"appearance" toml:"appearance"`
93 Debug DebugConfig `mapstructure:"debug" yaml:"debug" toml:"debug"`
94 // DefaultWebpageZoom sets the default zoom level for pages without saved zoom settings (1.0 = 100%, 1.2 = 120%)
95 DefaultWebpageZoom float64 `mapstructure:"default_webpage_zoom" yaml:"default_webpage_zoom" toml:"default_webpage_zoom"`
96 // DefaultUIScale sets the default UI scale for GTK widgets (1.0 = 100%, 2.0 = 200%)
97 DefaultUIScale float64 `mapstructure:"default_ui_scale" yaml:"default_ui_scale" toml:"default_ui_scale"`
98 // Workspace defines workspace, pane, and tab handling behavior.
99 Workspace WorkspaceConfig `mapstructure:"workspace" yaml:"workspace" toml:"workspace"`
100 // Session controls session persistence and restoration.
101 Session SessionConfig `mapstructure:"session" yaml:"session" toml:"session"`
102 // ContentFiltering controls ad blocking and content filtering
103 ContentFiltering ContentFilteringConfig `mapstructure:"content_filtering" yaml:"content_filtering" toml:"content_filtering"`
104 // Clipboard controls clipboard-related behavior
105 Clipboard ClipboardConfig `mapstructure:"clipboard" yaml:"clipboard" toml:"clipboard"`
106 // Omnibox controls the omnibox behavior (initial history display)
107 Omnibox OmniboxConfig `mapstructure:"omnibox" yaml:"omnibox" toml:"omnibox"`
108 // Media controls video playback and hardware acceleration
109 Media MediaConfig `mapstructure:"media" yaml:"media" toml:"media"`
110 // Update controls automatic update checking and downloading.
111 Update UpdateConfig `mapstructure:"update" yaml:"update" toml:"update"`
112 // Downloads configures file download behavior.
113 Downloads DownloadsConfig `mapstructure:"downloads" yaml:"downloads" toml:"downloads"`
114 // Engine holds engine selection and unified engine options.
115 Engine EngineConfig `mapstructure:"engine" toml:"engine" yaml:"engine"`
116}
117
118// CookiePolicy controls cookie acceptance behavior.
119type CookiePolicy string
120
121const (
122 // CookiePolicyAlways accepts all cookies.
123 CookiePolicyAlways CookiePolicy = "always"
124 // CookiePolicyNoThirdParty blocks third-party cookies.
125 CookiePolicyNoThirdParty CookiePolicy = "no_third_party"
126 // CookiePolicyNever blocks all cookies.
127 CookiePolicyNever CookiePolicy = "never"
128)
129
130// GSKRendererMode controls the GTK Scene Kit renderer selection.
131type GSKRendererMode string
132
133const (
134 GSKRendererAuto GSKRendererMode = "auto"
135 GSKRendererOpenGL GSKRendererMode = "opengl"
136 GSKRendererVulkan GSKRendererMode = "vulkan"
137 GSKRendererCairo GSKRendererMode = "cairo"
138)
139
140// HardwareDecodingMode controls video hardware acceleration.
141type HardwareDecodingMode string
142
143const (
144 // HardwareDecodingAuto lets GStreamer choose (hw preferred, sw fallback)
145 HardwareDecodingAuto HardwareDecodingMode = "auto"
146 // HardwareDecodingForce requires hardware decoding (fails if unavailable)
147 HardwareDecodingForce HardwareDecodingMode = "force"
148 // HardwareDecodingDisable uses software decoding only
149 HardwareDecodingDisable HardwareDecodingMode = "disable"
150)
151
152// GLRenderingMode controls OpenGL API selection for video rendering.
153type GLRenderingMode string
154
155const (
156 // GLRenderingModeAuto lets GStreamer choose the best GL API
157 GLRenderingModeAuto GLRenderingMode = "auto"
158 // GLRenderingModeGLES2 forces GLES2 (better for some mobile/embedded GPUs)
159 GLRenderingModeGLES2 GLRenderingMode = "gles2"
160 // GLRenderingModeGL3 forces OpenGL 3.x desktop
161 GLRenderingModeGL3 GLRenderingMode = "gl3"
162 // GLRenderingModeNone disables GL-based rendering
163 GLRenderingModeNone GLRenderingMode = "none"
164)
165
166// PerformanceProfile selects preset performance tuning settings.
167type PerformanceProfile string
168
169const (
170 // ProfileDefault uses WebKit defaults (no tuning applied).
171 ProfileDefault PerformanceProfile = "default"
172 // ProfileLite reduces resource usage for low-RAM systems.
173 ProfileLite PerformanceProfile = "lite"
174 // ProfileBalanced is a conservative compatibility preset between lite and max.
175 ProfileBalanced PerformanceProfile = "balanced"
176 // ProfileMax maximizes responsiveness for heavy pages (GitHub PRs, etc).
177 ProfileMax PerformanceProfile = "max"
178 // ProfileCustom allows full control over individual performance settings.
179 ProfileCustom PerformanceProfile = "custom"
180)
181
182// ThemeDefault is the default theme setting (follows system).
183const ThemeDefault = "default"
184
185const (
186 // ThemePreferDark explicitly selects dark theme.
187 ThemePreferDark = "prefer-dark"
188 // ThemePreferLight explicitly selects light theme.
189 ThemePreferLight = "prefer-light"
190)
191
192// MediaConfig holds video playback and hardware acceleration preferences.
193type MediaConfig struct {
194 // HardwareDecodingMode controls hardware vs software video decoding
195 // Values: "auto" (default), "force", "disable"
196 HardwareDecodingMode HardwareDecodingMode `mapstructure:"hardware_decoding" yaml:"hardware_decoding" toml:"hardware_decoding"`
197 // PreferAV1 prioritizes AV1 codec (most efficient) when available
198 PreferAV1 bool `mapstructure:"prefer_av1" yaml:"prefer_av1" toml:"prefer_av1"`
199 // ShowDiagnosticsOnStartup shows media capability warnings at startup
200 ShowDiagnosticsOnStartup bool `mapstructure:"show_diagnostics" yaml:"show_diagnostics" toml:"show_diagnostics"`
201 // ForceVSync forces vertical sync for video playback (may help with tearing).
202 //
203 // Deprecated: moved to [engine.webkit]. Kept for read compatibility during migration.
204 ForceVSync bool `mapstructure:"force_vsync" yaml:"force_vsync" toml:"-"`
205 // GLRenderingMode controls OpenGL API selection for video rendering.
206 // Values: "auto" (default), "gles2", "gl3", "none"
207 //
208 // Deprecated: moved to [engine.webkit]. Kept for read compatibility during migration.
209 GLRenderingMode GLRenderingMode `mapstructure:"gl_rendering_mode" yaml:"gl_rendering_mode" toml:"-"`
210 // GStreamerDebugLevel sets GStreamer debug verbosity (0=off, 1-5=increasing verbosity).
211 //
212 // Deprecated: moved to [engine.webkit]. Kept for read compatibility during migration.
213 GStreamerDebugLevel int `mapstructure:"gstreamer_debug_level" yaml:"gstreamer_debug_level" toml:"-"`
214}
215
216// DatabaseConfig holds database-related configuration.
217type DatabaseConfig struct {
218 Path string `mapstructure:"path" yaml:"path" toml:"path"`
219}
220
221// HistoryConfig holds history-related configuration.
222type HistoryConfig struct {
223 MaxEntries int `mapstructure:"max_entries" yaml:"max_entries" toml:"max_entries"`
224 RetentionPeriodDays int `mapstructure:"retention_period_days" yaml:"retention_period_days" toml:"retention_period_days"`
225 CleanupIntervalDays int `mapstructure:"cleanup_interval_days" yaml:"cleanup_interval_days" toml:"cleanup_interval_days"`
226}
227
228// PerformanceConfig holds internal performance tuning options.
229// These are not exposed in dumb://config UI but can be set in config file.
230type PerformanceConfig struct {
231 // Profile selects a preset performance configuration.
232 // Values: "default" (no tuning), "lite" (low RAM), "balanced" (compatibility), "max" (heavy pages), "custom" (manual control)
233 // When profile is not "custom", individual tuning fields below are ignored and computed from the profile.
234 // Default: "default"
235 Profile PerformanceProfile `mapstructure:"profile" yaml:"profile" toml:"profile"`
236
237 // ZoomCacheSize is the number of domain zoom levels to cache in memory.
238 // Higher values reduce database queries but use more memory.
239 // Default: 256 domains (~20KB memory)
240 ZoomCacheSize int `mapstructure:"zoom_cache_size" yaml:"zoom_cache_size" toml:"zoom_cache_size"`
241
242 // WebViewPoolPrewarmCount is the number of WebViews to pre-create at startup.
243 // Higher values speed up initial tab creation but use more memory.
244 // Default: 4 (custom mode), computed from profile otherwise
245 WebViewPoolPrewarmCount int `mapstructure:"webview_pool_prewarm_count" yaml:"webview_pool_prewarm_count" toml:"webview_pool_prewarm_count"` //nolint:lll // struct tags must stay on one line
246
247 // --- Skia rendering threads (env vars) ---
248 // NOTE: Fields below only apply when Profile is "custom".
249 // SkiaCPUPaintingThreads sets WEBKIT_SKIA_CPU_PAINTING_THREADS.
250 // Default: 0 (unset, uses WebKit default)
251 SkiaCPUPaintingThreads int `mapstructure:"skia_cpu_painting_threads" yaml:"skia_cpu_painting_threads" toml:"skia_cpu_painting_threads"` //nolint:lll // struct tags must stay on one line
252
253 // SkiaGPUPaintingThreads sets WEBKIT_SKIA_GPU_PAINTING_THREADS.
254 // Default: -1 (unset). Value 0 disables GPU tile painting.
255 SkiaGPUPaintingThreads int `mapstructure:"skia_gpu_painting_threads" yaml:"skia_gpu_painting_threads" toml:"skia_gpu_painting_threads"` //nolint:lll // struct tags must stay on one line
256
257 // SkiaEnableCPURendering forces CPU rendering via WEBKIT_SKIA_ENABLE_CPU_RENDERING=1.
258 // Default: false
259 SkiaEnableCPURendering bool `mapstructure:"skia_enable_cpu_rendering" yaml:"skia_enable_cpu_rendering" toml:"skia_enable_cpu_rendering"` //nolint:lll // struct tags must stay on one line
260
261 // --- Web process memory pressure ---
262 // WebProcessMemoryLimitMB sets memory limit in MB for web processes.
263 // Default: 0 (unset, uses WebKit default: system RAM capped at 3GB)
264 WebProcessMemoryLimitMB int `mapstructure:"web_process_memory_limit_mb" yaml:"web_process_memory_limit_mb" toml:"web_process_memory_limit_mb"` //nolint:lll // struct tags must stay on one line
265
266 // WebProcessMemoryPollIntervalSec sets poll interval for memory checks.
267 // Default: 0 (unset, uses WebKit default: 30 seconds)
268 WebProcessMemoryPollIntervalSec float64 `mapstructure:"web_process_memory_poll_interval_sec" yaml:"web_process_memory_poll_interval_sec" toml:"web_process_memory_poll_interval_sec"` //nolint:lll // struct tags must stay on one line
269
270 // WebProcessMemoryConservativeThreshold sets threshold for conservative memory release.
271 // Valid: (0, 1). Default: 0 (unset, uses WebKit default: 0.33)
272 WebProcessMemoryConservativeThreshold float64 `mapstructure:"web_process_memory_conservative_threshold" yaml:"web_process_memory_conservative_threshold" toml:"web_process_memory_conservative_threshold"` //nolint:lll // struct tags must stay on one line
273
274 // WebProcessMemoryStrictThreshold sets threshold for strict memory release.
275 // Valid: (0, 1). Default: 0 (unset, uses WebKit default: 0.5)
276 WebProcessMemoryStrictThreshold float64 `mapstructure:"web_process_memory_strict_threshold" yaml:"web_process_memory_strict_threshold" toml:"web_process_memory_strict_threshold"` //nolint:lll // struct tags must stay on one line
277
278 // --- Network process memory pressure ---
279 // NetworkProcessMemoryLimitMB sets memory limit in MB for network process.
280 // Default: 0 (unset)
281 NetworkProcessMemoryLimitMB int `mapstructure:"network_process_memory_limit_mb" yaml:"network_process_memory_limit_mb" toml:"network_process_memory_limit_mb"` //nolint:lll // struct tags must stay on one line
282
283 // NetworkProcessMemoryPollIntervalSec sets poll interval for memory checks.
284 // Default: 0 (unset)
285 NetworkProcessMemoryPollIntervalSec float64 `mapstructure:"network_process_memory_poll_interval_sec" yaml:"network_process_memory_poll_interval_sec" toml:"network_process_memory_poll_interval_sec"` //nolint:lll // struct tags must stay on one line
286
287 // NetworkProcessMemoryConservativeThreshold sets threshold for conservative memory release.
288 // Valid: (0, 1). Default: 0 (unset)
289 NetworkProcessMemoryConservativeThreshold float64 `mapstructure:"network_process_memory_conservative_threshold" yaml:"network_process_memory_conservative_threshold" toml:"network_process_memory_conservative_threshold"` //nolint:lll // struct tags must stay on one line
290
291 // NetworkProcessMemoryStrictThreshold sets threshold for strict memory release.
292 // Valid: (0, 1). Default: 0 (unset)
293 NetworkProcessMemoryStrictThreshold float64 `mapstructure:"network_process_memory_strict_threshold" yaml:"network_process_memory_strict_threshold" toml:"network_process_memory_strict_threshold"` //nolint:lll // struct tags must stay on one line
294}
295
296// SearchShortcut represents a search shortcut configuration.
297type SearchShortcut struct {
298 URL string `mapstructure:"url" toml:"url" yaml:"url" json:"url"`
299 Description string `mapstructure:"description" toml:"description" yaml:"description" json:"description"`
300}
301
302// ShortcutURLs returns a simple map of shortcut keys to URL templates.
303// This is useful for passing to url.BuildSearchURL.
304func (c *Config) ShortcutURLs() map[string]string {
305 result := make(map[string]string, len(c.SearchShortcuts))
306 for key, shortcut := range c.SearchShortcuts {
307 result[key] = shortcut.URL
308 }
309 return result
310}
311
312// DmenuConfig holds dmenu/rofi integration configuration.
313type DmenuConfig struct {
314 MaxHistoryDays int `mapstructure:"max_history_days" yaml:"max_history_days" toml:"max_history_days"`
315 ShowVisitCount bool `mapstructure:"show_visit_count" yaml:"show_visit_count" toml:"show_visit_count"`
316 ShowLastVisited bool `mapstructure:"show_last_visited" yaml:"show_last_visited" toml:"show_last_visited"`
317 HistoryPrefix string `mapstructure:"history_prefix" yaml:"history_prefix" toml:"history_prefix"`
318 ShortcutPrefix string `mapstructure:"shortcut_prefix" yaml:"shortcut_prefix" toml:"shortcut_prefix"`
319 URLPrefix string `mapstructure:"url_prefix" yaml:"url_prefix" toml:"url_prefix"`
320 DateFormat string `mapstructure:"date_format" yaml:"date_format" toml:"date_format"`
321 SortByVisitCount bool `mapstructure:"sort_by_visit_count" yaml:"sort_by_visit_count" toml:"sort_by_visit_count"`
322}
323
324// LoggingConfig holds logging configuration.
325type LoggingConfig struct {
326 Level string `mapstructure:"level" yaml:"level" toml:"level"`
327 Format string `mapstructure:"format" yaml:"format" toml:"format"`
328 MaxAge int `mapstructure:"max_age" yaml:"max_age" toml:"max_age"`
329 MaxFiles int `mapstructure:"max_files" yaml:"max_files" toml:"max_files"`
330
331 // File output configuration
332 LogDir string `mapstructure:"log_dir" yaml:"log_dir" toml:"log_dir"`
333 EnableFileLog bool `mapstructure:"enable_file_log" yaml:"enable_file_log" toml:"enable_file_log"`
334
335 // Capture browser console to logs
336 CaptureConsole bool `mapstructure:"capture_console" yaml:"capture_console" toml:"capture_console" json:"capture_console"`
337
338 // Capture GTK4/WebKitGTK6 messages to session logs
339 CaptureGTKLogs bool `mapstructure:"capture_gtk_logs" yaml:"capture_gtk_logs" toml:"capture_gtk_logs" json:"capture_gtk_logs"`
340}
341
342// ContentFilteringConfig holds content filtering and ad blocking preferences
343type ContentFilteringConfig struct {
344 // Enabled controls whether ad blocking is active (default: true)
345 Enabled bool `mapstructure:"enabled" yaml:"enabled" toml:"enabled"`
346 // AutoUpdate controls whether filters are automatically updated (default: true)
347 AutoUpdate bool `mapstructure:"auto_update" yaml:"auto_update" toml:"auto_update"`
348 // Note: Filters are downloaded from bnema/ublock-webkit-filters GitHub releases
349 // Note: Whitelist is managed via database (content_whitelist table)
350}
351
352// ClipboardConfig holds clipboard-related behavior preferences
353type ClipboardConfig struct {
354 // AutoCopyOnSelection automatically copies selected text to clipboard (zellij-style).
355 // When enabled, selecting text in a webview immediately copies it to clipboard.
356 // Does not apply to text selection in input fields or textareas.
357 // Default: true
358 AutoCopyOnSelection bool `mapstructure:"auto_copy_on_selection" yaml:"auto_copy_on_selection" toml:"auto_copy_on_selection" json:"autoCopyOnSelection"` //nolint:lll // struct tags must stay on one line
359}
360
361// OmniboxConfig holds omnibox behavior preferences
362type OmniboxConfig struct {
363 // InitialBehavior controls what to show when omnibox opens with empty input
364 // Values: "recent" (recent visits), "most_visited" (most visited sites), "none" (nothing)
365 InitialBehavior OmniboxInitialBehavior `mapstructure:"initial_behavior" yaml:"initial_behavior" toml:"initial_behavior"`
366 // MostVisitedDays controls how many days of history are considered when initial behavior is most_visited.
367 // 0 means all history.
368 // Default: 30.
369 MostVisitedDays int `mapstructure:"most_visited_days" yaml:"most_visited_days" toml:"most_visited_days"`
370 // AutoOpenOnNewPane opens the omnibox automatically when a new pane is created.
371 // Default: false
372 AutoOpenOnNewPane bool `mapstructure:"auto_open_on_new_pane" yaml:"auto_open_on_new_pane" toml:"auto_open_on_new_pane"`
373}
374
375// DebugConfig holds debug and troubleshooting options
376type DebugConfig struct {
377 // Enable browser developer tools (F12, Inspect Element in context menu)
378 EnableDevTools bool `mapstructure:"enable_devtools" yaml:"enable_devtools" toml:"enable_devtools"`
379}
380
381// DownloadsConfig holds file download preferences.
382type DownloadsConfig struct {
383 // Path is the directory where downloads are saved.
384 // Empty string means use XDG_DOWNLOAD_DIR or ~/Downloads.
385 Path string `mapstructure:"path" yaml:"path" toml:"path"`
386}