diff options
| author | Caroline Larimore <caroline@larimo.re> | 2025-01-30 22:26:55 -0800 |
|---|---|---|
| committer | Caroline Larimore <caroline@larimo.re> | 2025-01-30 22:26:55 -0800 |
| commit | 8fcb05ee54e250ae23113549e09fc11410829272 (patch) | |
| tree | 273c26a838973fdb448134be8ef34b791722338a /srv/notifServer.go | |
| parent | d9ddbfa1b7e697884f2be1ea9f11f8ecb5a2027d (diff) | |
Add dismissal commands
Diffstat (limited to 'srv/notifServer.go')
| -rw-r--r-- | srv/notifServer.go | 76 |
1 files changed, 6 insertions, 70 deletions
diff --git a/srv/notifServer.go b/srv/notifServer.go index 00038cc..d175055 100644 --- a/srv/notifServer.go +++ b/srv/notifServer.go @@ -1,23 +1,17 @@ package srv import ( - "encoding/json" - "fmt" "image" "image/png" "log" "os" - "slices" "strings" "time" "github.com/godbus/dbus/v5" ) -type notifServer struct { - notifications *notificationStack - server -} +type notifServer server func (s notifServer) GetCapabilities() (capabilities []string, e *dbus.Error) { // log.Print("GetCapabilities called") @@ -34,7 +28,8 @@ func (s notifServer) GetServerInformation() (name, vendor, version, specVersion func (s notifServer) CloseNotification(id uint32) (e *dbus.Error) { // log.Printf("CloseNotification called: %d", id) - s.close(id, CloseReasonClosed) + server(s).close(id, CloseReasonClosed) + server(s).output() return nil } @@ -124,72 +119,13 @@ func (s notifServer) Notify(appName string, replacesId uint32, appIcon string, s if expireTimeout != 0 { notification.timer = time.AfterFunc(time.Duration(expireTimeout)*time.Millisecond, func() { - s.close(notification.Id, CloseReasonExpire) + server(s).close(notification.Id, CloseReasonExpire) + server(s).output() }) } s.notifications.notifications[id] = notification - s.output() + server(s).output() return id, nil } - -func (s notifServer) close(id uint32, reason closeReason) { - s.notifications.mutex.Lock() - defer s.notifications.mutex.Unlock() - - n, ok := s.notifications.notifications[id] - if !ok { - return - } - - if n.timer != nil { - n.timer.Stop() - } - - if n.Image != "" { - os.Remove(n.Image) - } - - delete(s.notifications.notifications, n.Id) - s.output() - - err := s.conn.Emit(s.object, s.name+".NotificationClosed", n.Id, reason) - if err != nil { - log.Print(err) - } -} - -// TODO: relocate to cmd/corvid -func (s notifServer) output() { - arr := make([]notification, len(s.notifications.notifications)) - - i := 0 - for _, notification := range s.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)) -} |