5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-17 01:19:29 +08:00

Ensure key callbacks in window run() are called on the main thread

This commit is contained in:
Lea Anthony 2024-12-07 20:54:22 +11:00
parent 5445aebe94
commit 2a6e3da30a
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
4 changed files with 31 additions and 26 deletions

View File

@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- [darwin] Ensure `windowDidBecomeKey` callback is running on main thread by [@leaanthony](https://github.com/leaanthony) - [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 ## v3.0.0-alpha.8.3 - 2024-12-07

View File

@ -826,6 +826,7 @@ func (w *linuxWebviewWindow) enableDND() {
} }
func (w *linuxWebviewWindow) execJS(js string) { func (w *linuxWebviewWindow) execJS(js string) {
InvokeAsync(func() {
value := C.CString(js) value := C.CString(js)
C.webkit_web_view_evaluate_javascript(w.webKitWebView(), C.webkit_web_view_evaluate_javascript(w.webKitWebView(),
value, value,
@ -836,6 +837,7 @@ func (w *linuxWebviewWindow) execJS(js string) {
nil, nil,
nil) nil)
C.free(unsafe.Pointer(value)) C.free(unsafe.Pointer(value))
})
} }
func getMousePosition() (int, int, *Screen) { func getMousePosition() (int, int, *Screen) {
@ -1483,6 +1485,7 @@ func onUriList(extracted **C.char, data unsafe.Pointer) {
var debounceTimer *time.Timer var debounceTimer *time.Timer
var isDebouncing bool = false var isDebouncing bool = false
//export onKeyPressEvent //export onKeyPressEvent
func onKeyPressEvent(_ *C.GtkWidget, event *C.GdkEventKey, userData C.uintptr_t) C.gboolean { 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 // Keypress re-emits if the key is pressed over a certain threshold so we need a debounce

View File

@ -321,6 +321,7 @@ func (w *linuxWebviewWindow) run() {
w.setURL(startURL) w.setURL(startURL)
w.parent.OnWindowEvent(events.Linux.WindowLoadChanged, func(_ *WindowEvent) { w.parent.OnWindowEvent(events.Linux.WindowLoadChanged, func(_ *WindowEvent) {
InvokeAsync(func() {
if w.parent.options.JS != "" { if w.parent.options.JS != "" {
w.execJS(w.parent.options.JS) w.execJS(w.parent.options.JS)
} }
@ -329,6 +330,7 @@ func (w *linuxWebviewWindow) run() {
w.execJS(js) w.execJS(js)
} }
}) })
})
w.parent.OnWindowEvent(events.Linux.WindowFocusIn, func(e *WindowEvent) { w.parent.OnWindowEvent(events.Linux.WindowFocusIn, func(e *WindowEvent) {
w.parent.emit(events.Common.WindowFocus) w.parent.emit(events.Common.WindowFocus)
}) })

View File

@ -267,7 +267,7 @@ func (w *windowsWebviewWindow) run() {
nil) nil)
if w.hwnd == 0 { 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. // Ensure correct window size in case the scale factor of current screen is different from the initial one.
@ -329,8 +329,10 @@ func (w *windowsWebviewWindow) run() {
case SystemDefault: case SystemDefault:
w.updateTheme(w32.IsCurrentlyDarkMode()) w.updateTheme(w32.IsCurrentlyDarkMode())
w.parent.onApplicationEvent(events.Windows.SystemThemeChanged, func(*ApplicationEvent) { w.parent.onApplicationEvent(events.Windows.SystemThemeChanged, func(*ApplicationEvent) {
InvokeAsync(func() {
w.updateTheme(w32.IsCurrentlyDarkMode()) w.updateTheme(w32.IsCurrentlyDarkMode())
}) })
})
case Light: case Light:
w.updateTheme(false) w.updateTheme(false)
case Dark: case Dark:
@ -527,8 +529,7 @@ func (w *windowsWebviewWindow) reload() {
} }
func (w *windowsWebviewWindow) forceReload() { func (w *windowsWebviewWindow) forceReload() {
//TODO implement me // noop
panic("implement me")
} }
func (w *windowsWebviewWindow) zoomReset() { func (w *windowsWebviewWindow) zoomReset() {
@ -580,8 +581,7 @@ func (w *windowsWebviewWindow) close() {
} }
func (w *windowsWebviewWindow) zoom() { func (w *windowsWebviewWindow) zoom() {
//TODO implement me // Noop
panic("implement me")
} }
func (w *windowsWebviewWindow) setHTML(html string) { func (w *windowsWebviewWindow) setHTML(html string) {
@ -1299,7 +1299,7 @@ func (w *windowsWebviewWindow) setWindowMask(imageData []byte) {
data, err := pngToImage(imageData) data, err := pngToImage(imageData)
if err != nil { if err != nil {
panic(err) globalApplication.fatal("Fatal error in callback setWindowMask: " + err.Error())
} }
bitmap, err := w32.CreateHBITMAPFromImage(data) bitmap, err := w32.CreateHBITMAPFromImage(data)