diff options
Diffstat (limited to 'notifier_darwin.go')
| -rw-r--r-- | notifier_darwin.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/notifier_darwin.go b/notifier_darwin.go new file mode 100644 index 0000000..b075f1c --- /dev/null +++ b/notifier_darwin.go @@ -0,0 +1,57 @@ +// Copyright 2016 Keybase, Inc. All rights reserved. Use of +// this source code is governed by the included BSD license. + +package notifier + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework Cocoa +#import <Cocoa/Cocoa.h> +extern CFStringRef deliverNotification(CFStringRef title, CFStringRef subtitle, CFStringRef message, CFStringRef appIconURLString, CFStringRef groupID, CFStringRef bundleID, CFStringRef actionButtonTitle, CFStringRef otherButtonTitle); +*/ +import "C" +import "fmt" + +type darwinNotifier struct{} + +// NewNotifier constructs notifier for Windows +func NewNotifier() (Notifier, error) { + return &darwinNotifier{}, nil +} + +// DeliverNotification sends a notification +func (n darwinNotifier) DeliverNotification(notification Notification) error { + titleRef, err := StringToCFString(notification.Title) + if err != nil { + return err + } + defer Release(C.CFTypeRef(titleRef)) + messageRef, err := StringToCFString(notification.Message) + if err != nil { + return err + } + defer Release(C.CFTypeRef(messageRef)) + + var bundleIDRef C.CFStringRef + if notification.BundleID != "" { + bundleIDRef, err = StringToCFString(notification.BundleID) + if err != nil { + return err + } + defer Release(C.CFTypeRef(bundleIDRef)) + } + + var appIconURLStringRef C.CFStringRef + if notification.ImagePath != "" { + appIconURLString := fmt.Sprintf("file://%s", notification.ImagePath) + appIconURLStringRef, err = StringToCFString(appIconURLString) + if err != nil { + return err + } + defer Release(C.CFTypeRef(appIconURLStringRef)) + } + + C.deliverNotification(titleRef, nil, messageRef, appIconURLStringRef, bundleIDRef, bundleIDRef, nil, nil) + + return nil +} |
