From 88e85bb106bac29f2b76b2c179a22a05c2bbba05 Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Wed, 23 Aug 2023 19:13:24 -0500 Subject: [PATCH] macos: add screenlock example (#202) --- macos/_examples/screenlock/main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 macos/_examples/screenlock/main.go diff --git a/macos/_examples/screenlock/main.go b/macos/_examples/screenlock/main.go new file mode 100644 index 00000000..57705f23 --- /dev/null +++ b/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") + }) + }) +}