webui_gateway.go RawHistoryFolder
1package config
2
3import (
4 "context"
5 "fmt"
6
7 "github.com/bnema/dumber/internal/application/dto"
8)
9
10type WebUIConfigGateway struct {
11 mgr *Manager
12}
13
14func NewWebUIConfigGateway(mgr *Manager) *WebUIConfigGateway {
15 return &WebUIConfigGateway{mgr: mgr}
16}
17
18// SaveWebUIConfig maps an already validated and normalized WebUI config onto
19// the stored config and saves it. Policy lives in SaveWebUIConfigUseCase.
20func (g *WebUIConfigGateway) SaveWebUIConfig(ctx context.Context, cfg dto.WebUIConfig) error {
21 _ = ctx
22 if g == nil || g.mgr == nil {
23 return fmt.Errorf("config manager not initialized")
24 }
25
26 current := Get()
27 current.Appearance.SansFont = cfg.Appearance.SansFont
28 current.Appearance.SerifFont = cfg.Appearance.SerifFont
29 current.Appearance.MonospaceFont = cfg.Appearance.MonospaceFont
30 current.Appearance.GtkFont = cfg.Appearance.GtkFont
31 current.Appearance.DefaultFontSize = cfg.Appearance.DefaultFontSize
32 current.Appearance.ColorScheme = cfg.Appearance.ColorScheme
33 current.Appearance.LightPalette = ColorPalette{
34 Background: cfg.Appearance.LightPalette.Background,
35 Surface: cfg.Appearance.LightPalette.Surface,
36 SurfaceVariant: cfg.Appearance.LightPalette.SurfaceVariant,
37 Text: cfg.Appearance.LightPalette.Text,
38 Muted: cfg.Appearance.LightPalette.Muted,
39 Accent: cfg.Appearance.LightPalette.Accent,
40 Border: cfg.Appearance.LightPalette.Border,
41 }
42 current.Appearance.DarkPalette = ColorPalette{
43 Background: cfg.Appearance.DarkPalette.Background,
44 Surface: cfg.Appearance.DarkPalette.Surface,
45 SurfaceVariant: cfg.Appearance.DarkPalette.SurfaceVariant,
46 Text: cfg.Appearance.DarkPalette.Text,
47 Muted: cfg.Appearance.DarkPalette.Muted,
48 Accent: cfg.Appearance.DarkPalette.Accent,
49 Border: cfg.Appearance.DarkPalette.Border,
50 }
51 current.Appearance.ExternalTheme = cfg.Appearance.ExternalTheme
52 current.DefaultUIScale = cfg.DefaultUIScale
53 current.DefaultSearchEngine = cfg.DefaultSearchEngine
54 if len(cfg.SearchShortcuts) == 0 {
55 current.SearchShortcuts = nil
56 } else {
57 shortcuts := make(map[string]SearchShortcut, len(cfg.SearchShortcuts))
58 for key, shortcut := range cfg.SearchShortcuts {
59 shortcuts[key] = SearchShortcut{
60 URL: shortcut.URL,
61 Description: shortcut.Description,
62 }
63 }
64 current.SearchShortcuts = shortcuts
65 }
66
67 // Performance profile (requires restart to take effect)
68 if cfg.Performance.Profile != "" {
69 current.Engine.Profile = PerformanceProfile(cfg.Performance.Profile)
70 }
71
72 // Custom performance fields (only used when profile is "custom")
73 if cfg.Performance.Profile == string(ProfileCustom) {
74 custom := cfg.Performance.Custom
75 current.Engine.WebKit.SkiaCPUPaintingThreads = custom.SkiaCPUThreads
76 current.Engine.WebKit.SkiaGPUPaintingThreads = custom.SkiaGPUThreads
77 current.Engine.WebKit.WebProcessMemoryLimitMB = custom.WebProcessMemoryMB
78 current.Engine.WebKit.NetworkProcessMemoryLimitMB = custom.NetworkProcessMemoryMB
79 current.Engine.PoolPrewarmCount = custom.WebViewPoolPrewarm
80 }
81
82 return g.mgr.Save(current)
83}