fix: apply theme background early for webviews
- commit
- 79b3471de7538e82556ff392b6623115f6f71287
- author
- bnema · · 2025-12-28 11:59 UTC
- committer
- bnema · · 2025-12-28 11:59 UTC
- parent
- ddb81a0
- signature
- GPG Unverified
2B82207D370127A0The key is unknown
2 files · +13 -0
M internal/bootstrap/webkit_stack.go +3 -0
| @@ -111,6 +111,9 @@ func BuildWebKitStack( | |||
| 111 | 111 | poolCfg.PrewarmCount = cfg.Performance.WebViewPoolPrewarmCount | |
| 112 | 112 | } | |
| 113 | 113 | pool := webkit.NewWebViewPool(ctx, wkCtx, settings, poolCfg, injector, messageRouter) | |
| 114 | + | // Ensure prewarmed WebViews pick up the theme background color. | |
| 115 | + | bgR, bgG, bgB, bgA := themeManager.GetBackgroundRGBA() | |
| 116 | + | pool.SetBackgroundColor(bgR, bgG, bgB, bgA) | |
| 114 | 117 | ||
| 115 | 118 | if filterManager != nil { | |
| 116 | 119 | pool.SetFilterApplier(filterManager) | |
| @@ -111,6 +111,9 @@ func BuildWebKitStack( | |||||
| 111 | poolCfg.PrewarmCount = cfg.Performance.WebViewPoolPrewarmCount | 111 | poolCfg.PrewarmCount = cfg.Performance.WebViewPoolPrewarmCount | ||
| 112 | } | 112 | } | ||
| 113 | pool := webkit.NewWebViewPool(ctx, wkCtx, settings, poolCfg, injector, messageRouter) | 113 | pool := webkit.NewWebViewPool(ctx, wkCtx, settings, poolCfg, injector, messageRouter) | ||
| 114 | + | // Ensure prewarmed WebViews pick up the theme background color. | |||
| 115 | + | bgR, bgG, bgB, bgA := themeManager.GetBackgroundRGBA() | |||
| 116 | + | pool.SetBackgroundColor(bgR, bgG, bgB, bgA) | |||
| 114 | 117 | ||||
| 115 | if filterManager != nil { | 118 | if filterManager != nil { | ||
| 116 | pool.SetFilterApplier(filterManager) | 119 | pool.SetFilterApplier(filterManager) | ||
M internal/infrastructure/webkit/pool.go +10 -0
| @@ -126,6 +126,16 @@ func (p *WebViewPool) Acquire(ctx context.Context) (*WebView, error) { | |||
| 126 | 126 | select { | |
| 127 | 127 | case wv := <-p.pool: | |
| 128 | 128 | if wv != nil && !wv.IsDestroyed() { | |
| 129 | + | p.bgMu.RLock() | |
| 130 | + | r, g, b, a := p.bgR, p.bgG, p.bgB, p.bgA | |
| 131 | + | p.bgMu.RUnlock() | |
| 132 | + | if a > 0 { | |
| 133 | + | wv.SetBackgroundColor(r, g, b, a) | |
| 134 | + | } | |
| 135 | + | wv.inner.AddCssClass("webview-themed") | |
| 136 | + | // Keep pooled WebViews hidden until we explicitly reveal them. | |
| 137 | + | wv.inner.SetVisible(false) | |
| 138 | + | ||
| 129 | 139 | // Ensure frontend is attached even if this WebView was pooled before injection was configured. | |
| 130 | 140 | _ = wv.AttachFrontend(ctx, p.injector, p.router) | |
| 131 | 141 | // Apply filters if available (may not have been applied during prewarm) | |
| @@ -126,6 +126,16 @@ func (p *WebViewPool) Acquire(ctx context.Context) (*WebView, error) { | |||||
| 126 | select { | 126 | select { | ||
| 127 | case wv := <-p.pool: | 127 | case wv := <-p.pool: | ||
| 128 | if wv != nil && !wv.IsDestroyed() { | 128 | if wv != nil && !wv.IsDestroyed() { | ||
| 129 | + | p.bgMu.RLock() | |||
| 130 | + | r, g, b, a := p.bgR, p.bgG, p.bgB, p.bgA | |||
| 131 | + | p.bgMu.RUnlock() | |||
| 132 | + | if a > 0 { | |||
| 133 | + | wv.SetBackgroundColor(r, g, b, a) | |||
| 134 | + | } | |||
| 135 | + | wv.inner.AddCssClass("webview-themed") | |||
| 136 | + | // Keep pooled WebViews hidden until we explicitly reveal them. | |||
| 137 | + | wv.inner.SetVisible(false) | |||
| 138 | + | ||||
| 129 | // Ensure frontend is attached even if this WebView was pooled before injection was configured. | 139 | // Ensure frontend is attached even if this WebView was pooled before injection was configured. | ||
| 130 | _ = wv.AttachFrontend(ctx, p.injector, p.router) | 140 | _ = wv.AttachFrontend(ctx, p.injector, p.router) | ||
| 131 | // Apply filters if available (may not have been applied during prewarm) | 141 | // Apply filters if available (may not have been applied during prewarm) | ||