detached 401b02c

refactor(webkit-settings): pass context as first parameter instead of storing

Remove stored ctx field from SettingsManager and update all methods
(CreateSettings, applySettings, UpdateFromConfig, ApplyToWebView) to
accept context as first parameter, following project convention of using
log := logging.FromContext(ctx) in each method.
commit
401b02cd15abebcdc79a9e0e2bf6a0cf891efa85
author
brice · · 2025-12-17 06:44 UTC
parent
b106e60
signature
unsigned
1 file · +12 -12
M internal/infrastructure/webkit/settings.go +12 -12
@@ -12,21 +12,21 @@ import (
1212 // SettingsManager creates and manages WebKit Settings instances from config.
1313 type SettingsManager struct {
1414 cfg *config.Config
15- ctx context.Context
1615 mu sync.RWMutex
1716 }
1817
1918 // NewSettingsManager creates a new SettingsManager with the given config.
2019 func NewSettingsManager(ctx context.Context, cfg *config.Config) *SettingsManager {
20+ log := logging.FromContext(ctx)
21+ log.Debug().Msg("creating settings manager")
2122 return &SettingsManager{
2223 cfg: cfg,
23- ctx: logging.WithComponent(ctx, "webkit-settings"),
2424 }
2525 }
2626
2727 // CreateSettings creates a new webkit.Settings instance configured from the current config.
28-func (sm *SettingsManager) CreateSettings() *webkit.Settings {
29- log := logging.FromContext(sm.ctx)
28+func (sm *SettingsManager) CreateSettings(ctx context.Context) *webkit.Settings {
29+ log := logging.FromContext(ctx)
3030
3131 sm.mu.RLock()
3232 cfg := sm.cfg
@@ -38,12 +38,13 @@ func (sm *SettingsManager) CreateSettings() *webkit.Settings {
3838 return nil
3939 }
4040
41- sm.applySettings(settings, cfg)
41+ sm.applySettings(ctx, settings, cfg)
4242 return settings
4343 }
4444
4545 // applySettings applies configuration to a webkit.Settings instance.
46-func (sm *SettingsManager) applySettings(settings *webkit.Settings, cfg *config.Config) {
46+func (sm *SettingsManager) applySettings(ctx context.Context, settings *webkit.Settings, cfg *config.Config) {
47+ log := logging.FromContext(ctx)
4748 // JavaScript settings
4849 settings.SetEnableJavascript(true)
4950 settings.SetEnableJavascriptMarkup(true)
@@ -108,7 +109,6 @@ func (sm *SettingsManager) applySettings(settings *webkit.Settings, cfg *config.
108109 // WebRTC
109110 settings.SetEnableWebrtc(true)
110111
111- log := logging.FromContext(sm.ctx)
112112 log.Debug().
113113 Str("sans_font", cfg.Appearance.SansFont).
114114 Str("rendering_mode", string(cfg.RenderingMode)).
@@ -119,8 +119,8 @@ func (sm *SettingsManager) applySettings(settings *webkit.Settings, cfg *config.
119119 // UpdateFromConfig updates the manager with a new config (for hot-reload).
120120 // Note: This doesn't update already-created Settings instances.
121121 // New WebViews will use the updated config.
122-func (sm *SettingsManager) UpdateFromConfig(cfg *config.Config) {
123- log := logging.FromContext(sm.ctx)
122+func (sm *SettingsManager) UpdateFromConfig(ctx context.Context, cfg *config.Config) {
123+ log := logging.FromContext(ctx)
124124 sm.mu.Lock()
125125 defer sm.mu.Unlock()
126126 sm.cfg = cfg
@@ -129,12 +129,12 @@ func (sm *SettingsManager) UpdateFromConfig(cfg *config.Config) {
129129
130130 // ApplyToWebView applies current settings to an existing WebView.
131131 // This can be used to update a WebView's settings after config hot-reload.
132-func (sm *SettingsManager) ApplyToWebView(wv *webkit.WebView) {
132+func (sm *SettingsManager) ApplyToWebView(ctx context.Context, wv *webkit.WebView) {
133133 if wv == nil {
134134 return
135135 }
136136
137- settings := sm.CreateSettings()
137+ settings := sm.CreateSettings(ctx)
138138 if settings == nil {
139139 return
140140 }
@@ -147,6 +147,6 @@ func (sm *SettingsManager) ApplyToWebView(wv *webkit.WebView) {
147147 sm.mu.RLock()
148148 cfg := sm.cfg
149149 sm.mu.RUnlock()
150- sm.applySettings(existingSettings, cfg)
150+ sm.applySettings(ctx, existingSettings, cfg)
151151 }
152152 }
@@ -12,21 +12,21 @@ import (
12 // SettingsManager creates and manages WebKit Settings instances from config.12 // SettingsManager creates and manages WebKit Settings instances from config.
13 type SettingsManager struct {13 type SettingsManager struct {
14 cfg *config.Config14 cfg *config.Config
15- ctx context.Context
16 mu sync.RWMutex15 mu sync.RWMutex
17 }16 }
18 17
19 // NewSettingsManager creates a new SettingsManager with the given config.18 // NewSettingsManager creates a new SettingsManager with the given config.
20 func NewSettingsManager(ctx context.Context, cfg *config.Config) *SettingsManager {19 func NewSettingsManager(ctx context.Context, cfg *config.Config) *SettingsManager {
20+ log := logging.FromContext(ctx)
21+ log.Debug().Msg("creating settings manager")
21 return &SettingsManager{22 return &SettingsManager{
22 cfg: cfg,23 cfg: cfg,
23- ctx: logging.WithComponent(ctx, "webkit-settings"),
24 }24 }
25 }25 }
26 26
27 // CreateSettings creates a new webkit.Settings instance configured from the current config.27 // CreateSettings creates a new webkit.Settings instance configured from the current config.
28-func (sm *SettingsManager) CreateSettings() *webkit.Settings {28+func (sm *SettingsManager) CreateSettings(ctx context.Context) *webkit.Settings {
29- log := logging.FromContext(sm.ctx)29+ log := logging.FromContext(ctx)
30 30
31 sm.mu.RLock()31 sm.mu.RLock()
32 cfg := sm.cfg32 cfg := sm.cfg
@@ -38,12 +38,13 @@ func (sm *SettingsManager) CreateSettings() *webkit.Settings {
38 return nil38 return nil
39 }39 }
40 40
41- sm.applySettings(settings, cfg)41+ sm.applySettings(ctx, settings, cfg)
42 return settings42 return settings
43 }43 }
44 44
45 // applySettings applies configuration to a webkit.Settings instance.45 // applySettings applies configuration to a webkit.Settings instance.
46-func (sm *SettingsManager) applySettings(settings *webkit.Settings, cfg *config.Config) {46+func (sm *SettingsManager) applySettings(ctx context.Context, settings *webkit.Settings, cfg *config.Config) {
47+ log := logging.FromContext(ctx)
47 // JavaScript settings48 // JavaScript settings
48 settings.SetEnableJavascript(true)49 settings.SetEnableJavascript(true)
49 settings.SetEnableJavascriptMarkup(true)50 settings.SetEnableJavascriptMarkup(true)
@@ -108,7 +109,6 @@ func (sm *SettingsManager) applySettings(settings *webkit.Settings, cfg *config.
108 // WebRTC109 // WebRTC
109 settings.SetEnableWebrtc(true)110 settings.SetEnableWebrtc(true)
110 111
111- log := logging.FromContext(sm.ctx)
112 log.Debug().112 log.Debug().
113 Str("sans_font", cfg.Appearance.SansFont).113 Str("sans_font", cfg.Appearance.SansFont).
114 Str("rendering_mode", string(cfg.RenderingMode)).114 Str("rendering_mode", string(cfg.RenderingMode)).
@@ -119,8 +119,8 @@ func (sm *SettingsManager) applySettings(settings *webkit.Settings, cfg *config.
119 // UpdateFromConfig updates the manager with a new config (for hot-reload).119 // UpdateFromConfig updates the manager with a new config (for hot-reload).
120 // Note: This doesn't update already-created Settings instances.120 // Note: This doesn't update already-created Settings instances.
121 // New WebViews will use the updated config.121 // New WebViews will use the updated config.
122-func (sm *SettingsManager) UpdateFromConfig(cfg *config.Config) {122+func (sm *SettingsManager) UpdateFromConfig(ctx context.Context, cfg *config.Config) {
123- log := logging.FromContext(sm.ctx)123+ log := logging.FromContext(ctx)
124 sm.mu.Lock()124 sm.mu.Lock()
125 defer sm.mu.Unlock()125 defer sm.mu.Unlock()
126 sm.cfg = cfg126 sm.cfg = cfg
@@ -129,12 +129,12 @@ func (sm *SettingsManager) UpdateFromConfig(cfg *config.Config) {
129 129
130 // ApplyToWebView applies current settings to an existing WebView.130 // ApplyToWebView applies current settings to an existing WebView.
131 // This can be used to update a WebView's settings after config hot-reload.131 // This can be used to update a WebView's settings after config hot-reload.
132-func (sm *SettingsManager) ApplyToWebView(wv *webkit.WebView) {132+func (sm *SettingsManager) ApplyToWebView(ctx context.Context, wv *webkit.WebView) {
133 if wv == nil {133 if wv == nil {
134 return134 return
135 }135 }
136 136
137- settings := sm.CreateSettings()137+ settings := sm.CreateSettings(ctx)
138 if settings == nil {138 if settings == nil {
139 return139 return
140 }140 }
@@ -147,6 +147,6 @@ func (sm *SettingsManager) ApplyToWebView(wv *webkit.WebView) {
147 sm.mu.RLock()147 sm.mu.RLock()
148 cfg := sm.cfg148 cfg := sm.cfg
149 sm.mu.RUnlock()149 sm.mu.RUnlock()
150- sm.applySettings(existingSettings, cfg)150+ sm.applySettings(ctx, existingSettings, cfg)
151 }151 }
152 }152 }

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