DarwinKit: Native Apple APIs for Golang!
DarwinKit lets you work with supported Apple frameworks and build native applications using Go. With XCode and Go 1.18+ installed, you can write this program in a main.go
file:
package main
import (
"github.com/progrium/darwinkit/objc"
"github.com/progrium/darwinkit/macos"
"github.com/progrium/darwinkit/macos/appkit"
"github.com/progrium/darwinkit/macos/foundation"
"github.com/progrium/darwinkit/macos/webkit"
)
func main() {
// runs macOS application event loop with a callback on success
macos.RunApp(func(app appkit.Application, delegate *appkit.ApplicationDelegate) {
app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular)
app.ActivateIgnoringOtherApps(true)
url := foundation.URL_URLWithString("https://github.com/sponsors/darwinkitdev")
req := foundation.NewURLRequestWithURL(url)
frame := foundation.Rect{Size: foundation.Size{1440, 900}}
config := webkit.NewWebViewConfiguration()
wv := webkit.NewWebViewWithFrameConfiguration(frame, config)
wv.LoadRequest(req)
w := appkit.NewWindowWithContentRectStyleMaskBackingDefer(frame,
appkit.ClosableWindowMask|appkit.TitledWindowMask,
appkit.BackingStoreBuffered, false)
objc.Retain(&w)
w.SetContentView(wv)
w.MakeKeyAndOrderFront(w)
w.Center()
delegate.SetApplicationShouldTerminateAfterLastWindowClosed(func(appkit.Application) bool {
return true
})
})
}