5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-16 08:59: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
- [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

View File

@ -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

View File

@ -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)

View File

@ -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)