notify

package module
v0.0.0-...-11f4c6c Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: Apache-2.0 Imports: 3 Imported by: 5

README

notifier

A library for sending native desktop notifications from Go designed distribution particularly within other apps that care about install size. This uses platform-specific helper libraries as follows:

Those libraries are embedded directly in Go in this library using go-bindata, so there are no external dependencies or expectations for installations on the user's system. These libraries were also chosen for their small size, particularly in the case of notifu, which is far smaller than things like Growl or Snarl.

To generate updated embedded binaries, you first need go-bindata:

go get -u github.com/jteeuwen/go-bindata/...

Then you can run, for example:

cd platform/notifu-1.7.1
go-bindata -pkg win --nomemcopy -nocompress notifu.exe
mv bindata.go ../../win

This is currently a work in progress and only runs on OSX and Windows and embeds binaries for Windows instead of dynamically only including the required platform at build time, for example.

The platform directory is only here to serve as a reference for the native binaries being used.

For documentation purposes, here are the raw options for terminal-notifier:

$ ./terminal-notifier.app/Contents/MacOS/terminal-notifier
terminal-notifier (1.6.3) is a command-line tool to send OS X User Notifications.

Usage: terminal-notifier -[message|list|remove] [VALUE|ID|ID] [options]

   Either of these is required (unless message data is piped to the tool):

       -help              Display this help banner.
       -message VALUE     The notification message.
       -remove ID         Removes a notification with the specified ‘group’ ID.
       -list ID           If the specified ‘group’ ID exists show when it was delivered,
                          or use ‘ALL’ as ID to see all notifications.
                          The output is a tab-separated list.

   Optional:

       -title VALUE       The notification title. Defaults to ‘Terminal’.
       -subtitle VALUE    The notification subtitle.
       -sound NAME        The name of a sound to play when the notification appears. The names are listed
                          in Sound Preferences. Use 'default' for the default notification sound.
       -group ID          A string which identifies the group the notifications belong to.
                          Old notifications with the same ID will be removed.
       -activate ID       The bundle identifier of the application to activate when the user clicks the notification.
       -sender ID         The bundle identifier of the application that should be shown as the sender, including its icon.
       -appIcon URL       The URL of a image to display instead of the application icon (Mavericks+ only)
       -contentImage URL  The URL of a image to display attached to the notification (Mavericks+ only)
       -open URL          The URL of a resource to open when the user clicks the notification.
       -execute COMMAND   A shell command to perform when the user clicks the notification.

When the user activates a notification, the results are logged to the system logs.
Use Console.app to view these logs.

Note that in some circumstances the first character of a message has to be escaped in order to be recognized.
An example of this is when using an open bracket, which has to be escaped like so: ‘\[’.

Here are the docs for notifu:

Usage: notifu [@argfile] [/?|h|help] [/v|version] [/t <value>] [/d <value>] [/p <value>]
                  /m <value< [/i <value>] [/e]

@argfile        Read arguments from a file.


/?              Show usage.
/v              Show version.
/t <value>      The type of message to display values are:
                    info      The message is an informational message
                    warn      The message is an warning message
                    error     The message is an error message
/d <value>      The number of milliseconds to display (omit or 0 for infinit)
/p <value>      The title (or prompt) of the ballon
/m <value>      The message text
/i <value>      Specify an icon to use ("parent" uses the icon of the parent process)
/e              Enable ballon tips in the registry (for this user only)
/q              Do not play a sound when the tooltip is displayed
/w              Show the tooltip even if the user is in the quiet period that follows his very first login (Windows 7 and up)
/xp             Use IUserNotification interface event when IUserNotification2 is available

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
	IconURL string
	// Sender identifies the application that's sending the notification on OS X
	// to pick up the appropriate icon (e.g. com.getlantern.lantern). This
	// overrides whatever is set in IconURL.
	Sender   string
	ClickURL string
	// ClickLabel is the label for the clickable link in OS X notifications (e.g.
	// "open" or "show")
	ClickLabel string
	// AutoDismissAfter governs how quickly notifications on OS X are
	// automatically dismissed.
	AutoDismissAfter time.Duration
}

Notification contains data for notifying the user about something. This is directly modeled after Chrome notifications, as detailed at: https://developer.chrome.com/apps/notifications

type Notifier

type Notifier interface {
	// Notify sends a notification to the user.
	Notify(*Notification) error
}

Notifier is an interface for sending notifications to the user.

func NewNotifications

func NewNotifications() Notifier

NewNotifications creates a new Notifier that can notify the user about stuff.

func NewNotificationsWithErrorCallback

func NewNotificationsWithErrorCallback(errorFunc func(error)) Notifier

NewNotificationsWithErrorCallback creates a new Notifier that can notify the user about stuff and calls the specified error func on errors.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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