notify

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 4 Imported by: 1

README

go-notify: Go bindings for libnotify

go-notify implements go bindings for libnotify to create, send, and update OS level notifications. It does not shell out to notify-send so it can update existing notifications as well as create new ones.

Installation

This package requires Cgo and the libnotify (libnotify-dev) shared library to be installed.

On Debian can install with apt install libnotify-dev on Arch with pacman -S libnotify.

Usage

A simple example without any error checking:

// Get an instance of a Notifier
notifier, _ := notify.NewNotifier("my-cool-app-name")

// Create and show a notification
notification, _ := notifier.NewNotification(
    "A summary", "Some body text", "a/path/to/an/icon.png")

// Set notification urgency (Low, Normal, Critical)
_ := notification.SetUrgency(notify.Critical)

notification.Show()

// Update an existing notification (or send a new one if one hasn't
// been sent)
notification.Update(
    "A new summary",
    "Some different body text",
    "another/path/to/icon.png",
)

// Remove an existing notification
notification.Close()

See example/example.go for a more complete example.

Roadmap

  • Add API that returns a Notification instance to manage multiple notifications at once
  • Support notification urgencies
  • Support notification timeouts
  • Better support for notification icons (PixBuf?)

Authors

The original code for these bindings was written by @codegoalie and provided under the MIT license. This fork was written by me, Stefan van den Akker.

Documentation

Overview

Package notify implements Go bindings for libnotify to create, send, and update OS level notifications. It does not shell out to `notify-send` so it can update existing notifications as well as create new ones.

This package requires Cgo and the libnotify (libnotify-dev) shared library to be installed.

On Ubuntu or Debian you can install with: sudo apt-get install libnotify-dev

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Notification

type Notification struct {
	// contains filtered or unexported fields
}

Notification represents an instance of a single notification

func (*Notification) Close

func (n *Notification) Close() error

Close removes the notification from the OS

func (*Notification) SetUrgency

func (n *Notification) SetUrgency(urgency Urgency) error

SetUrgency sets the notification urgency (Low, Normal, Critical)

func (*Notification) Show

func (n *Notification) Show() error

Show sends the notification to the OS for displaying

func (*Notification) Update

func (n *Notification) Update(summary, body, icon string) error

Update an existing notification with new information

type Notifier

type Notifier struct {
	// contains filtered or unexported fields
}

Notifier is an instance of an application sending notifications

func NewNotifier

func NewNotifier(appName string) (*Notifier, error)

NewNotifier initializes a new application to send notifications. It's required to call this function first.

func (*Notifier) ApplicationName

func (n *Notifier) ApplicationName() string

ApplicationName returns the current application's initialized name

func (*Notifier) NewNotification

func (n *Notifier) NewNotification(summary, body, icon string) (*Notification, error)

NewNotification creates a new notification

type Urgency

type Urgency int

Urgency represents the urgency of the notification

const (
	Low Urgency = iota
	Medium
	Critical
)

3 levels of urgency:

Low: used for unimportant notifications. Normal: used for most standard notifications. Critical: used for very important notifications.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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