webui_config.go RawHistoryFolder
1package dto
2
3import "github.com/bnema/dumber/internal/domain/entity"
4
5// WebUIConfig represents the subset of configuration editable in dumb://config.
6type WebUIConfig struct {
7 Appearance WebUIAppearanceConfig `json:"appearance"`
8 Performance WebUIPerformanceConfig `json:"performance"`
9 DefaultUIScale float64 `json:"default_ui_scale"`
10 DefaultSearchEngine string `json:"default_search_engine"`
11 SearchShortcuts map[string]SearchShortcut `json:"search_shortcuts"`
12}
13
14// SystemviewCustomPerformancePayload is the editable custom performance profile shape.
15type SystemviewCustomPerformancePayload = WebUICustomPerformanceConfig
16
17// SystemviewResolvedPerformancePayload is the resolved effective performance shape.
18type SystemviewResolvedPerformancePayload struct {
19 SkiaCPUThreads int `json:"skia_cpu_threads"`
20 SkiaGPUThreads int `json:"skia_gpu_threads"`
21 WebProcessMemoryMB int `json:"web_process_memory_mb"`
22 NetworkProcessMemoryMB int `json:"network_process_memory_mb"`
23 WebViewPoolPrewarm int `json:"webview_pool_prewarm"`
24 ConservativeThreshold float64 `json:"conservative_threshold"`
25 StrictThreshold float64 `json:"strict_threshold"`
26}
27
28// SystemviewHardwarePayload exposes detected hardware to the settings UI.
29type SystemviewHardwarePayload struct {
30 CPUCores int `json:"cpu_cores"`
31 CPUThreads int `json:"cpu_threads"`
32 TotalRAMMB int `json:"total_ram_mb"`
33 GPUVendor string `json:"gpu_vendor"`
34 GPUName string `json:"gpu_name"`
35 VRAMMB int `json:"vram_mb"`
36}
37
38// SystemviewPerformancePayload is the performance tab payload expected by the UI.
39type SystemviewPerformancePayload struct {
40 Profile string `json:"profile"`
41 Custom SystemviewCustomPerformancePayload `json:"custom"`
42 Resolved SystemviewResolvedPerformancePayload `json:"resolved"`
43 Hardware SystemviewHardwarePayload `json:"hardware"`
44}
45
46// SystemviewConfigPayload is the full JSON shape expected by dumb://config.
47type SystemviewConfigPayload struct {
48 // Appearance is the editable config snapshot.
49 Appearance WebUIAppearanceConfig `json:"appearance"`
50 // ResolvedAppearance is optional, display-only appearance resolved from config
51 // plus external theme sources. Forms must save Appearance, never this field.
52 ResolvedAppearance *WebUIAppearanceConfig `json:"resolved_appearance,omitempty"`
53 Performance SystemviewPerformancePayload `json:"performance"`
54 DefaultUIScale float64 `json:"default_ui_scale"`
55 DefaultSearchEngine string `json:"default_search_engine"`
56 SearchShortcuts map[string]SearchShortcut `json:"search_shortcuts"`
57 EngineType string `json:"engine_type"`
58}
59
60// WebUIPerformanceConfig represents performance settings editable in dumb://config.
61type WebUIPerformanceConfig struct {
62 Profile string `json:"profile"`
63 Custom WebUICustomPerformanceConfig `json:"custom"`
64}
65
66// WebUICustomPerformanceConfig holds user-editable fields for custom profile.
67type WebUICustomPerformanceConfig struct {
68 SkiaCPUThreads int `json:"skia_cpu_threads"`
69 SkiaGPUThreads int `json:"skia_gpu_threads"`
70 WebProcessMemoryMB int `json:"web_process_memory_mb"`
71 NetworkProcessMemoryMB int `json:"network_process_memory_mb"`
72 WebViewPoolPrewarm int `json:"webview_pool_prewarm"`
73}
74
75type WebUIAppearanceConfig = entity.AppearanceConfig
76
77type WebUIExternalThemeConfig = entity.ExternalThemeConfig
78
79type ColorPalette = entity.ColorPalette
80
81type SearchShortcut struct {
82 URL string `json:"url"`
83 Description string `json:"description"`
84}
85
86// WebUIAppearanceWithResolvedTheme builds a display-only appearance payload from
87// resolved theme values while preserving fields that are not theme-resolution
88// outputs, such as ColorScheme and ExternalTheme.
89func WebUIAppearanceWithResolvedTheme(base WebUIAppearanceConfig, resolved entity.ResolvedTheme) WebUIAppearanceConfig {
90 base.SansFont = resolved.Fonts.SansFont
91 base.SerifFont = resolved.Fonts.SerifFont
92 base.MonospaceFont = resolved.Fonts.MonospaceFont
93 base.GtkFont = resolved.Fonts.GtkFont
94 base.DefaultFontSize = resolved.Fonts.DefaultSize
95 base.LightPalette = resolved.LightPalette
96 base.DarkPalette = resolved.DarkPalette
97 return base
98}