mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-16 08:59:29 +08:00
[v3 mac] Better main thread calls
This commit is contained in:
parent
22cc649e81
commit
155e34c7a8
@ -147,6 +147,7 @@ type (
|
||||
getPrimaryScreen() (*Screen, error)
|
||||
getScreens() ([]*Screen, error)
|
||||
GetFlags(options Options) map[string]any
|
||||
isOnMainThread() bool
|
||||
}
|
||||
|
||||
runnable interface {
|
||||
@ -585,6 +586,12 @@ func (a *App) Clipboard() *Clipboard {
|
||||
}
|
||||
|
||||
func (a *App) dispatchOnMainThread(fn func()) {
|
||||
// If we are on the main thread, just call the function
|
||||
if a.impl.isOnMainThread() {
|
||||
fn()
|
||||
return
|
||||
}
|
||||
|
||||
mainThreadFunctionStoreLock.Lock()
|
||||
id := generateFunctionStoreID()
|
||||
mainThreadFunctionStore[id] = fn
|
||||
|
@ -16,9 +16,17 @@ static void dispatchOnMainThread(unsigned int id) {
|
||||
});
|
||||
}
|
||||
|
||||
static bool onMainThread() {
|
||||
return [NSThread isMainThread];
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func (m *macosApp) isOnMainThread() bool {
|
||||
return bool(C.onMainThread())
|
||||
}
|
||||
|
||||
func (m *macosApp) dispatchOnMainThread(id uint) {
|
||||
C.dispatchOnMainThread(C.uint(id))
|
||||
}
|
||||
|
@ -829,6 +829,11 @@ type macosWebviewWindow struct {
|
||||
parent *WebviewWindow
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) startResize(border string) error {
|
||||
// Not needed right now
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) focus() {
|
||||
w.show()
|
||||
}
|
||||
@ -1212,13 +1217,10 @@ func (w *macosWebviewWindow) setBackgroundColour(colour RGBA) {
|
||||
|
||||
func (w *macosWebviewWindow) position() (int, int) {
|
||||
var x, y C.int
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go globalApplication.dispatchOnMainThread(func() {
|
||||
invokeSync(func() {
|
||||
C.windowGetPosition(w.nsWindow, &x, &y)
|
||||
wg.Done()
|
||||
})
|
||||
wg.Wait()
|
||||
|
||||
return int(x), int(y)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user