diff options
| author | Caroline Larimore <caroline@larimo.re> | 2025-01-30 21:47:09 -0800 |
|---|---|---|
| committer | Caroline Larimore <caroline@larimo.re> | 2025-01-30 21:47:09 -0800 |
| commit | 4b5ff500b97cb86a5fbaaf5f3c5f9a004d1334f0 (patch) | |
| tree | bd1db5355acb7edb46294c67fc809036ba07c59f /notification.go | |
| parent | 784ee51b9613cac5764c9a33c343655e514e20f0 (diff) | |
Restructure
Diffstat (limited to 'notification.go')
| -rw-r--r-- | notification.go | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/notification.go b/notification.go deleted file mode 100644 index 2d5625d..0000000 --- a/notification.go +++ /dev/null @@ -1,86 +0,0 @@ -package main - -import ( - "encoding/json" - "log" - "os" - "time" - - "github.com/godbus/dbus/v5" -) - -type hint struct { - dbus.Variant -} - -func (h hint) MarshalJSON() ([]byte, error) { - //TODO: find a better way lol - switch h.Signature().String()[0] { - case 'y': - return json.Marshal(h.Value().(uint8)) - case 'b': - return json.Marshal(h.Value().(bool)) - case 'n': - return json.Marshal(h.Value().(int16)) - case 'q': - return json.Marshal(h.Value().(uint16)) - case 'i': - return json.Marshal(h.Value().(int32)) - case 'u': - return json.Marshal(h.Value().(uint32)) - case 'x': - return json.Marshal(h.Value().(int64)) - case 't': - return json.Marshal(h.Value().(uint64)) - case 'd': - return json.Marshal(h.Value().(float64)) - case 's': - return json.Marshal(h.Value().(string)) - default: - panic("Impossible type") - } -} - -type closeReason uint32 - -const ( - CloseReasonExpire closeReason = 1 - CloseReasonDismissed = iota - CloseReasonClosed = iota - CloseReasonOther = iota -) - -type notification struct { - Id uint32 `json:"id"` - AppName string `json:"app_name"` - AppIcon string `json:"app_icon"` - Summary string `json:"summary"` - Body string `json:"body"` - Actions map[string]string `json:"actions"` - Hints map[string]hint `json:"hints"` - Timestamp int64 `json:"timestamp"` - Expiration int32 `json:"expiration"` - Image string `json:"image"` - timer *time.Timer -} - -func (n notification) close(reason closeReason) { - notifications.mutex.Lock() - defer notifications.mutex.Unlock() - - if n.timer != nil { - n.timer.Stop() - } - - if n.Image != "" { - os.Remove(n.Image) - } - - delete(notifications.notifications, n.Id) - output() - - err := conn.Emit(DBUS_OBJECT, DBUS_NAME+".NotificationClosed", n.Id, reason) - if err != nil { - log.Print(err) - } -} |