pane.go RawHistoryFolder
1package browser
2
3import (
4 "log"
5 "time"
6
7 "github.com/bnema/dumber/internal/app/control"
8 "github.com/bnema/dumber/internal/app/messaging"
9 "github.com/bnema/dumber/pkg/webkit"
10)
11
12// BrowserPane bundles the per-pane WebView and its controllers.
13type BrowserPane struct {
14 webView *webkit.WebView
15 navigationController *control.NavigationController
16 zoomController *control.ZoomController
17 clipboardController *control.ClipboardController
18 messageHandler *messaging.Handler
19 shortcutHandler *ShortcutHandler
20
21 // Multi-pane support
22 id string
23 hasGUI bool
24 guiComponents map[string]bool
25 lastFocusTime time.Time
26}
27
28func (p *BrowserPane) WebView() *webkit.WebView { return p.webView }
29
30func (p *BrowserPane) MessageHandler() *messaging.Handler { return p.messageHandler }
31
32func (p *BrowserPane) NavigationController() *control.NavigationController {
33 return p.navigationController
34}
35
36func (p *BrowserPane) ZoomController() *control.ZoomController { return p.zoomController }
37
38func (p *BrowserPane) ClipboardController() *control.ClipboardController {
39 return p.clipboardController
40}
41
42func (p *BrowserPane) ShortcutHandler() *ShortcutHandler { return p.shortcutHandler }
43
44// ID returns the unique pane identifier
45func (p *BrowserPane) ID() string { return p.id }
46
47// HasGUI returns whether GUI components are injected
48func (p *BrowserPane) HasGUI() bool { return p.hasGUI }
49
50// SetHasGUI marks GUI components as injected
51func (p *BrowserPane) SetHasGUI(has bool) { p.hasGUI = has }
52
53// SetID sets the pane identifier
54func (p *BrowserPane) SetID(id string) { p.id = id }
55
56// UpdateLastFocus updates the last focus time
57func (p *BrowserPane) UpdateLastFocus() { p.lastFocusTime = time.Now() }
58
59// Initialize GUI component tracking
60func (p *BrowserPane) initializeGUITracking() {
61 if p.guiComponents == nil {
62 p.guiComponents = make(map[string]bool)
63 }
64}
65
66// HasGUIComponent checks if a specific GUI component is loaded
67func (p *BrowserPane) HasGUIComponent(component string) bool {
68 if p.guiComponents == nil {
69 return false
70 }
71 return p.guiComponents[component]
72}
73
74// SetGUIComponent marks a GUI component as loaded
75func (p *BrowserPane) SetGUIComponent(component string, loaded bool) {
76 p.initializeGUITracking()
77 p.guiComponents[component] = loaded
78}
79
80// Cleanup releases pane resources
81func (p *BrowserPane) Cleanup() {
82 // Cleanup shortcuts
83 if p.shortcutHandler != nil {
84 // TODO: Add cleanup method to ShortcutHandler
85 log.Printf("[pane-%s] Cleaned up shortcuts", p.id)
86 }
87
88 // Notify JS to cleanup GUI
89 if p.webView != nil && p.hasGUI {
90 if err := p.webView.InjectScript(`
91 if (window.__dumber_gui_manager) {
92 window.__dumber_gui_manager.destroy();
93 }
94 `); err != nil {
95 log.Printf("[pane-%s] failed to inject cleanup script: %v", p.id, err)
96 }
97 }
98
99 // Clear tracking
100 p.guiComponents = nil
101 p.hasGUI = false
102}