Skip to content

Commit

Permalink
macos: add screenlock example (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
progrium committed Aug 24, 2023
1 parent afd1efc commit 88e85bb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions macos/_examples/screenlock/main.go
@@ -0,0 +1,21 @@
package main

import (
"log"

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

func main() {
macos.RunApp(func(app appkit.Application, delegate *appkit.ApplicationDelegate) {
dnc := foundation.DistributedNotificationCenter_NotificationCenterForType(foundation.LocalNotificationCenterType)
dnc.AddObserverForNameObjectQueueUsingBlock("com.apple.screenIsLocked", nil, foundation.OperationQueue_MainQueue(), func(notification foundation.Notification) {
log.Println("screen is locked")
})
dnc.AddObserverForNameObjectQueueUsingBlock("com.apple.screenIsUnlocked", nil, foundation.OperationQueue_MainQueue(), func(notification foundation.Notification) {
log.Println("screen is unlocked")
})
})
}

0 comments on commit 88e85bb

Please sign in to comment.