refactor(coordinator): decouple navigation.go and tab.go from webkit
- commit
- 4cbf000ca6b87a02de8ed855e7b526694f1d1881
- author
- brice · · 2026-03-15 16:44 UTC
- parent
- bcab118
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +13 -13
M internal/ui/coordinator/navigation.go +8 -8
| @@ -5,9 +5,9 @@ import ( | |||
| 5 | 5 | "fmt" | |
| 6 | 6 | "time" | |
| 7 | 7 | ||
| 8 | + | "github.com/bnema/dumber/internal/application/port" | |
| 8 | 9 | "github.com/bnema/dumber/internal/application/usecase" | |
| 9 | 10 | "github.com/bnema/dumber/internal/domain/entity" | |
| 10 | - | "github.com/bnema/dumber/internal/infrastructure/webkit" | |
| 11 | 11 | "github.com/bnema/dumber/internal/logging" | |
| 12 | 12 | ) | |
| 13 | 13 | ||
| @@ -210,9 +210,9 @@ func (c *NavigationCoordinator) OpenDevTools(ctx context.Context) error { | |||
| 210 | 210 | ||
| 211 | 211 | log.Debug().Uint64("webview_id", uint64(wv.ID())).Msg("opening devtools") | |
| 212 | 212 | ||
| 213 | - | // Type assert to access ShowDevTools (not in port.WebView interface) | |
| 214 | - | if webkitWV, ok := interface{}(wv).(*webkit.WebView); ok { | |
| 215 | - | return webkitWV.ShowDevTools() | |
| 213 | + | if opener, ok := wv.(port.DevToolsOpener); ok { | |
| 214 | + | opener.OpenDevTools() | |
| 215 | + | return nil | |
| 216 | 216 | } | |
| 217 | 217 | ||
| 218 | 218 | return fmt.Errorf("webview does not support devtools") | |
| @@ -230,9 +230,9 @@ func (c *NavigationCoordinator) PrintPage(ctx context.Context) error { | |||
| 230 | 230 | ||
| 231 | 231 | log.Debug().Uint64("webview_id", uint64(wv.ID())).Msg("opening print dialog") | |
| 232 | 232 | ||
| 233 | - | // Type assert to access Print (not in port.WebView interface) | |
| 234 | - | if webkitWV, ok := interface{}(wv).(*webkit.WebView); ok { | |
| 235 | - | return webkitWV.Print() | |
| 233 | + | if printer, ok := wv.(port.Printer); ok { | |
| 234 | + | printer.PrintPage() | |
| 235 | + | return nil | |
| 236 | 236 | } | |
| 237 | 237 | ||
| 238 | 238 | return fmt.Errorf("webview does not support printing") | |
| @@ -269,7 +269,7 @@ func (c *NavigationCoordinator) ClearPaneHistory(paneID entity.PaneID) { | |||
| 269 | 269 | } | |
| 270 | 270 | ||
| 271 | 271 | // ActiveWebView returns the WebView for the active pane (for zoom operations). | |
| 272 | - | func (c *NavigationCoordinator) ActiveWebView(ctx context.Context) *webkit.WebView { | |
| 272 | + | func (c *NavigationCoordinator) ActiveWebView(ctx context.Context) port.WebView { | |
| 273 | 273 | return c.contentCoord.ActiveWebView(ctx) | |
| 274 | 274 | } | |
| 275 | 275 | ||
| @@ -5,9 +5,9 @@ import ( | |||||
| 5 | "fmt" | 5 | "fmt" | ||
| 6 | "time" | 6 | "time" | ||
| 7 | 7 | ||||
| 8 | + | "github.com/bnema/dumber/internal/application/port" | |||
| 8 | "github.com/bnema/dumber/internal/application/usecase" | 9 | "github.com/bnema/dumber/internal/application/usecase" | ||
| 9 | "github.com/bnema/dumber/internal/domain/entity" | 10 | "github.com/bnema/dumber/internal/domain/entity" | ||
| 10 | - | "github.com/bnema/dumber/internal/infrastructure/webkit" | |||
| 11 | "github.com/bnema/dumber/internal/logging" | 11 | "github.com/bnema/dumber/internal/logging" | ||
| 12 | ) | 12 | ) | ||
| 13 | 13 | ||||
| @@ -210,9 +210,9 @@ func (c *NavigationCoordinator) OpenDevTools(ctx context.Context) error { | |||||
| 210 | 210 | ||||
| 211 | log.Debug().Uint64("webview_id", uint64(wv.ID())).Msg("opening devtools") | 211 | log.Debug().Uint64("webview_id", uint64(wv.ID())).Msg("opening devtools") | ||
| 212 | 212 | ||||
| 213 | - | // Type assert to access ShowDevTools (not in port.WebView interface) | 213 | + | if opener, ok := wv.(port.DevToolsOpener); ok { |
| 214 | - | if webkitWV, ok := interface{}(wv).(*webkit.WebView); ok { | 214 | + | opener.OpenDevTools() |
| 215 | - | return webkitWV.ShowDevTools() | 215 | + | return nil |
| 216 | } | 216 | } | ||
| 217 | 217 | ||||
| 218 | return fmt.Errorf("webview does not support devtools") | 218 | return fmt.Errorf("webview does not support devtools") | ||
| @@ -230,9 +230,9 @@ func (c *NavigationCoordinator) PrintPage(ctx context.Context) error { | |||||
| 230 | 230 | ||||
| 231 | log.Debug().Uint64("webview_id", uint64(wv.ID())).Msg("opening print dialog") | 231 | log.Debug().Uint64("webview_id", uint64(wv.ID())).Msg("opening print dialog") | ||
| 232 | 232 | ||||
| 233 | - | // Type assert to access Print (not in port.WebView interface) | 233 | + | if printer, ok := wv.(port.Printer); ok { |
| 234 | - | if webkitWV, ok := interface{}(wv).(*webkit.WebView); ok { | 234 | + | printer.PrintPage() |
| 235 | - | return webkitWV.Print() | 235 | + | return nil |
| 236 | } | 236 | } | ||
| 237 | 237 | ||||
| 238 | return fmt.Errorf("webview does not support printing") | 238 | return fmt.Errorf("webview does not support printing") | ||
| @@ -269,7 +269,7 @@ func (c *NavigationCoordinator) ClearPaneHistory(paneID entity.PaneID) { | |||||
| 269 | } | 269 | } | ||
| 270 | 270 | ||||
| 271 | // ActiveWebView returns the WebView for the active pane (for zoom operations). | 271 | // ActiveWebView returns the WebView for the active pane (for zoom operations). | ||
| 272 | - | func (c *NavigationCoordinator) ActiveWebView(ctx context.Context) *webkit.WebView { | 272 | + | func (c *NavigationCoordinator) ActiveWebView(ctx context.Context) port.WebView { |
| 273 | return c.contentCoord.ActiveWebView(ctx) | 273 | return c.contentCoord.ActiveWebView(ctx) | ||
| 274 | } | 274 | } | ||
| 275 | 275 | ||||
M internal/ui/coordinator/tab.go +5 -5
| @@ -3,10 +3,10 @@ package coordinator | |||
| 3 | 3 | import ( | |
| 4 | 4 | "context" | |
| 5 | 5 | ||
| 6 | + | "github.com/bnema/dumber/internal/application/port" | |
| 6 | 7 | "github.com/bnema/dumber/internal/application/usecase" | |
| 7 | 8 | "github.com/bnema/dumber/internal/domain/entity" | |
| 8 | 9 | "github.com/bnema/dumber/internal/infrastructure/config" | |
| 9 | - | "github.com/bnema/dumber/internal/infrastructure/webkit" | |
| 10 | 10 | "github.com/bnema/dumber/internal/logging" | |
| 11 | 11 | "github.com/bnema/dumber/internal/ui/component" | |
| 12 | 12 | "github.com/bnema/dumber/internal/ui/window" | |
| @@ -23,8 +23,8 @@ type TabCoordinator struct { | |||
| 23 | 23 | onTabCreated func(ctx context.Context, tab *entity.Tab) | |
| 24 | 24 | onTabSwitched func(ctx context.Context, tab *entity.Tab) | |
| 25 | 25 | onQuit func() | |
| 26 | - | onAttachPopupToTab func(ctx context.Context, tabID entity.TabID, pane *entity.Pane, wv *webkit.WebView) // For popup tabs | |
| 27 | - | onStateChanged func() // For session snapshots | |
| 26 | + | onAttachPopupToTab func(ctx context.Context, tabID entity.TabID, pane *entity.Pane, wv port.WebView) // For popup tabs | |
| 27 | + | onStateChanged func() // For session snapshots | |
| 28 | 28 | } | |
| 29 | 29 | ||
| 30 | 30 | // TabCoordinatorConfig holds configuration for TabCoordinator. | |
| @@ -335,7 +335,7 @@ func (c *TabCoordinator) GetTabBar() *component.TabBar { | |||
| 335 | 335 | } | |
| 336 | 336 | ||
| 337 | 337 | // SetOnAttachPopupToTab sets the callback for attaching popup WebViews to tabs. | |
| 338 | - | func (c *TabCoordinator) SetOnAttachPopupToTab(fn func(ctx context.Context, tabID entity.TabID, pane *entity.Pane, wv *webkit.WebView)) { | |
| 338 | + | func (c *TabCoordinator) SetOnAttachPopupToTab(fn func(ctx context.Context, tabID entity.TabID, pane *entity.Pane, wv port.WebView)) { | |
| 339 | 339 | c.onAttachPopupToTab = fn | |
| 340 | 340 | } | |
| 341 | 341 | ||
| @@ -344,7 +344,7 @@ func (c *TabCoordinator) SetOnAttachPopupToTab(fn func(ctx context.Context, tabI | |||
| 344 | 344 | func (c *TabCoordinator) CreateWithPane( | |
| 345 | 345 | ctx context.Context, | |
| 346 | 346 | pane *entity.Pane, | |
| 347 | - | wv *webkit.WebView, | |
| 347 | + | wv port.WebView, | |
| 348 | 348 | initialURL string, | |
| 349 | 349 | ) (*entity.Tab, error) { | |
| 350 | 350 | log := logging.FromContext(ctx) | |
| @@ -3,10 +3,10 @@ package coordinator | |||||
| 3 | import ( | 3 | import ( | ||
| 4 | "context" | 4 | "context" | ||
| 5 | 5 | ||||
| 6 | + | "github.com/bnema/dumber/internal/application/port" | |||
| 6 | "github.com/bnema/dumber/internal/application/usecase" | 7 | "github.com/bnema/dumber/internal/application/usecase" | ||
| 7 | "github.com/bnema/dumber/internal/domain/entity" | 8 | "github.com/bnema/dumber/internal/domain/entity" | ||
| 8 | "github.com/bnema/dumber/internal/infrastructure/config" | 9 | "github.com/bnema/dumber/internal/infrastructure/config" | ||
| 9 | - | "github.com/bnema/dumber/internal/infrastructure/webkit" | |||
| 10 | "github.com/bnema/dumber/internal/logging" | 10 | "github.com/bnema/dumber/internal/logging" | ||
| 11 | "github.com/bnema/dumber/internal/ui/component" | 11 | "github.com/bnema/dumber/internal/ui/component" | ||
| 12 | "github.com/bnema/dumber/internal/ui/window" | 12 | "github.com/bnema/dumber/internal/ui/window" | ||
| @@ -23,8 +23,8 @@ type TabCoordinator struct { | |||||
| 23 | onTabCreated func(ctx context.Context, tab *entity.Tab) | 23 | onTabCreated func(ctx context.Context, tab *entity.Tab) | ||
| 24 | onTabSwitched func(ctx context.Context, tab *entity.Tab) | 24 | onTabSwitched func(ctx context.Context, tab *entity.Tab) | ||
| 25 | onQuit func() | 25 | onQuit func() | ||
| 26 | - | onAttachPopupToTab func(ctx context.Context, tabID entity.TabID, pane *entity.Pane, wv *webkit.WebView) // For popup tabs | 26 | + | onAttachPopupToTab func(ctx context.Context, tabID entity.TabID, pane *entity.Pane, wv port.WebView) // For popup tabs |
| 27 | - | onStateChanged func() // For session snapshots | 27 | + | onStateChanged func() // For session snapshots |
| 28 | } | 28 | } | ||
| 29 | 29 | ||||
| 30 | // TabCoordinatorConfig holds configuration for TabCoordinator. | 30 | // TabCoordinatorConfig holds configuration for TabCoordinator. | ||
| @@ -335,7 +335,7 @@ func (c *TabCoordinator) GetTabBar() *component.TabBar { | |||||
| 335 | } | 335 | } | ||
| 336 | 336 | ||||
| 337 | // SetOnAttachPopupToTab sets the callback for attaching popup WebViews to tabs. | 337 | // SetOnAttachPopupToTab sets the callback for attaching popup WebViews to tabs. | ||
| 338 | - | func (c *TabCoordinator) SetOnAttachPopupToTab(fn func(ctx context.Context, tabID entity.TabID, pane *entity.Pane, wv *webkit.WebView)) { | 338 | + | func (c *TabCoordinator) SetOnAttachPopupToTab(fn func(ctx context.Context, tabID entity.TabID, pane *entity.Pane, wv port.WebView)) { |
| 339 | c.onAttachPopupToTab = fn | 339 | c.onAttachPopupToTab = fn | ||
| 340 | } | 340 | } | ||
| 341 | 341 | ||||
| @@ -344,7 +344,7 @@ func (c *TabCoordinator) SetOnAttachPopupToTab(fn func(ctx context.Context, tabI | |||||
| 344 | func (c *TabCoordinator) CreateWithPane( | 344 | func (c *TabCoordinator) CreateWithPane( | ||
| 345 | ctx context.Context, | 345 | ctx context.Context, | ||
| 346 | pane *entity.Pane, | 346 | pane *entity.Pane, | ||
| 347 | - | wv *webkit.WebView, | 347 | + | wv port.WebView, |
| 348 | initialURL string, | 348 | initialURL string, | ||
| 349 | ) (*entity.Tab, error) { | 349 | ) (*entity.Tab, error) { | ||
| 350 | log := logging.FromContext(ctx) | 350 | log := logging.FromContext(ctx) | ||