1// Package config provides default configuration values for dumber.
2package config
3
4import (
5 "time"
6)
7
8// Default configuration constants
9const (
10 // Database defaults
11 defaultMaxIdleTimeMin = 5 // minutes
12 defaultQueryTimeoutSec = 30 // seconds
13
14 // History defaults
15 defaultMaxHistoryEntries = 10000 // entries
16 defaultRetentionDays = 365 // 1 year
17
18 // Dmenu defaults
19 defaultMaxHistoryItems = 20 // items
20
21 // Logging defaults
22 defaultMaxLogSizeMB = 100 // MB
23 defaultMaxBackups = 3 // backup files
24 defaultMaxLogAgeDays = 7 // days
25
26 // Appearance defaults
27 defaultFontSize = 16 // points
28)
29
30// getDefaultLogDir returns the default log directory, falls back to empty string on error
31func getDefaultLogDir() string {
32 logDir, err := GetLogDir()
33 if err != nil {
34 return ""
35 }
36 return logDir
37}
38
39// DefaultConfig returns the default configuration values for dumber.
40func DefaultConfig() *Config {
41 return &Config{
42 Database: DatabaseConfig{
43 MaxConnections: 1,
44 MaxIdleTime: time.Minute * defaultMaxIdleTimeMin,
45 QueryTimeout: time.Second * defaultQueryTimeoutSec,
46 },
47 History: HistoryConfig{
48 MaxEntries: defaultMaxHistoryEntries,
49 RetentionPeriodDays: defaultRetentionDays, // 1 year
50 CleanupIntervalDays: 1, // daily cleanup
51 },
52 SearchShortcuts: map[string]SearchShortcut{
53 "g": {
54 URL: "https://www.google.com/search?q=%s",
55 Description: "Google search",
56 },
57 "gh": {
58 URL: "https://github.com/search?q=%s",
59 Description: "GitHub search",
60 },
61 "yt": {
62 URL: "https://www.youtube.com/results?search_query=%s",
63 Description: "YouTube search",
64 },
65 "w": {
66 URL: "https://en.wikipedia.org/wiki/%s",
67 Description: "Wikipedia search",
68 },
69 },
70 Dmenu: DmenuConfig{
71 MaxHistoryItems: defaultMaxHistoryItems,
72 ShowVisitCount: true,
73 ShowLastVisited: true,
74 HistoryPrefix: "🕒",
75 ShortcutPrefix: "🔍",
76 URLPrefix: "🌐",
77 DateFormat: "2006-01-02 15:04",
78 SortByVisitCount: true,
79 },
80 Logging: LoggingConfig{
81 Level: "info",
82 Format: "text", // text or json
83 Filename: "", // empty means stdout
84 MaxSize: defaultMaxLogSizeMB, // MB
85 MaxBackups: defaultMaxBackups,
86 MaxAge: defaultMaxLogAgeDays, // days
87 Compress: true,
88 LogDir: getDefaultLogDir(),
89 EnableFileLog: true,
90 CaptureStdout: false,
91 CaptureStderr: false,
92 CaptureCOutput: false, // Disabled by default to avoid performance impact
93 DebugFile: "debug.log",
94 VerboseWebKit: false,
95 },
96 Appearance: AppearanceConfig{
97 SansFont: "Fira Sans",
98 SerifFont: "Fira Sans",
99 MonospaceFont: "Fira Code",
100 DefaultFontSize: defaultFontSize,
101 },
102 VideoAcceleration: VideoAccelerationConfig{
103 EnableVAAPI: true,
104 AutoDetectGPU: true,
105 VAAPIDriverName: "", // Will be auto-detected
106 EnableAllDrivers: true,
107 LegacyVAAPI: false,
108 },
109 CodecPreferences: CodecConfig{
110 PreferredCodecs: "av1,h264", // AV1 first, but allow VP9 fallback for higher resolutions
111 ForceAV1: false, // Use smart AV1 negotiation instead of forcing
112 BlockVP9: false, // Allow VP9 for higher resolutions
113 BlockVP8: true, // Still block VP8 as it's outdated
114 AV1HardwareOnly: false, // Allow software AV1 fallback
115 DisableVP9Hardware: false, // Allow VP9 hardware for high res content
116 VideoBufferSizeMB: 16, // Larger buffer for AV1 streams
117 QueueBufferTimeSec: 10, // More buffering time for smooth playback
118 CustomUserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", // Chrome UA with AV1 support
119 AV1MaxResolution: "1080p", // Optimal AV1 up to 1080p, fallback to VP9 for higher res
120 DisableTwitchCodecControl: true, // Disable codec control on Twitch by default (prevents theater/fullscreen freezing)
121 },
122 WebkitMemory: WebkitMemoryConfig{
123 CacheModel: "web_browser", // Aggressive caching for fast page loads
124 EnablePageCache: true, // Instant back/forward navigation
125 MemoryLimitMB: 0, // Use system default
126 ConservativeThreshold: 0.4, // Start cleanup at 40%
127 StrictThreshold: 0.6, // Strict cleanup at 60%
128 KillThreshold: 0.8, // Kill processes at 80%
129 PollIntervalSeconds: 45.0, // Check every 45 seconds
130 EnableGCInterval: 120, // GC every 2 minutes
131 ProcessRecycleThreshold: 50, // Recycle after 50 page loads
132 EnableMemoryMonitoring: true, // Monitor for production tuning
133 },
134 Debug: DebugConfig{
135 EnableWebKitDebug: false,
136 WebKitDebugCategories: "Network:preconnectTo,ContentFilters",
137 EnableFilteringDebug: false,
138 EnableWebViewDebug: false,
139 LogWebKitCrashes: true, // Always log crashes
140 EnableScriptDebug: false,
141 EnableGeneralDebug: false,
142 },
143 APISecurity: APISecurityConfig{
144 Token: "",
145 RequireToken: false,
146 },
147 RenderingMode: RenderingModeAuto,
148 }
149}
150
151// GetDefaultSearchShortcuts returns the default search shortcuts.
152func GetDefaultSearchShortcuts() map[string]SearchShortcut {
153 return map[string]SearchShortcut{
154 "g": {
155 URL: "https://www.google.com/search?q=%s",
156 Description: "Google search",
157 },
158 "gh": {
159 URL: "https://github.com/search?q=%s",
160 Description: "GitHub search",
161 },
162 "yt": {
163 URL: "https://www.youtube.com/results?search_query=%s",
164 Description: "YouTube search",
165 },
166 "w": {
167 URL: "https://en.wikipedia.org/wiki/%s",
168 Description: "Wikipedia search",
169 },
170 "ddg": {
171 URL: "https://duckduckgo.com/?q=%s",
172 Description: "DuckDuckGo search",
173 },
174 "so": {
175 URL: "https://stackoverflow.com/search?q=%s",
176 Description: "Stack Overflow search",
177 },
178 "r": {
179 URL: "https://www.reddit.com/search?q=%s",
180 Description: "Reddit search",
181 },
182 "npm": {
183 URL: "https://www.npmjs.com/search?q=%s",
184 Description: "npm package search",
185 },
186 "go": {
187 URL: "https://pkg.go.dev/search?q=%s",
188 Description: "Go package search",
189 },
190 "mdn": {
191 URL: "https://developer.mozilla.org/en-US/search?q=%s",
192 Description: "MDN Web Docs search",
193 },
194 }
195}
196
197// Note: We build our own browser, so no external browser commands needed