Documentation
¶
Overview ¶
Package notifications provides cross-platform notification capabilities for desktop applications. It supports macOS, Windows, and Linux with a consistent API while handling platform-specific differences internally. Key features include:
- Basic notifications with title, subtitle, and body
- Interactive notifications with buttons and actions
- Notification categories for reusing configurations
- User feedback handling with a unified callback system
Platform-specific notes:
- macOS: Requires a properly bundled and signed application
- Windows: Uses Windows Toast notifications
- Linux: Uses D-Bus and does not support text inputs
Index ¶
- Constants
- type NotificationAction
- type NotificationCategory
- type NotificationOptions
- type NotificationResponse
- type NotificationResult
- type NotificationService
- func (ns *NotificationService) CheckNotificationAuthorization() (bool, error)
- func (ns *NotificationService) OnNotificationResponse(callback func(result NotificationResult))
- func (ns *NotificationService) RegisterNotificationCategory(category NotificationCategory) error
- func (ns *NotificationService) RemoveAllDeliveredNotifications() error
- func (ns *NotificationService) RemoveAllPendingNotifications() error
- func (ns *NotificationService) RemoveDeliveredNotification(identifier string) error
- func (ns *NotificationService) RemoveNotification(identifier string) error
- func (ns *NotificationService) RemoveNotificationCategory(categoryID string) error
- func (ns *NotificationService) RemovePendingNotification(identifier string) error
- func (ns *NotificationService) RequestNotificationAuthorization() (bool, error)
- func (ns *NotificationService) SendNotification(options NotificationOptions) error
- func (ns *NotificationService) SendNotificationWithActions(options NotificationOptions) error
- func (ns *NotificationService) ServiceName() string
- func (ns *NotificationService) ServiceShutdown() error
- func (ns *NotificationService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error
Constants ¶
const DefaultActionIdentifier = "DEFAULT_ACTION"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NotificationAction ¶
type NotificationAction struct {
ID string `json:"id,omitempty"`
Title string `json:"title,omitempty"`
Destructive bool `json:"destructive,omitempty"` // (macOS-specific)
}
NotificationAction represents an action button for a notification.
type NotificationCategory ¶
type NotificationCategory struct {
ID string `json:"id,omitempty"`
Actions []NotificationAction `json:"actions,omitempty"`
HasReplyField bool `json:"hasReplyField,omitempty"`
ReplyPlaceholder string `json:"replyPlaceholder,omitempty"`
ReplyButtonTitle string `json:"replyButtonTitle,omitempty"`
}
NotificationCategory groups actions for notifications.
type NotificationOptions ¶
type NotificationOptions struct {
ID string `json:"id"`
Title string `json:"title"`
Subtitle string `json:"subtitle,omitempty"` // (macOS and Linux only)
Body string `json:"body,omitempty"`
CategoryID string `json:"categoryId,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
}
NotificationOptions contains configuration for a notification
type NotificationResponse ¶
type NotificationResponse struct {
ID string `json:"id,omitempty"`
ActionIdentifier string `json:"actionIdentifier,omitempty"`
CategoryID string `json:"categoryIdentifier,omitempty"`
Title string `json:"title,omitempty"`
Subtitle string `json:"subtitle,omitempty"` // (macOS and Linux only)
Body string `json:"body,omitempty"`
UserText string `json:"userText,omitempty"`
UserInfo map[string]interface{} `json:"userInfo,omitempty"`
}
NotificationResponse represents the response sent by interacting with a notification.
type NotificationResult ¶
type NotificationResult struct {
Response NotificationResponse
Error error
}
NotificationResult represents the result of a notification response, returning the response or any errors that occurred.
type NotificationService ¶
type NotificationService struct {
// contains filtered or unexported fields
}
Service represents the notifications service
var (
NotificationService_ *NotificationService
)
func (*NotificationService) CheckNotificationAuthorization ¶
func (ns *NotificationService) CheckNotificationAuthorization() (bool, error)
func (*NotificationService) OnNotificationResponse ¶
func (ns *NotificationService) OnNotificationResponse(callback func(result NotificationResult))
OnNotificationResponse registers a callback function that will be called when a notification response is received from the user.
func (*NotificationService) RegisterNotificationCategory ¶
func (ns *NotificationService) RegisterNotificationCategory(category NotificationCategory) error
func (*NotificationService) RemoveAllDeliveredNotifications ¶
func (ns *NotificationService) RemoveAllDeliveredNotifications() error
func (*NotificationService) RemoveAllPendingNotifications ¶
func (ns *NotificationService) RemoveAllPendingNotifications() error
func (*NotificationService) RemoveDeliveredNotification ¶
func (ns *NotificationService) RemoveDeliveredNotification(identifier string) error
func (*NotificationService) RemoveNotification ¶
func (ns *NotificationService) RemoveNotification(identifier string) error
func (*NotificationService) RemoveNotificationCategory ¶
func (ns *NotificationService) RemoveNotificationCategory(categoryID string) error
func (*NotificationService) RemovePendingNotification ¶
func (ns *NotificationService) RemovePendingNotification(identifier string) error
func (*NotificationService) RequestNotificationAuthorization ¶
func (ns *NotificationService) RequestNotificationAuthorization() (bool, error)
Public methods that delegate to the implementation.
func (*NotificationService) SendNotification ¶
func (ns *NotificationService) SendNotification(options NotificationOptions) error
func (*NotificationService) SendNotificationWithActions ¶
func (ns *NotificationService) SendNotificationWithActions(options NotificationOptions) error
func (*NotificationService) ServiceName ¶
func (ns *NotificationService) ServiceName() string
ServiceName returns the name of the service.
func (*NotificationService) ServiceShutdown ¶
func (ns *NotificationService) ServiceShutdown() error
ServiceShutdown is called when the service is unloaded.
func (*NotificationService) ServiceStartup ¶
func (ns *NotificationService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error
ServiceStartup is called when the service is loaded.