diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index f33099dc3..d6a1f9366 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [darwin] Ensure `windowDidBecomeKey` callback is running on main thread by [@leaanthony](https://github.com/leaanthony) - +- Ensure key callbacks in window run() are called on the main thread by [@leaanthony](https://github.com/leaanthony) ## v3.0.0-alpha.8.3 - 2024-12-07 diff --git a/v3/pkg/application/linux_cgo.go b/v3/pkg/application/linux_cgo.go index 4966769f7..1ef75c668 100644 --- a/v3/pkg/application/linux_cgo.go +++ b/v3/pkg/application/linux_cgo.go @@ -826,16 +826,18 @@ func (w *linuxWebviewWindow) enableDND() { } func (w *linuxWebviewWindow) execJS(js string) { - value := C.CString(js) - C.webkit_web_view_evaluate_javascript(w.webKitWebView(), - value, - C.long(len(js)), - nil, - C.CString(""), - nil, - nil, - nil) - C.free(unsafe.Pointer(value)) + InvokeAsync(func() { + value := C.CString(js) + C.webkit_web_view_evaluate_javascript(w.webKitWebView(), + value, + C.long(len(js)), + nil, + C.CString(""), + nil, + nil, + nil) + C.free(unsafe.Pointer(value)) + }) } func getMousePosition() (int, int, *Screen) { @@ -1481,8 +1483,9 @@ func onUriList(extracted **C.char, data unsafe.Pointer) { } } -var debounceTimer *time.Timer +var debounceTimer *time.Timer var isDebouncing bool = false + //export onKeyPressEvent func onKeyPressEvent(_ *C.GtkWidget, event *C.GdkEventKey, userData C.uintptr_t) C.gboolean { // Keypress re-emits if the key is pressed over a certain threshold so we need a debounce diff --git a/v3/pkg/application/webview_window_linux.go b/v3/pkg/application/webview_window_linux.go index a43ae2e82..a02f2aa47 100644 --- a/v3/pkg/application/webview_window_linux.go +++ b/v3/pkg/application/webview_window_linux.go @@ -321,13 +321,15 @@ func (w *linuxWebviewWindow) run() { w.setURL(startURL) w.parent.OnWindowEvent(events.Linux.WindowLoadChanged, func(_ *WindowEvent) { - if w.parent.options.JS != "" { - w.execJS(w.parent.options.JS) - } - if w.parent.options.CSS != "" { - js := fmt.Sprintf("(function() { var style = document.createElement('style'); style.appendChild(document.createTextNode('%s')); document.head.appendChild(style); })();", w.parent.options.CSS) - w.execJS(js) - } + InvokeAsync(func() { + if w.parent.options.JS != "" { + w.execJS(w.parent.options.JS) + } + if w.parent.options.CSS != "" { + js := fmt.Sprintf("(function() { var style = document.createElement('style'); style.appendChild(document.createTextNode('%s')); document.head.appendChild(style); })();", w.parent.options.CSS) + w.execJS(js) + } + }) }) w.parent.OnWindowEvent(events.Linux.WindowFocusIn, func(e *WindowEvent) { w.parent.emit(events.Common.WindowFocus) diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index c34c1288f..85c32505c 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -267,7 +267,7 @@ func (w *windowsWebviewWindow) run() { nil) if w.hwnd == 0 { - panic("Unable to create window") + globalApplication.fatal("Unable to create window") } // Ensure correct window size in case the scale factor of current screen is different from the initial one. @@ -329,7 +329,9 @@ func (w *windowsWebviewWindow) run() { case SystemDefault: w.updateTheme(w32.IsCurrentlyDarkMode()) w.parent.onApplicationEvent(events.Windows.SystemThemeChanged, func(*ApplicationEvent) { - w.updateTheme(w32.IsCurrentlyDarkMode()) + InvokeAsync(func() { + w.updateTheme(w32.IsCurrentlyDarkMode()) + }) }) case Light: w.updateTheme(false) @@ -527,8 +529,7 @@ func (w *windowsWebviewWindow) reload() { } func (w *windowsWebviewWindow) forceReload() { - //TODO implement me - panic("implement me") + // noop } func (w *windowsWebviewWindow) zoomReset() { @@ -580,8 +581,7 @@ func (w *windowsWebviewWindow) close() { } func (w *windowsWebviewWindow) zoom() { - //TODO implement me - panic("implement me") + // Noop } func (w *windowsWebviewWindow) setHTML(html string) { @@ -1299,7 +1299,7 @@ func (w *windowsWebviewWindow) setWindowMask(imageData []byte) { data, err := pngToImage(imageData) if err != nil { - panic(err) + globalApplication.fatal("Fatal error in callback setWindowMask: " + err.Error()) } bitmap, err := w32.CreateHBITMAPFromImage(data)