A key with `folder: NAME` swaps the deck to the keys defined under `folders.NAME`. Every folder shows a back key (slot 0 by default, drawn with a built-in chevron) that pops back to the parent; folders nest. The daemon now runs one page at a time: per-key setup moved into setupKey(), openPage() draws a page under its own context, and page.stop() tears it down before the next page is drawn (and on exit, so device death no longer waits on uncancelled goroutines). streamdeck-ctl gains `key set -folder`, reports kind "folder", lists every folder in status, and refuses to `key press` a navigation-only key. The Omarchy grid shows a folder glyph. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ARLa4moGb154fzc9TevgV
83 lines
1.8 KiB
Go
83 lines
1.8 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadFolders(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "config.yaml")
|
|
src := `
|
|
keys:
|
|
3:
|
|
icon: folder.png
|
|
folder: media
|
|
folders:
|
|
media:
|
|
back:
|
|
key: 7
|
|
icon: back.png
|
|
text: Up
|
|
keys:
|
|
0:
|
|
icon: play.png
|
|
command: play
|
|
1:
|
|
icon: more.png
|
|
folder: nested
|
|
nested:
|
|
keys:
|
|
1:
|
|
text: Deep
|
|
command: echo deep
|
|
`
|
|
if err := os.WriteFile(path, []byte(src), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
if got := cfg.Keys[3].Folder; got != "media" {
|
|
t.Errorf("key 3 folder = %q, want media", got)
|
|
}
|
|
media, ok := cfg.Folders["media"]
|
|
if !ok {
|
|
t.Fatal("folder media missing")
|
|
}
|
|
if media.BackKey() != 7 || media.Back.Icon != "back.png" || media.Back.Text != "Up" {
|
|
t.Errorf("media back = %+v (key %d)", media.Back, media.BackKey())
|
|
}
|
|
if media.Keys[0].Command != "play" || media.Keys[1].Folder != "nested" {
|
|
t.Errorf("media keys = %+v", media.Keys)
|
|
}
|
|
nested := cfg.Folders["nested"]
|
|
if nested.BackKey() != 0 {
|
|
t.Errorf("nested back key = %d, want default 0", nested.BackKey())
|
|
}
|
|
if nested.Keys[1].Text != "Deep" {
|
|
t.Errorf("nested keys = %+v", nested.Keys)
|
|
}
|
|
}
|
|
|
|
func TestApplyKeyEditFolder(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "config.yaml")
|
|
if err := os.WriteFile(path, []byte("keys: {}\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err := ApplyKeyEdit(path, 5, KeyEdit{Set: map[string]any{"icon": "f.png", "folder": "media"}})
|
|
if err != nil {
|
|
t.Fatalf("ApplyKeyEdit: %v", err)
|
|
}
|
|
cfg, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
if cfg.Keys[5].Folder != "media" || cfg.Keys[5].Icon != "f.png" {
|
|
t.Errorf("key 5 = %+v", cfg.Keys[5])
|
|
}
|
|
}
|