notify

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package notify shows system notifications (Notification Center on macOS, the notification area on Windows, the freedesktop notification service on Linux) and reports clicks on them.

if ok, err := notify.RequestPermission(a); ok && err == nil {
	id, err := notify.Send(a, notify.Message{Title: "Build done", Body: "3 warnings"})
	...
}
notify.OnClickWithData(a, func(id, data string) { openSession(data) })

Set Message.Data to attach an application value. Store the returned id to withdraw the notification with RemoveDelivered when it is read.

Functions are safe from any goroutine once the app runs. They return ErrUnsupported when the backend has no notifications and tango.ErrNotRunning after the app quit.

Platform notes: on macOS notifications need the app to run from a .app bundle with a bundle identifier, and the user must allow them. A bare go run or go build executable returns an error. If RequestPermission returns "Notifications are not allowed for this application" when testing a bundle from a temporary directory, quit the app, move the signed bundle to /Applications or ~/Applications and relaunch it with Finder or open. Check the app in System Settings > Notifications if permission was already requested. See the notify guide.

Windows shows WinRT toast notifications. The app's ID (else Name) becomes the process's AppUserModelID and is registered under HKCU so an app without a Start-menu shortcut can show toasts; a click on a toast still in the Action Center calls OnClick while the app runs, but cannot launch a closed app (that needs a shortcut or package with the same AUMID and a COM activator). Where toasts are unavailable or turned off — or with TANGO_WINDOWS_TOAST=0 — they fall back to notification-area balloons. On Linux they go to org.freedesktop.Notifications over D-Bus. On iOS they are local UNUserNotificationCenter notifications, shown as banners also while the app is in the foreground; Send asks for permission the first time. On Android they go to a "Notifications" channel (a "Silent notifications" one for Silent); on Android 13+ the app must declare "notifications" in tan.json (POST_NOTIFICATIONS) and Send asks the first time. On both, a tap opens the app and calls OnClick; a tap on a notification of an earlier run (including the one that launched the app) arrives through OnClick too.

Index

Constants

View Source
const MaxDataBytes = 1024

MaxDataBytes is the maximum size of Message.Data in bytes.

Variables

View Source
var ErrUnsupported = platform.ErrUnsupported

ErrUnsupported is platform.ErrUnsupported.

Functions

func OnClick

func OnClick(a *tango.App, fn func(id string))

OnClick registers fn to run on the main thread when the user clicks a notification this app sent. On macOS, iOS and Android, this includes notifications sent by an earlier run, including the click that launched the app. Register before Run or in OnReady to receive the launch click. IDs stay unique across runs.

func OnClickWithData

func OnClickWithData(a *tango.App, fn func(id, data string))

OnClickWithData registers fn to receive a notification's id and Data on the main thread. Register before Run or in OnReady for launch clicks. macOS preserves Data across runs. On other platforms Data is available for clicks handled by the process that sent the notification. A notification sent without data delivers an empty string.

func RemoveAllDelivered

func RemoveAllDelivered(a *tango.App) error

RemoveAllDelivered withdraws the application's delivered notifications. Some platforms can only withdraw notifications tracked by this process.

func RemoveDelivered

func RemoveDelivered(a *tango.App, id string) error

RemoveDelivered withdraws a delivered notification using its Send id. A missing notification is a no-op. An empty id returns an error.

func RequestPermission

func RequestPermission(a *tango.App) (bool, error)

RequestPermission asks the user, if the platform requires it and they were not asked before, to allow notifications. It reports whether notifications may be shown. It blocks until the user answers; called on the main thread it keeps the event loop running meanwhile.

func Send

func Send(a *tango.App, m Message) (string, error)

Send shows a notification and returns its id, which OnClick handlers receive when the user clicks it.

Types

type Message

type Message struct {
	Title    string
	Subtitle string // shown under the title on macOS; merged into the body elsewhere
	Body     string
	Silent   bool   // no sound
	Data     string // optional application data, at most MaxDataBytes bytes
}

Message is the content of a notification.

Jump to

Keyboard shortcuts

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