You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
813 B
Go
53 lines
813 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
/*
|
|
#cgo CFLAGS: -x objective-c
|
|
#cgo LDFLAGS: -framework AppKit
|
|
#include "procmon.h"
|
|
*/
|
|
import "C"
|
|
|
|
var appChanges = make(chan appStateChange, 1)
|
|
|
|
type stateChange uint
|
|
|
|
const (
|
|
stateStarted stateChange = iota
|
|
stateEnded
|
|
)
|
|
|
|
type appStateChange struct {
|
|
stateChange
|
|
appname string
|
|
}
|
|
|
|
//export AppStarted
|
|
func AppStarted(name string) {
|
|
appChanges <- appStateChange{stateStarted, name}
|
|
}
|
|
|
|
//export AppEnded
|
|
func AppEnded(name string) {
|
|
appChanges <- appStateChange{stateEnded, name}
|
|
}
|
|
|
|
func reportChanges() {
|
|
for change := range appChanges {
|
|
switch change.stateChange {
|
|
case stateStarted:
|
|
fmt.Printf("started: %s\n", change.appname)
|
|
case stateEnded:
|
|
fmt.Printf("terminated: %s\n", change.appname)
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
go reportChanges()
|
|
C.MonitorProcesses()
|
|
}
|