Use shared internal UI toolkit v0.2.0
This commit is contained in:
1 parent
c1ca5746d0
commit
3d515b8810
11 files changed
+131
-831
No files matched your search
@@ -7,6 +7,7 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
commonui "git.stormux.org/storm/screenreader-common/internalui"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
@@ -32,6 +33,7 @@ type accessibleActionSource interface {
|
||||
PerformAccessibleAction(context.Context, atspi.ActionTarget, string) error
|
||||
}
|
||||
type internalUIResult struct {
|
||||
Controls map[string]commonui.Control // Submission only; may contain secrets.
|
||||
Activated string
|
||||
Values map[string]interaction.Value
|
||||
Cancelled bool
|
||||
@@ -85,6 +87,19 @@ func (ui *internalUI) open_form(ctx context.Context, form interaction.Form, loca
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ui.open_session(ctx, session, localOnly)
|
||||
}
|
||||
|
||||
// OpenUI is the core-only rich form API. localOnly preserves the same input
|
||||
// authorization boundary as OpenLocal; rich controls do not extend the wire API.
|
||||
func (ui *internalUI) OpenUI(ctx context.Context, form commonui.Form, localOnly bool) (<-chan internalUIResult, error) {
|
||||
session, err := interaction.NewUnifiedSession(form, commonui.Messages{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ui.open_session(ctx, session, localOnly)
|
||||
}
|
||||
func (ui *internalUI) open_session(ctx context.Context, session *interaction.Session, localOnly bool) (<-chan internalUIResult, error) {
|
||||
request := internalUIRequest{ctx: ctx, session: session, result: make(chan internalUIResult, 1), ready: make(chan error, 1), localOnly: localOnly}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -157,7 +172,9 @@ func (ui *internalUI) run(ctx context.Context) {
|
||||
var requestDone <-chan struct{}
|
||||
finish := func(reply internalUIResult) error {
|
||||
if emojiActive && session != nil {
|
||||
copyEmoji = session.Values()["copy"].Checked
|
||||
if values := session.Values(); values != nil {
|
||||
copyEmoji = values["copy"].Checked
|
||||
}
|
||||
}
|
||||
emojiActive = false
|
||||
if session != nil {
|
||||
@@ -177,7 +194,7 @@ func (ui *internalUI) run(ctx context.Context) {
|
||||
reply.Err = closeErr
|
||||
}
|
||||
if reply.Cancelled || reply.Err != nil {
|
||||
reply.Activated, reply.Values = "", nil
|
||||
reply.Activated, reply.Values, reply.Controls = "", nil, nil
|
||||
}
|
||||
result <- reply
|
||||
close(result)
|
||||
@@ -339,6 +356,9 @@ func (ui *internalUI) run(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
key := internal_ui_event(event)
|
||||
if emojiActive {
|
||||
copyEmoji = session.Values()["copy"].Checked
|
||||
}
|
||||
effect := session.Handle(key)
|
||||
if effect.Cancelled {
|
||||
_ = finish(internalUIResult{Cancelled: true})
|
||||
@@ -394,7 +414,8 @@ func (ui *internalUI) run(ctx context.Context) {
|
||||
}
|
||||
actionTarget := target
|
||||
selectedList := documentList
|
||||
closeErr := finish(internalUIResult{Activated: effect.Activated, Values: values})
|
||||
controls := session.ControlValues()
|
||||
closeErr := finish(internalUIResult{Activated: effect.Activated, Values: values, Controls: controls})
|
||||
if len(selectedList.Entries) > 0 && closeErr == nil && !ui.gate.Locked() && !ui.gate.Suspended() {
|
||||
index, err := strconv.Atoi(effect.Activated)
|
||||
if err == nil {
|
||||
|
||||
@@ -79,7 +79,7 @@ func TestInternalUISecretOutputAndLifetime(t *testing.T) {
|
||||
if got.Err != nil || got.Cancelled || got.Activated != "key" || got.Values["key"].Text != "fixture猫" {
|
||||
t.Fatal("secret not delivered on successful submission")
|
||||
}
|
||||
} else if got.Values != nil || got.Activated != "" || !got.Cancelled && got.Err == nil {
|
||||
} else if got.Values != nil || got.Controls != nil || got.Activated != "" || !got.Cancelled && got.Err == nil {
|
||||
t.Fatal("failed or cancelled form delivered secret values")
|
||||
}
|
||||
case <-ctx.Done():
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
common "git.stormux.org/storm/screenreader-common/internalui"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestInternalUIRichFormUsesExistingCaptureAndTypedValues(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
keys := &uiTestKeys{}
|
||||
output := &ocrTestOutput{speech: make(chan speechRequest, 16)}
|
||||
ui := &internalUI{keys: keys, speech: output, gate: &focusGate{}, events: make(chan input.CommandEvent, 16), requests: make(chan internalUIRequest, 1), done: make(chan struct{})}
|
||||
go ui.run(ctx)
|
||||
defer func() { cancel(); <-ui.done }()
|
||||
form := common.Form{Type: common.TabForm, Title: "Settings", Tabs: []common.Tab{{ID: "page", Label: "Page", Controls: []common.Control{
|
||||
{ID: "amount", Label: "Amount", Kind: common.Number, Number: 2, Min: 0, Max: 10, Step: 0.5},
|
||||
{ID: "ok", Label: "OK", Kind: common.Button, Action: "save"},
|
||||
}}}}
|
||||
// An unsupported local-only backend must still refuse authorization.
|
||||
if _, err := ui.OpenUI(ctx, form, true); err == nil {
|
||||
t.Fatal("local-only capture silently downgraded")
|
||||
}
|
||||
result, err := ui.OpenUI(ctx, form, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, symbol := range []uint32{0xff09, 0xff52, 0xff09, 0xff0d} {
|
||||
ui.Handle(input.CommandEvent{Command: input.InternalUIKey, UISession: 1, Chord: input.CommandChord{Symbol: symbol}})
|
||||
}
|
||||
select {
|
||||
case got := <-result:
|
||||
if got.Err != nil || got.Cancelled || got.Activated != "save" || got.Controls["page.amount"].Number != 3 || keys.InternalUISession() != 0 {
|
||||
t.Fatal("rich form submission or release failed")
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("rich form timed out")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user