progrium/darwinkit

Having trouble installing

Closed this issue ยท 6 comments

I'm trying to use your project for the first time. Hitting this issue:

main.go:6:2: no required module provides package github.com/progrium/macdriver/macos/appkit; to add it:
	go get github.com/progrium/macdriver/macos/appkit

Code is simply this:

package main

import (
	"github.com/progrium/macdriver/macos/appkit"
)

func main() {

	ws := appkit.SharedWorkspace()

}

My go.mod file is pointing to the latest version:

require github.com/progrium/macdriver v0.4.0 // indirect

Not sure if this is something to do with the breaking API changes but this should work. Any help would be appreciated!

You have to explicitly use the main branch until we release the 0.5.0-preview release.

Also if you're using this particular API you should follow the conventions in this example:
https://github.com/progrium/macdriver/blob/main/macos/_examples/workspace/main.go

Unless using RunApp, you need to lock the thread and probably wrap in an autorelease pool.

Thank you! I got past the build issue using the commit off master.

Also, thanks for the suggestion. I'm trying to get the currently active window however it doesn't seem to be working for me. I modified your example to show the frontmost application every 1 second. It sticks to the terminal even though I click around to other windows. Any ideas?

This little bit in the docs suggests this data won't update unless inside a run loop, so you'd have to use RunApp and do something like this:

package main

import (
	"fmt"

	"github.com/progrium/macdriver/macos"
	"github.com/progrium/macdriver/macos/appkit"
	"github.com/progrium/macdriver/macos/foundation"
)

func main() {
	macos.RunApp(func(a appkit.Application, ad *appkit.ApplicationDelegate) {
		foundation.Timer_ScheduledTimerWithTimeIntervalRepeatsBlock(2, true, func(timer foundation.Timer) {
			ws := appkit.Workspace_SharedWorkspace()
			fmt.Println(ws.FrontmostApplication().LocalizedName())
		})
	})
}

Yep, that works great. I also tried to do the previous logic in Swift and got the same result. Sounds like using observables is the correct way though?

Not sure if you mean classic KVO or the Observation framework in beta. You could try KVO, those APIs are exposed here, though I haven't tested them. The observation framework is both in beta and it's unclear what the Objective-C API would be or if there is one.. maybe it's just wrapping KVO.

Either way, I'd avoid any assumptions about a "correct" way. The correct way according to Apple would be to use XCode and Swift.

Anyway, I think we can close.