aboutsummaryrefslogtreecommitdiff
path: root/srv
diff options
context:
space:
mode:
authorCaroline Larimore <caroline@larimo.re>2025-01-30 22:26:55 -0800
committerCaroline Larimore <caroline@larimo.re>2025-01-30 22:26:55 -0800
commit8fcb05ee54e250ae23113549e09fc11410829272 (patch)
tree273c26a838973fdb448134be8ef34b791722338a /srv
parentd9ddbfa1b7e697884f2be1ea9f11f8ecb5a2027d (diff)
Add dismissal commands
Diffstat (limited to 'srv')
-rw-r--r--srv/corvidServer.go39
-rw-r--r--srv/notifServer.go76
-rw-r--r--srv/server.go88
3 files changed, 94 insertions, 109 deletions
diff --git a/srv/corvidServer.go b/srv/corvidServer.go
index 4a0556d..8b08a6e 100644
--- a/srv/corvidServer.go
+++ b/srv/corvidServer.go
@@ -1,39 +1,24 @@
package srv
import (
- "log"
-
"github.com/godbus/dbus/v5"
)
type corvidServer server
-func (s corvidServer) Test(param uint32) (e *dbus.Error) {
- log.Printf("Test called %d", param)
+func (s corvidServer) Dismiss(id uint32) (e *dbus.Error) {
+ // log.Print("Dismiss called")
+ server(s).close(id, CloseReasonDismissed)
+ server(s).output()
return nil
}
-// func (s corvidServer) GetCapabilities() (e *dbus.Error) {
-// log.Print("GetCapabilities called")
-// return nil
-// }
-
-// func (s corvidServer) GetServerInformation() (name, vendor, version, specVersion string, e *dbus.Error) {
-// // log.Print("GetServerInformation called")
-// return "corvid", "CartConnoisseur", "0.1.0", "1.2", nil
-// }
-
-// func (s corvidServer) CloseNotification(id uint32) (e *dbus.Error) {
-// // log.Printf("CloseNotification called: %d", id)
-// notification, ok := notifications.notifications[id]
-// if ok {
-// notification.close(CloseReasonClosed)
-// }
-
-// return nil
-// }
+func (s corvidServer) DismissAll() (e *dbus.Error) {
+ // log.Print("DismissAll called")
+ for _, notification := range s.notifications.notifications {
+ server(s).close(notification.Id, CloseReasonDismissed)
+ }
-// func (s corvidServer) Notify(appName string, replacesId uint32, appIcon string, summary string, body string, actions []string, hints map[string]dbus.Variant, expireTimeout int32) (id uint32, e *dbus.Error) {
-// // log.Print("Notify called")
-
-// }
+ server(s).output()
+ return nil
+}
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))
-}
diff --git a/srv/server.go b/srv/server.go
index 673081b..27ced3f 100644
--- a/srv/server.go
+++ b/srv/server.go
@@ -1,8 +1,11 @@
package srv
import (
+ "encoding/json"
"fmt"
"log"
+ "os"
+ "slices"
"sync"
"github.com/godbus/dbus/v5"
@@ -11,10 +14,70 @@ import (
const DEFAULT_EXPIRATION = 5000
const SORT_DIRECTION = 1 // 1 = newest first, -1 = oldest first
-type server = struct {
- conn *dbus.Conn
- object dbus.ObjectPath
- name string
+type server struct {
+ notifications *notificationStack
+ conn *dbus.Conn
+ object dbus.ObjectPath
+ name string
+}
+
+func (s server) 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)
+
+ 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 server) 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))
}
func Start() {
@@ -37,9 +100,10 @@ func Start() {
err = startDBusServer(
conn,
corvidServer{
- conn: conn,
- object: CORVID_DBUS_OBJECT,
- name: CORVID_DBUS_NAME,
+ notifications: &notifications,
+ conn: conn,
+ object: CORVID_DBUS_OBJECT,
+ name: CORVID_DBUS_NAME,
},
CORVID_DBUS_OBJECT,
CORVID_DBUS_NAME,
@@ -52,11 +116,9 @@ func Start() {
conn,
notifServer{
notifications: &notifications,
- server: server{
- conn: conn,
- object: NOTIF_DBUS_OBJECT,
- name: NOTIF_DBUS_NAME,
- },
+ conn: conn,
+ object: NOTIF_DBUS_OBJECT,
+ name: NOTIF_DBUS_NAME,
},
NOTIF_DBUS_OBJECT,
NOTIF_DBUS_NAME,
@@ -64,6 +126,8 @@ func Start() {
if err != nil {
log.Fatal(err)
}
+
+ fmt.Println("[]")
}
func startDBusServer(conn *dbus.Conn, v interface{}, object dbus.ObjectPath, name string) error {