Skip to content

Commit

Permalink
notification: add Urgency and replace Variant with Hint
Browse files Browse the repository at this point in the history
  • Loading branch information
esiqveland committed May 25, 2024
1 parent edaef70 commit 631c6a4
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,38 @@ const (
channelBufferSize = 10
)

// Deprecated: use Hint
type Variant = Hint

// See: https://specifications.freedesktop.org/notification-spec/latest/ar01s08.html
type Variant struct {
type Hint struct {
ID string
Variant dbus.Variant
}

func SoundWithName(soundName string) *Variant {
return &Variant{
ID: "sound-name",
Variant: dbus.MakeVariant(soundName),
}
type Hints map[string]dbus.Variant

func HintSoundWithName(soundName string) Hint {
return Hint{
ID: "sound-name",
Variant: dbus.MakeVariant(soundName),
}
}

func HintUrgency(urgency Urgency) Hint {
return Hint{
ID: "urgency",
Variant: dbus.MakeVariant(byte(urgency)),
}
}

type Urgency byte

const (
UrgencyLow Urgency = 0
UrgencyNormal Urgency = 1
UrgencyCritical Urgency = 2
)
}

// Notification holds all information needed for creating a notification
Expand All @@ -56,6 +77,15 @@ type Notification struct {
ExpireTimeout time.Duration
}

func (n *Notification) SetUrgency(urgency Urgency) *Notification {
if n.Hints == nil {
n.Hints = map[string]dbus.Variant{}
}
h := HintUrgency(urgency)
n.Hints[h.ID] = h.Variant
return n
}

// ExpireTimeoutSetByNotificationServer used as ExpireTimeout to leave expiration up to the notification server.
// Expiration is sent as number of millis.
// When -1, the notification's expiration time is dependent on the notification server's settings, and may vary for the type of notification. If 0, never expire.
Expand Down

0 comments on commit 631c6a4

Please sign in to comment.