aboutsummaryrefslogtreecommitdiffstats
path: root/internal/notify/icons_test.go
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-15 17:52:40 +0200
committerDanilo M. <danix@danix.xyz>2026-09-15 17:52:40 +0200
commit4eb086eeb44023aec23f5a48bd643b86024e3717 (patch)
tree4841add7da565af62f1078335d0f7a7e39820843 /internal/notify/icons_test.go
parent35f78d269b9f275aecf1bd26eaec8c4f5c3ef17e (diff)
downloadnotifyd-4eb086eeb44023aec23f5a48bd643b86024e3717.tar.gz
notifyd-4eb086eeb44023aec23f5a48bd643b86024e3717.zip
feat(notify): resolve theme icon names to files
qt6ct's icon_theme is authoritative on this desktop, with the GTK3 setting and hicolor as fallbacks. The lookup prefers scalable, then the largest raster, and follows the theme's Inherits chain, so an app that passes a name instead of a path gets an icon.
Diffstat (limited to 'internal/notify/icons_test.go')
-rw-r--r--internal/notify/icons_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/internal/notify/icons_test.go b/internal/notify/icons_test.go
new file mode 100644
index 0000000..527b330
--- /dev/null
+++ b/internal/notify/icons_test.go
@@ -0,0 +1,70 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+package notify
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+func TestResolveIconPathAndURI(t *testing.T) {
+ if got := ResolveIcon("/usr/share/icons/x/apps/48/firefox.png"); got != "/usr/share/icons/x/apps/48/firefox.png" {
+ t.Fatalf("path passthrough: %q", got)
+ }
+ if got := ResolveIcon("file:///tmp/shot.png"); got != "/tmp/shot.png" {
+ t.Fatalf("uri: %q", got)
+ }
+ if got := ResolveIcon(""); got != "" {
+ t.Fatalf("empty: %q", got)
+ }
+}
+
+func TestResolveIconThemeName(t *testing.T) {
+ root := t.TempDir()
+ // Theme "Plum" inherits "Base"; the icon is only in Base.
+ theme := filepath.Join(root, "icons", "Plum")
+ base := filepath.Join(root, "icons", "Base")
+ plumIndex := filepath.Join(theme, "index.theme")
+ baseApp := filepath.Join(base, "apps", "48")
+ if err := os.MkdirAll(filepath.Join(theme, "apps", "scalable"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.MkdirAll(baseApp, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(plumIndex, []byte("[Icon Theme]\nInherits=Base\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(baseApp, "firefox.svg"), []byte("<svg/>"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ t.Setenv("XDG_DATA_HOME", root)
+ t.Setenv("XDG_DATA_DIRS", "")
+ t.Setenv("HOME", filepath.Join(root, "home"))
+ if err := os.MkdirAll(filepath.Join(root, "home", ".config", "qt6ct"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(root, "home", ".config", "qt6ct", "qt6ct.conf"), []byte("icon_theme=Plum\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ got := ResolveIcon("firefox")
+ want := filepath.Join(root, "icons", "Base", "apps", "48", "firefox.svg")
+ if got != want {
+ t.Fatalf("resolved %q, want %q", got, want)
+ }
+ if got := ResolveIcon("no-such-icon-xyz"); got != "" {
+ t.Fatalf("missing name must be empty, got %q", got)
+ }
+}