Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this library to programmatically create macOS Apps #3

Open
efgee opened this issue May 15, 2017 · 1 comment
Open

How to use this library to programmatically create macOS Apps #3

efgee opened this issue May 15, 2017 · 1 comment

Comments

@efgee
Copy link

efgee commented May 15, 2017

Congratulation to this gem of library.
I would like to use it to programmatically create macOS apps with Go.

How can I make this work?
The code below crashes as soon the NewNSWindow call is done.
It looks like it has something to do with NSRectMake.

Thanks in advance.
`

package main

import (
"github.com/mkrautz/objc"
. "github.com/mkrautz/objc/Foundation"
. "github.com/mkrautz/objc/AppKit"
"runtime"
"fmt"
)

type ApplicationDelegate struct {
objc.Object
}

func InitApplicationDelegate() ApplicationDelegate {
return ApplicationDelegate{objc.GetClass("ApplicationDelegate").Alloc().Init()}
}

func main() {
defer runtime.LockOSThread()
pool := NewNSAutoreleasePool()
defer pool.Release()

app := NSSharedApplication()
del := InitApplicationDelegate()
app.SetDelegate(del)
app.SendMsg("setActivationPolicy:", 0)

rect := NSRectMake(0, 0, 500, 500)
window := NewNSWindow(rect, NSWindowStyleMaskTitled, NSBackingStoreBuffered, false)
window.SendMsg("display")
window.SendMsg("makeKeyAndOrderFront:", app)

fmt.Println("Still OK!")

app.SendMsg("activateIgnoringOtherApps:", true)
app.Run()
pool.Release()

}`

Not sure why the code is weirdly displayed on GitHub...

@tmm1
Copy link

tmm1 commented Nov 6, 2017

To fix the code display, you need to surround it in triple backticks ```

There is an example in the repo that shows how to create a simple app delegate in go: https://github.com/mkrautz/objc/blob/master/demo/demo.go#L17-L19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants