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