notifier

package module
v0.0.0-...-f005f1a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 2 Imported by: 0

README

go-notifier

Cross platform system notifications in go (golang).

Platforms

For OS X, we use NSUserNotificationCenter APIs from cgo. This only supports OS X 10.9 and above.

For Windows, we use toaster. This only supports Windows 8 and above.

For Linux, we use notify-send.

Install

go install github.com/keybase/go-notifier/notifier

Alerts

If you need alert style (actionable) notifications (on OS X), you need to include an Info.plist in the binary and sign it. You can look at build_darwin.sh on how to do this.

Examples (OS X)

Notification with single action
notifier --title="Hi" --message="Test message" --bundle-id=keybase.Electron --timeout=20 --action=Close

If action is chosen, you get output (stdout):

{"type":"action","action":"Close"}

If the notification contents are clicked,

{"type":"clicked"}
Notification with multiple actions
notifier --title="Hi" --message="Test message" --bundle-id=keybase.Electron --timeout=20 --action=Close --action="Install" --action="Ignore"

Resources

Follows similar requirements of node-notifier, but only supports recent platform versions.

Instead of deckarep/gosx-notifier, which uses an embedded version of terminal-notifier, this implementation uses cgo to talk directly to NSUserNotificationCenter APIs. It is also possible to use AppleScript APIs to generate notifications (see this post), but a cgo implementation was preferable.

The 0xAX/notificator only supports growlnotify on Windows and OS X.

The vjeantet/alerter app allows you to use alert style notifications on OS X.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Notification

type Notification struct {
	Title     string
	Message   string
	ImagePath string

	// For darwin
	Actions  []string
	Timeout  float64
	BundleID string

	// For windows
	ToastPath string // Path to toast.exe
}

Notification defines a notification

type Notifier

type Notifier interface {
	DeliverNotification(notification Notification) error
}

Notifier knows how to deliver a notification

func NewNotifier

func NewNotifier() (Notifier, error)

NewNotifier constructs notifier for Linux

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL