Keep notification history on single lines with responsive navigation

This commit is contained in:
ak47 committed 2026-11-16 22:54:28 -05:00
1 parent 5dfa038706
commit 5fd5a26120
8 files changed
+398 -68

No files matched your search

@@ -0,0 +1,106 @@
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package app
import (
"context"
"encoding/json"
"io"
"log/slog"
"os"
"os/exec"
"strings"
"testing"
"time"
"git.stormux.org/storm/cthulhu/internal/atspi"
"git.stormux.org/storm/cthulhu/internal/braille"
"git.stormux.org/storm/cthulhu/internal/notificationui"
)
func TestNativeNotificationListOutput(t *testing.T) {
if os.Getenv("CTHULHU_NATIVE_NOTIFICATIONS") != "1" {
t.Skip("requires private notification UI session")
}
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
adapter := atspi.New()
if err := adapter.Start(ctx); err != nil {
t.Fatal(err)
}
defer adapter.Stop(context.Background())
queue := &autocompleteRequestQueue{requests: make(chan speechRequest, 256)}
frames := make(chan braille.Frame, 256)
done := make(chan struct{})
go func() {
defer close(done)
processEventsWithInput(ctx, slog.New(slog.DiscardHandler),
outputQueue{speech: queue, braille: frameRecorder{frames: frames}},
adapter, nil, nil, 0, nil, nil, nil, nil)
}()
defer func() { cancel(); <-done }()
command := exec.CommandContext(ctx, os.Getenv("CTHULHU_BINARY"), "--notification-list-ui")
in, err := command.StdinPipe()
if err != nil {
t.Fatal(err)
}
defer in.Close()
command.Stdout = io.Discard
command.Stderr = os.Stderr
if err := command.Start(); err != nil {
t.Fatal(err)
}
defer func() { _ = command.Process.Kill(); _ = command.Wait() }()
if err := json.NewEncoder(in).Encode(notificationui.Response{
Title: "Notification output test", Selected: "newest",
Entries: []notificationui.Entry{
{ID: "newest", Message: "Newest message", Received: "0 seconds ago"},
{ID: "middle", Message: "Middle\n\nmessage\tbody", Received: "1 minute ago"},
{ID: "oldest", Message: "Oldest message", Received: "2 minutes ago"},
},
}); err != nil {
t.Fatal(err)
}
wait := func(want string) {
t.Helper()
spoken, displayed := false, false
timer := time.NewTimer(4 * time.Second)
defer timer.Stop()
for !spoken || !displayed {
select {
case request := <-queue.requests:
t.Logf("speech: %q", request.Text)
spoken = spoken || strings.Contains(request.Text, want)
case frame := <-frames:
t.Logf("braille: %q", frame.Text)
displayed = displayed || strings.Contains(frame.Text, want)
case <-timer.C:
t.Fatalf("missing %q: speech=%v braille=%v", want, spoken, displayed)
case <-ctx.Done():
t.Fatal(ctx.Err())
}
}
}
wait("Newest message, 0 seconds ago")
for _, step := range []struct{ key, want string }{
{"Down", "Middle message body, 1 minute ago"},
{"Down", "Oldest message, 2 minutes ago"},
{"Up", "Middle message body, 1 minute ago"},
{"Home", "Newest message, 0 seconds ago"},
{"End", "Oldest message, 2 minutes ago"},
} {
if output, err := exec.CommandContext(ctx, "xdotool", "key", "--clearmodifiers", step.key).CombinedOutput(); err != nil {
t.Fatalf("%s: %v: %s", step.key, err, output)
}
wait(step.want)
}
if output, err := exec.CommandContext(ctx, "xdotool", "key", "--clearmodifiers", "Escape").CombinedOutput(); err != nil {
t.Fatalf("Escape: %v: %s", err, output)
}
if err := command.Wait(); err != nil {
t.Fatalf("closing notification list: %v", err)
}
}