From c551d98a53c393140c54e955b1d4fd7005f43b54 Mon Sep 17 00:00:00 2001 From: Caroline Larimore Date: Mon, 21 Apr 2025 17:07:11 -0700 Subject: Add proper expiration and sort settings --- cmd/corvid/main.go | 27 ++++++++++++++++++++++++++- srv/notifServer.go | 2 +- srv/server.go | 9 ++++++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/cmd/corvid/main.go b/cmd/corvid/main.go index 53c84aa..7fffbd1 100644 --- a/cmd/corvid/main.go +++ b/cmd/corvid/main.go @@ -39,10 +39,35 @@ func main() { } func server() { - srv.Start() + defaultExpiration := getEnvInt("CORVID_DEFAULT_EXPIRATION", 5000) + sortDirection := 1 + + switch os.Getenv("CORVID_SORT_DIRECTION") { + case "NEWEST_FIRST": + sortDirection = 1 + case "OLDEST_FIRST": + sortDirection = -1 + } + + srv.Start(defaultExpiration, sortDirection) select {} } +func getEnvInt(key string, fallback int) int { + str := os.Getenv(key) + + if len(str) == 0 { + return fallback + } + + value, err := strconv.Atoi(str) + if err != nil { + return fallback + } + + return value +} + func call(name string, args ...interface{}) error { const CORVID_DBUS_OBJECT = "/sh/cxl/Corvid" const CORVID_DBUS_NAME = "sh.cxl.Corvid" diff --git a/srv/notifServer.go b/srv/notifServer.go index d175055..a64a165 100644 --- a/srv/notifServer.go +++ b/srv/notifServer.go @@ -100,7 +100,7 @@ func (s notifServer) Notify(appName string, replacesId uint32, appIcon string, s } if expireTimeout == -1 { - expireTimeout = DEFAULT_EXPIRATION + expireTimeout = int32(DEFAULT_EXPIRATION) } notification := notification{ diff --git a/srv/server.go b/srv/server.go index 27ced3f..2500f62 100644 --- a/srv/server.go +++ b/srv/server.go @@ -11,8 +11,8 @@ import ( "github.com/godbus/dbus/v5" ) -const DEFAULT_EXPIRATION = 5000 -const SORT_DIRECTION = 1 // 1 = newest first, -1 = oldest first +var DEFAULT_EXPIRATION int +var SORT_DIRECTION int // 1 = newest first, -1 = oldest first type server struct { notifications *notificationStack @@ -80,12 +80,15 @@ func (s server) output() { fmt.Println(string(j)) } -func Start() { +func Start(defaultExpiration int, sortDirection int) { const NOTIF_DBUS_OBJECT = "/org/freedesktop/Notifications" const NOTIF_DBUS_NAME = "org.freedesktop.Notifications" const CORVID_DBUS_OBJECT = "/sh/cxl/Corvid" const CORVID_DBUS_NAME = "sh.cxl.Corvid" + DEFAULT_EXPIRATION = defaultExpiration + SORT_DIRECTION = sortDirection + notifications := notificationStack{ mutex: &sync.Mutex{}, notifications: make(map[uint32]notification), -- cgit v1.2.3