From 3b8a0e0f4a5c28394ac578e8559bf57ae82d3fd2 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 15 Sep 2026 17:59:35 +0200 Subject: feat(notify): add the image field and its cleanup Popup gains image, and the store calls an injected removeImage when an entry is dismissed, evicted, replaced or expired, so a daemon-written PNG does not outlive its balloon. The service decides what is daemon-owned; the store only names the path. NewStore now takes the callback as a third parameter, so the service wires its removeImage in (unlinking only under ImagesDir) and the existing call sites pass nil. --- internal/notify/store_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'internal/notify/store_test.go') diff --git a/internal/notify/store_test.go b/internal/notify/store_test.go index 1fb8bdc..a0ab7be 100644 --- a/internal/notify/store_test.go +++ b/internal/notify/store_test.go @@ -23,6 +23,7 @@ func newTestStore() (*Store, *[]event) { s := NewStore( func(id, reason uint32) { *emitted = append(*emitted, event{id, reason}) }, func(live, history []Popup) {}, + nil, ) return s, emitted } @@ -131,3 +132,25 @@ func TestHistoryRingCapsAtTwenty(t *testing.T) { t.Errorf("history length = %d, want 20", got) } } + +func TestStoreRemovesImageOnDismissAndExpire(t *testing.T) { + var removed []string + s := NewStore(func(uint32, uint32) {}, func(_, _ []Popup) {}, func(p string) { removed = append(removed, p) }) + id, _ := s.Add(&Popup{Image: "/run/img/1.png"}, "", 0) + s.SetImage(id, "/run/img/other.png") + s.Dismiss(id, 2) + if len(removed) != 1 || removed[0] != "/run/img/other.png" { + t.Fatalf("dismiss removed %v", removed) + } +} + +func TestStoreRemovesImageOnReplace(t *testing.T) { + var removed []string + s := NewStore(func(uint32, uint32) {}, func(_, _ []Popup) {}, func(p string) { removed = append(removed, p) }) + s.Add(&Popup{Image: "/run/img/old.png"}, "tag", 0) + id, _ := s.Add(&Popup{Image: "/run/img/new.png"}, "tag", 0) + _ = id + if len(removed) != 1 || removed[0] != "/run/img/old.png" { + t.Fatalf("replace removed %v", removed) + } +} -- cgit v1.2.3