v0.25.0 2e6c485

settings.go RawHistoryFolder

1package webkit
2
3import (
4	"context"
5	"sync"
6
7	"github.com/bnema/dumber/internal/infrastructure/config"
8	"github.com/bnema/dumber/internal/logging"
9	"github.com/bnema/puregotk-webkit/webkit"
10	"github.com/rs/zerolog"
11)
12
13// SettingsManager creates and manages WebKit Settings instances from config.
14type SettingsManager struct {
15	cfg *config.Config
16	mu  sync.RWMutex
17}
18
19// NewSettingsManager creates a new SettingsManager with the given config.
20func NewSettingsManager(ctx context.Context, cfg *config.Config) *SettingsManager {
21	log := logging.FromContext(ctx)
22	log.Debug().Msg("creating settings manager")
23	return &SettingsManager{
24		cfg: cfg,
25	}
26}
27
28// CreateSettings creates a new webkit.Settings instance configured from the current config.
29func (sm *SettingsManager) CreateSettings(ctx context.Context) *webkit.Settings {
30	log := logging.FromContext(ctx)
31
32	sm.mu.RLock()
33	cfg := sm.cfg
34	sm.mu.RUnlock()
35
36	settings := webkit.NewSettings()
37	if settings == nil {
38		log.Error().Msg("failed to create webkit settings")
39		return nil
40	}
41
42	sm.applySettings(ctx, settings, cfg)
43	return settings
44}
45
46// applySettings applies configuration to a webkit.Settings instance.
47func (sm *SettingsManager) applySettings(ctx context.Context, settings *webkit.Settings, cfg *config.Config) {
48	if sm == nil {
49		return
50	}
51	log := logging.FromContext(ctx)
52	applyJavaScriptSettings(settings)
53	applyFontSettings(settings, cfg)
54	applyRenderingSettings(settings, cfg)
55	applyDebugSettings(settings, cfg)
56	applyBrowsingSettings(settings)
57	applyMediaSettings(settings, cfg, log)
58	applyStorageSettings(settings)
59	applyUISettings(settings)
60	applyCanvasSettings(settings)
61	applyWebRTCSettings(settings)
62
63	log.Debug().
64		Str("sans_font", cfg.Appearance.SansFont).
65		Str("rendering_mode", string(cfg.Rendering.Mode)).
66		Bool("developer_extras", cfg.Debug.EnableDevTools).
67		Msg("settings applied")
68}
69
70func applyJavaScriptSettings(settings *webkit.Settings) {
71	settings.SetEnableJavascript(true)
72	settings.SetEnableJavascriptMarkup(true)
73}
74
75func applyFontSettings(settings *webkit.Settings, cfg *config.Config) {
76	if cfg.Appearance.SansFont != "" {
77		settings.SetDefaultFontFamily(cfg.Appearance.SansFont)
78		settings.SetSansSerifFontFamily(cfg.Appearance.SansFont)
79	}
80	if cfg.Appearance.SerifFont != "" {
81		settings.SetSerifFontFamily(cfg.Appearance.SerifFont)
82	}
83	if cfg.Appearance.MonospaceFont != "" {
84		settings.SetMonospaceFontFamily(cfg.Appearance.MonospaceFont)
85	}
86	if cfg.Appearance.DefaultFontSize > 0 {
87		settings.SetDefaultFontSize(uint32(cfg.Appearance.DefaultFontSize))
88	}
89}
90
91func applyRenderingSettings(settings *webkit.Settings, cfg *config.Config) {
92	switch cfg.Rendering.Mode {
93	case config.RenderingModeGPU:
94		settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyAlwaysValue)
95	case config.RenderingModeCPU:
96		settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyNeverValue)
97	case config.RenderingModeAuto:
98		settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyAlwaysValue)
99	}
100}
101
102func applyDebugSettings(settings *webkit.Settings, cfg *config.Config) {
103	settings.SetEnableDeveloperExtras(cfg.Debug.EnableDevTools)
104	settings.SetEnableWriteConsoleMessagesToStdout(cfg.Logging.CaptureConsole)
105	settings.SetDrawCompositingIndicators(cfg.Rendering.DrawCompositingIndicators)
106}
107
108func applyBrowsingSettings(settings *webkit.Settings) {
109	settings.SetEnableSmoothScrolling(true)
110	settings.SetEnablePageCache(true)
111	settings.SetEnableSiteSpecificQuirks(true)
112}
113
114func applyMediaSettings(settings *webkit.Settings, cfg *config.Config, log *zerolog.Logger) {
115	settings.SetEnableWebaudio(true)
116	settings.SetEnableWebgl(true)
117	settings.SetEnableMedia(true)
118	settings.SetEnableMediasource(true)
119	settings.SetEnableMediaCapabilities(true)
120	settings.SetEnableMediaStream(true)
121	settings.SetEnableEncryptedMedia(true)
122	settings.SetMediaPlaybackRequiresUserGesture(true)
123	settings.SetMediaPlaybackAllowsInline(true)
124
125	switch cfg.Media.HardwareDecodingMode {
126	case config.HardwareDecodingForce:
127		hwTypes := "video/av01;video/mp4;video/webm;video/x-h264;video/x-h265"
128		settings.SetMediaContentTypesRequiringHardwareSupport(&hwTypes)
129		log.Debug().Msg("hardware decoding: forced (may fail without hw support)")
130	case config.HardwareDecodingDisable:
131		settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyNeverValue)
132		log.Debug().Msg("hardware decoding: disabled (software only)")
133	default:
134		emptyTypes := ""
135		settings.SetMediaContentTypesRequiringHardwareSupport(&emptyTypes)
136		log.Debug().Msg("hardware decoding: auto (hw preferred, software fallback)")
137	}
138}
139
140func applyStorageSettings(settings *webkit.Settings) {
141	settings.SetEnableHtml5LocalStorage(true)
142	settings.SetEnableHtml5Database(true)
143}
144
145func applyUISettings(settings *webkit.Settings) {
146	settings.SetEnableBackForwardNavigationGestures(true)
147	settings.SetEnableFullscreen(true)
148}
149
150func applyCanvasSettings(settings *webkit.Settings) {
151	settings.SetEnable2dCanvasAcceleration(true)
152}
153
154func applyWebRTCSettings(settings *webkit.Settings) {
155	settings.SetEnableWebrtc(true)
156}
157
158// UpdateFromConfig updates the manager with a new config (for hot-reload).
159// Note: This doesn't update already-created Settings instances.
160// New WebViews will use the updated config.
161func (sm *SettingsManager) UpdateFromConfig(ctx context.Context, cfg *config.Config) {
162	log := logging.FromContext(ctx)
163	sm.mu.Lock()
164	defer sm.mu.Unlock()
165	sm.cfg = cfg
166	log.Debug().Msg("settings config updated")
167}
168
169// ApplyToWebView applies current settings to an existing WebView.
170// This can be used to update a WebView's settings after config hot-reload.
171func (sm *SettingsManager) ApplyToWebView(ctx context.Context, wv *webkit.WebView) {
172	if wv == nil {
173		return
174	}
175
176	settings := sm.CreateSettings(ctx)
177	if settings == nil {
178		return
179	}
180
181	// WebView.GetSettings() returns the current settings - we can modify them directly
182	// For a full replacement, we'd need webkit_web_view_set_settings which may not be available
183	// Instead, we apply to the existing settings object
184	existingSettings := wv.GetSettings()
185	if existingSettings != nil {
186		sm.mu.RLock()
187		cfg := sm.cfg
188		sm.mu.RUnlock()
189		sm.applySettings(ctx, existingSettings, cfg)
190	}
191}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close