diff options
| author | Caroline Larimore <caroline@larimo.re> | 2025-01-30 16:39:09 -0800 |
|---|---|---|
| committer | Caroline Larimore <caroline@larimo.re> | 2025-01-30 16:39:09 -0800 |
| commit | 784ee51b9613cac5764c9a33c343655e514e20f0 (patch) | |
| tree | d6291c6c2a6be604913952f529cc335e827473c9 /corvid.go | |
Initial Commit
Diffstat (limited to 'corvid.go')
| -rw-r--r-- | corvid.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/corvid.go b/corvid.go new file mode 100644 index 0000000..267f4e5 --- /dev/null +++ b/corvid.go @@ -0,0 +1,85 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + "slices" + "sync" + + "github.com/godbus/dbus/v5" +) + +const DEFAULT_EXPIRATION = 5000 +const SORT_DIRECTION = 1 // 1 = newest first, -1 = oldest first +const DBUS_OBJECT = "/org/freedesktop/Notifications" +const DBUS_NAME = "org.freedesktop.Notifications" + +var conn *dbus.Conn + +type notificationStack = struct { + mutex *sync.Mutex + notifications map[uint32]notification + nextId uint32 +} + +var notifications = notificationStack{ + mutex: &sync.Mutex{}, + notifications: make(map[uint32]notification), + nextId: 1, +} + +func output() { + arr := make([]notification, len(notifications.notifications)) + + i := 0 + for _, notification := range notifications.notifications { + arr[i] = notification + i++ + } + + slices.SortFunc(arr, func(a, b notification) int { + if a.Timestamp > b.Timestamp { + return SORT_DIRECTION + } else if a.Timestamp < b.Timestamp { + return -SORT_DIRECTION + } else { + if a.Id > b.Id { + return SORT_DIRECTION + } else if a.Id < b.Id { + return -SORT_DIRECTION + } + } + + return 0 + }) + + j, err := json.Marshal(arr) + if err != nil { + log.Fatalln(err) + } + + fmt.Println(string(j)) +} + +func main() { + var err error + conn, err = dbus.SessionBus() + if err != nil { + log.Fatal(err) + } + + conn.Export(server{}, DBUS_OBJECT, DBUS_NAME) + + reply, err := conn.RequestName(DBUS_NAME, dbus.NameFlagReplaceExisting|dbus.NameFlagDoNotQueue) + if err != nil { + log.Fatal(err) + } + + if reply != dbus.RequestNameReplyPrimaryOwner { + log.Fatalf("'%s' already taken", DBUS_NAME) + } + + log.Print("connected to dbus") + select {} +} |