xx/osthread/osthread_darwin.go

33 lines
788 B
Go

//go:build darwin
package osthread
import "github.com/ebitengine/purego/objc"
func onmainthread() bool {
return objc.Send[bool](objc.ID(cls_nsthread), sel_isMainThread)
}
var (
cls_nsthread objc.Class
cls_nsapplication objc.Class
cls_nsapp objc.Class
sel_isMainThread objc.SEL
sel_sharedApplication objc.SEL
sel_run objc.SEL
)
func init() {
cls_nsthread = objc.GetClass("NSThread")
cls_nsapplication = objc.GetClass("NSApplication")
cls_nsapp = objc.GetClass("NSApp")
sel_isMainThread = objc.RegisterName("isMainThread")
sel_sharedApplication = objc.RegisterName("sharedApplication")
sel_run = objc.RegisterName("run")
// Just a bit of magic
objc.ID(cls_nsapplication).Send(sel_sharedApplication)
objc.ID(cls_nsapp).Send(sel_run)
}