notification.go (view raw)
1package main
2
3import (
4 "fmt"
5 "time"
6
7 dbus "github.com/godbus/dbus/v5"
8)
9
10type Notification struct {
11 Time time.Time
12 AppName string
13 Summary string
14 Body string
15}
16
17// https://specifications.freedesktop.org/notification-spec/latest/protocol.html
18func NewNotification(message *dbus.Message) Notification {
19 return Notification{
20 Time: time.Now(),
21 AppName: fmt.Sprintf("%v", message.Body[0]),
22 Summary: fmt.Sprintf("%v", message.Body[3]),
23 Body: fmt.Sprintf("%v", message.Body[4]),
24 }
25}
26
27func (n Notification) String() string {
28 return fmt.Sprintf("%s\n%s %s\n%s\n\n",
29 datetimeStyle.Render(n.Time.Format(DATETIME_FORMAT)),
30 getAppNameStyle(n.AppName).Render(n.AppName),
31 summaryStyle.Render(n.Summary),
32 bodyStyle.Render(n.Body),
33 )
34}