mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-16 17:09:28 +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)
|
getPrimaryScreen() (*Screen, error)
|
||||||
getScreens() ([]*Screen, error)
|
getScreens() ([]*Screen, error)
|
||||||
GetFlags(options Options) map[string]any
|
GetFlags(options Options) map[string]any
|
||||||
|
isOnMainThread() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
runnable interface {
|
runnable interface {
|
||||||
@ -585,6 +586,12 @@ func (a *App) Clipboard() *Clipboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) dispatchOnMainThread(fn func()) {
|
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()
|
mainThreadFunctionStoreLock.Lock()
|
||||||
id := generateFunctionStoreID()
|
id := generateFunctionStoreID()
|
||||||
mainThreadFunctionStore[id] = fn
|
mainThreadFunctionStore[id] = fn
|
||||||
|
@ -16,9 +16,17 @@ static void dispatchOnMainThread(unsigned int id) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool onMainThread() {
|
||||||
|
return [NSThread isMainThread];
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
func (m *macosApp) isOnMainThread() bool {
|
||||||
|
return bool(C.onMainThread())
|
||||||
|
}
|
||||||
|
|
||||||
func (m *macosApp) dispatchOnMainThread(id uint) {
|
func (m *macosApp) dispatchOnMainThread(id uint) {
|
||||||
C.dispatchOnMainThread(C.uint(id))
|
C.dispatchOnMainThread(C.uint(id))
|
||||||
}
|
}
|
||||||
|
@ -829,6 +829,11 @@ type macosWebviewWindow struct {
|
|||||||
parent *WebviewWindow
|
parent *WebviewWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *macosWebviewWindow) startResize(border string) error {
|
||||||
|
// Not needed right now
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (w *macosWebviewWindow) focus() {
|
func (w *macosWebviewWindow) focus() {
|
||||||
w.show()
|
w.show()
|
||||||
}
|
}
|
||||||
@ -1212,13 +1217,10 @@ func (w *macosWebviewWindow) setBackgroundColour(colour RGBA) {
|
|||||||
|
|
||||||
func (w *macosWebviewWindow) position() (int, int) {
|
func (w *macosWebviewWindow) position() (int, int) {
|
||||||
var x, y C.int
|
var x, y C.int
|
||||||
var wg sync.WaitGroup
|
invokeSync(func() {
|
||||||
wg.Add(1)
|
|
||||||
go globalApplication.dispatchOnMainThread(func() {
|
|
||||||
C.windowGetPosition(w.nsWindow, &x, &y)
|
C.windowGetPosition(w.nsWindow, &x, &y)
|
||||||
wg.Done()
|
|
||||||
})
|
})
|
||||||
wg.Wait()
|
|
||||||
return int(x), int(y)
|
return int(x), int(y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user