fix(shortcuts): migrate window_shortcuts.go to gotk4 API
- Replace InitializeGlobalShortcuts() with NewWindowShortcuts() - Change RegisterGlobalShortcut() to RegisterShortcut() - Fix GetZoom() return value (no error return in gotk4) - Convert WebView IDs to string using IDString() helper: - getWebViewId() return value - close-popup message WebViewID field - Simplify Cleanup() (WindowShortcuts needs no explicit cleanup) Fixed 7 compilation errors in window-level keyboard shortcuts.
- commit
- 2ffecd946497160f8674ea4399d7eb13f77d9254
- author
- bamen · · 2025-10-08 19:38 UTC
- committer
- bamen · · 2025-10-08 17:37 UTC
- parent
- 042e3de
- signature
- unsigned
1 file · +8 -18
M internal/app/browser/window_shortcuts.go +8 -18
| @@ -41,8 +41,8 @@ func NewWindowShortcutHandler(window *webkit.Window, app *BrowserApp) *WindowSho | |||
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | 43 | func (h *WindowShortcutHandler) initialize() error { | |
| 44 | - | // Initialize GTK4 global shortcuts | |
| 45 | - | h.shortcuts = h.window.InitializeGlobalShortcuts() | |
| 44 | + | // Create WindowShortcuts manager | |
| 45 | + | h.shortcuts = webkit.NewWindowShortcuts(h.window) | |
| 46 | 46 | if h.shortcuts == nil { | |
| 47 | 47 | return ErrFailedToInitialize | |
| 48 | 48 | } | |
| @@ -75,11 +75,7 @@ func (h *WindowShortcutHandler) registerGlobalShortcuts() error { | |||
| 75 | 75 | } | |
| 76 | 76 | ||
| 77 | 77 | for _, shortcut := range shortcuts { | |
| 78 | - | if err := h.shortcuts.RegisterGlobalShortcut(shortcut.key, shortcut.handler); err != nil { | |
| 79 | - | log.Printf("[window-shortcuts] Failed to register %s (%s): %v", | |
| 80 | - | shortcut.key, shortcut.desc, err) | |
| 81 | - | return err | |
| 82 | - | } | |
| 78 | + | h.shortcuts.RegisterShortcut(shortcut.key, shortcut.handler) | |
| 83 | 79 | log.Printf("[window-shortcuts] Registered global shortcut: %s (%s)", | |
| 84 | 80 | shortcut.key, shortcut.desc) | |
| 85 | 81 | } | |
| @@ -208,11 +204,7 @@ func (h *WindowShortcutHandler) handleZoom(action string, multiplier float64) { | |||
| 208 | 204 | log.Printf("[window-shortcuts] Zoom %s -> pane %p", action, activeWebView) | |
| 209 | 205 | ||
| 210 | 206 | // Get current zoom level | |
| 211 | - | currentZoom, err := activeWebView.GetZoom() | |
| 212 | - | if err != nil { | |
| 213 | - | log.Printf("[window-shortcuts] Failed to get current zoom: %v", err) | |
| 214 | - | return | |
| 215 | - | } | |
| 207 | + | currentZoom := activeWebView.GetZoom() | |
| 216 | 208 | ||
| 217 | 209 | // Calculate new zoom level | |
| 218 | 210 | var newZoom float64 | |
| @@ -261,7 +253,7 @@ func (h *WindowShortcutHandler) getWebViewId(pane *BrowserPane) string { | |||
| 261 | 253 | if pane == nil || pane.webView == nil { | |
| 262 | 254 | return "unknown" | |
| 263 | 255 | } | |
| 264 | - | return pane.webView.ID() | |
| 256 | + | return pane.webView.IDString() | |
| 265 | 257 | } | |
| 266 | 258 | ||
| 267 | 259 | func (h *WindowShortcutHandler) handleUIToggle(lastToggle *time.Time, featureName, action string) { | |
| @@ -342,7 +334,7 @@ func (h *WindowShortcutHandler) handleClosePane() { | |||
| 342 | 334 | // Use the proper close-popup message for popups | |
| 343 | 335 | msg := messaging.Message{ | |
| 344 | 336 | Event: "close-popup", | |
| 345 | - | WebViewID: activeWebView.ID(), | |
| 337 | + | WebViewID: activeWebView.IDString(), | |
| 346 | 338 | Reason: "user-ctrl-w", | |
| 347 | 339 | } | |
| 348 | 340 | h.app.workspace.OnWorkspaceMessage(activeWebView, msg) | |
| @@ -355,10 +347,8 @@ func (h *WindowShortcutHandler) handleClosePane() { | |||
| 355 | 347 | ||
| 356 | 348 | // Cleanup releases resources | |
| 357 | 349 | func (h *WindowShortcutHandler) Cleanup() { | |
| 358 | - | if h.shortcuts != nil { | |
| 359 | - | h.shortcuts.Cleanup() | |
| 360 | - | h.shortcuts = nil | |
| 361 | - | } | |
| 350 | + | // WindowShortcuts doesn't require explicit cleanup | |
| 351 | + | h.shortcuts = nil | |
| 362 | 352 | } | |
| 363 | 353 | ||
| 364 | 354 | // Error definitions | |
| @@ -41,8 +41,8 @@ func NewWindowShortcutHandler(window *webkit.Window, app *BrowserApp) *WindowSho | |||||
| 41 | } | 41 | } | ||
| 42 | 42 | ||||
| 43 | func (h *WindowShortcutHandler) initialize() error { | 43 | func (h *WindowShortcutHandler) initialize() error { | ||
| 44 | - | // Initialize GTK4 global shortcuts | 44 | + | // Create WindowShortcuts manager |
| 45 | - | h.shortcuts = h.window.InitializeGlobalShortcuts() | 45 | + | h.shortcuts = webkit.NewWindowShortcuts(h.window) |
| 46 | if h.shortcuts == nil { | 46 | if h.shortcuts == nil { | ||
| 47 | return ErrFailedToInitialize | 47 | return ErrFailedToInitialize | ||
| 48 | } | 48 | } | ||
| @@ -75,11 +75,7 @@ func (h *WindowShortcutHandler) registerGlobalShortcuts() error { | |||||
| 75 | } | 75 | } | ||
| 76 | 76 | ||||
| 77 | for _, shortcut := range shortcuts { | 77 | for _, shortcut := range shortcuts { | ||
| 78 | - | if err := h.shortcuts.RegisterGlobalShortcut(shortcut.key, shortcut.handler); err != nil { | 78 | + | h.shortcuts.RegisterShortcut(shortcut.key, shortcut.handler) |
| 79 | - | log.Printf("[window-shortcuts] Failed to register %s (%s): %v", | |||
| 80 | - | shortcut.key, shortcut.desc, err) | |||
| 81 | - | return err | |||
| 82 | - | } | |||
| 83 | log.Printf("[window-shortcuts] Registered global shortcut: %s (%s)", | 79 | log.Printf("[window-shortcuts] Registered global shortcut: %s (%s)", | ||
| 84 | shortcut.key, shortcut.desc) | 80 | shortcut.key, shortcut.desc) | ||
| 85 | } | 81 | } | ||
| @@ -208,11 +204,7 @@ func (h *WindowShortcutHandler) handleZoom(action string, multiplier float64) { | |||||
| 208 | log.Printf("[window-shortcuts] Zoom %s -> pane %p", action, activeWebView) | 204 | log.Printf("[window-shortcuts] Zoom %s -> pane %p", action, activeWebView) | ||
| 209 | 205 | ||||
| 210 | // Get current zoom level | 206 | // Get current zoom level | ||
| 211 | - | currentZoom, err := activeWebView.GetZoom() | 207 | + | currentZoom := activeWebView.GetZoom() |
| 212 | - | if err != nil { | |||
| 213 | - | log.Printf("[window-shortcuts] Failed to get current zoom: %v", err) | |||
| 214 | - | return | |||
| 215 | - | } | |||
| 216 | 208 | ||||
| 217 | // Calculate new zoom level | 209 | // Calculate new zoom level | ||
| 218 | var newZoom float64 | 210 | var newZoom float64 | ||
| @@ -261,7 +253,7 @@ func (h *WindowShortcutHandler) getWebViewId(pane *BrowserPane) string { | |||||
| 261 | if pane == nil || pane.webView == nil { | 253 | if pane == nil || pane.webView == nil { | ||
| 262 | return "unknown" | 254 | return "unknown" | ||
| 263 | } | 255 | } | ||
| 264 | - | return pane.webView.ID() | 256 | + | return pane.webView.IDString() |
| 265 | } | 257 | } | ||
| 266 | 258 | ||||
| 267 | func (h *WindowShortcutHandler) handleUIToggle(lastToggle *time.Time, featureName, action string) { | 259 | func (h *WindowShortcutHandler) handleUIToggle(lastToggle *time.Time, featureName, action string) { | ||
| @@ -342,7 +334,7 @@ func (h *WindowShortcutHandler) handleClosePane() { | |||||
| 342 | // Use the proper close-popup message for popups | 334 | // Use the proper close-popup message for popups | ||
| 343 | msg := messaging.Message{ | 335 | msg := messaging.Message{ | ||
| 344 | Event: "close-popup", | 336 | Event: "close-popup", | ||
| 345 | - | WebViewID: activeWebView.ID(), | 337 | + | WebViewID: activeWebView.IDString(), |
| 346 | Reason: "user-ctrl-w", | 338 | Reason: "user-ctrl-w", | ||
| 347 | } | 339 | } | ||
| 348 | h.app.workspace.OnWorkspaceMessage(activeWebView, msg) | 340 | h.app.workspace.OnWorkspaceMessage(activeWebView, msg) | ||
| @@ -355,10 +347,8 @@ func (h *WindowShortcutHandler) handleClosePane() { | |||||
| 355 | 347 | ||||
| 356 | // Cleanup releases resources | 348 | // Cleanup releases resources | ||
| 357 | func (h *WindowShortcutHandler) Cleanup() { | 349 | func (h *WindowShortcutHandler) Cleanup() { | ||
| 358 | - | if h.shortcuts != nil { | 350 | + | // WindowShortcuts doesn't require explicit cleanup |
| 359 | - | h.shortcuts.Cleanup() | 351 | + | h.shortcuts = nil |
| 360 | - | h.shortcuts = nil | |||
| 361 | - | } | |||
| 362 | } | 352 | } | ||
| 363 | 353 | ||||
| 364 | // Error definitions | 354 | // Error definitions | ||