feat(webkit): add WebView ID string conversion helpers
Add convenience methods for converting between uint64 and string WebView IDs:
- WebView.IDString() - converts ID to string for compatibility with string-based APIs
- ParseWebViewID(string) - parses string ID back to uint64
These helpers will make the gotk4 migration cleaner by providing a standard
way to handle ID conversions throughout the codebase, particularly for:
- Message passing where IDs are transmitted as strings
- Popup management where parent/child relationships use string IDs
- Legacy code expecting string IDs
Usage examples:
webView.IDString() // "123" instead of fmt.Sprintf("%d", webView.ID())
ParseWebViewID(msg.WebViewID) // 123 instead of manual parsing- commit
- 173610c5e97a94850aec4e826dfe0e1ea2e515e6
- author
- bamen · · 2025-10-08 20:26 UTC
- committer
- bamen · · 2025-10-08 18:17 UTC
- parent
- 4643f94
- signature
- unsigned
1 file · +17 -0
M pkg/webkit/webview.go +17 -0
| @@ -2,6 +2,7 @@ package webkit | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "fmt" | |
| 5 | + | "strconv" | |
| 5 | 6 | "sync" | |
| 6 | 7 | "sync/atomic" | |
| 7 | 8 | ||
| @@ -294,6 +295,22 @@ func (w *WebView) ID() uint64 { | |||
| 294 | 295 | return w.id | |
| 295 | 296 | } | |
| 296 | 297 | ||
| 298 | + | // IDString returns the WebView ID as a string | |
| 299 | + | // This is a convenience method for compatibility with code expecting string IDs | |
| 300 | + | func (w *WebView) IDString() string { | |
| 301 | + | return fmt.Sprintf("%d", w.id) | |
| 302 | + | } | |
| 303 | + | ||
| 304 | + | // ParseWebViewID converts a string WebView ID to uint64 | |
| 305 | + | // Returns 0 if the string cannot be parsed | |
| 306 | + | func ParseWebViewID(idStr string) uint64 { | |
| 307 | + | id, err := strconv.ParseUint(idStr, 10, 64) | |
| 308 | + | if err != nil { | |
| 309 | + | return 0 | |
| 310 | + | } | |
| 311 | + | return id | |
| 312 | + | } | |
| 313 | + | ||
| 297 | 314 | // AsWidget returns the WebView as a gtk.Widgetter | |
| 298 | 315 | func (w *WebView) AsWidget() gtk.Widgetter { | |
| 299 | 316 | if w == nil || w.view == nil { | |
| @@ -2,6 +2,7 @@ package webkit | |||||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | "fmt" | 4 | "fmt" | ||
| 5 | + | "strconv" | |||
| 5 | "sync" | 6 | "sync" | ||
| 6 | "sync/atomic" | 7 | "sync/atomic" | ||
| 7 | 8 | ||||
| @@ -294,6 +295,22 @@ func (w *WebView) ID() uint64 { | |||||
| 294 | return w.id | 295 | return w.id | ||
| 295 | } | 296 | } | ||
| 296 | 297 | ||||
| 298 | + | // IDString returns the WebView ID as a string | |||
| 299 | + | // This is a convenience method for compatibility with code expecting string IDs | |||
| 300 | + | func (w *WebView) IDString() string { | |||
| 301 | + | return fmt.Sprintf("%d", w.id) | |||
| 302 | + | } | |||
| 303 | + | ||||
| 304 | + | // ParseWebViewID converts a string WebView ID to uint64 | |||
| 305 | + | // Returns 0 if the string cannot be parsed | |||
| 306 | + | func ParseWebViewID(idStr string) uint64 { | |||
| 307 | + | id, err := strconv.ParseUint(idStr, 10, 64) | |||
| 308 | + | if err != nil { | |||
| 309 | + | return 0 | |||
| 310 | + | } | |||
| 311 | + | return id | |||
| 312 | + | } | |||
| 313 | + | ||||
| 297 | // AsWidget returns the WebView as a gtk.Widgetter | 314 | // AsWidget returns the WebView as a gtk.Widgetter | ||
| 298 | func (w *WebView) AsWidget() gtk.Widgetter { | 315 | func (w *WebView) AsWidget() gtk.Widgetter { | ||
| 299 | if w == nil || w.view == nil { | 316 | if w == nil || w.view == nil { | ||