notification

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package notification provides an interface for sending desktop notifications and handling signals (events).

For more details see the specification: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html

Index

Constants

View Source
const (
	PackageVersion = "0.2.2"
	ExpiresNever   = time.Duration(0)        // notification never expires
	ExpiresDefault = time.Duration(-1000000) // depends on the server's settings

	ReasonExpired   = 1 // the notification expired
	ReasonDismissed = 2 // the notification was dismissed by the user
	ReasonClosed    = 3 // the notification was closed by a call to CloseNotification
	ReasonUndefined = 4 // undefined/reserved reasons
)

Variables

View Source
var (
	AppName string
	AppIcon string
)

Functions

func CloseNotification

func CloseNotification(noti *Notification) error

CloseNotification closes a notification.

func GetCapabilities

func GetCapabilities() (result []string, err error)

GetCapabilities calls org.freedesktop.Notifications.GetCapabilities.

func Init

func Init(appName, appIcon string) error

Init connects to the session bus, sets the appName and appIcon and starts an event loop.

func Notify

func Notify(noti *Notification) error

Notify sends a notification.

func SendNotification

func SendNotification(summary, body, appName, appIcon string, urgency Urgency, timeout time.Duration) error

SendNotification sends a simple notification.

Types

type Notification

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

Notification represents a desktop notification. A notification can be modified and updated/shown again on the screen with Notify().

func New

func New(summary, body string) *Notification

New creates a new Notification. The urgency will be set to UrgencyNormal and the timeout to ExpiresDefault.

func (*Notification) AddActionHandler

func (noti *Notification) AddActionHandler(key, name string, handler func())

AddActionHandler adds an action and a function to handle an org.freedesktop.Notifications.ActionInvoked signal with the specified key. Setting handler to nil will remove the function.

func (*Notification) AddHint

func (noti *Notification) AddHint(key string, value interface{})

AddHint adds a hint to the notification. A hint with the key "urgency" will be ignored; use SetUrgency(). See the specification for more details.

func (*Notification) SetBody

func (noti *Notification) SetBody(body string)

SetBody sets the notification's body. This is a multi-line body of text.

func (*Notification) SetClosedHandler

func (noti *Notification) SetClosedHandler(handler func(uint32))

SetClosedHandler sets a function to handle the org.freedesktop.Notifications.NotificationClosed signal. This function gets one of the Reason* constants as its arguement. Setting handler to nil will remove the function.

func (*Notification) SetIcon

func (noti *Notification) SetIcon(icon string)

SetIcon sets the notification's icon. If icon is an empty string AppIcon will be used.

func (*Notification) SetSummary

func (noti *Notification) SetSummary(summary string)

SetSummary sets the notification's summary. This is a single line overview of the notification.

func (*Notification) SetTimeout

func (noti *Notification) SetTimeout(timeout time.Duration)

SetTimeout sets the expiration timeout. This is the duration after which the notification should be closed or one of the constants ExpiresNever or ExpiresDefault.

func (*Notification) SetUrgency

func (noti *Notification) SetUrgency(urgency Urgency)

SetUrgency sets the notification's urgency level. This is one of the Urgency* constants.

type ServerInfo

type ServerInfo struct {
	Name        string
	Vendor      string
	Version     string
	SpecVersion string
}

ServerInfo represents server information.

func GetServerInformation

func GetServerInformation() (*ServerInfo, error)

GetServerInformation calls org.freedesktop.Notifications.GetServerInformation.

type Urgency

type Urgency byte
const (
	UrgencyLow      Urgency = 0
	UrgencyNormal   Urgency = 1
	UrgencyCritical Urgency = 2
)

Jump to

Keyboard shortcuts

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