Use common v0.8.0 UI, transport, and translation APIs
This commit is contained in:
1 parent
317303adb7
commit
92fd479336
344 files changed
+4102
-4973
No files matched your search
@@ -14,9 +14,9 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
// Application_setting admits only settings which can be applied and restored
|
||||
// ApplicationSetting admits only settings which can be applied and restored
|
||||
// without changing devices, routing, storage, or other process-wide services.
|
||||
func Application_setting(path string) bool {
|
||||
func ApplicationSetting(path string) bool {
|
||||
switch path {
|
||||
case "presentation.speech.enabled", "presentation.speech.rate", "presentation.speech.pitch", "presentation.speech.volume", "presentation.speech.module", "presentation.speech.language", "presentation.speech.voice",
|
||||
"presentation.sound.enabled", "presentation.sound.volume", "presentation.progress.enabled",
|
||||
@@ -34,11 +34,11 @@ func Application_setting(path string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Open_application_document overlays a sparse, current-schema profile on the
|
||||
// OpenApplicationDocument overlays a sparse, current-schema profile on the
|
||||
// application's inherited settings. Missing files inherit everything.
|
||||
func Open_application_document(path string, base Settings) (*Document, error) {
|
||||
func OpenApplicationDocument(path string, base Settings) (*Document, error) {
|
||||
doc := &Document{Settings: base, path: path, applicationBase: &base, applicationFields: make(map[string]bool)}
|
||||
data, err := read_document(path)
|
||||
data, err := readDocument(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return doc, nil
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func Open_application_document(path string, base Settings) (*Document, error) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !Application_setting(path) {
|
||||
if !ApplicationSetting(path) {
|
||||
return fmt.Errorf("setting %s is not supported in application profiles", path)
|
||||
}
|
||||
doc.applicationFields[path] = true
|
||||
@@ -79,19 +79,19 @@ func Open_application_document(path string, base Settings) (*Document, error) {
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// Apply_application preserves inherited session state for every omitted field.
|
||||
func (d *Document) Apply_application(base Settings) Settings {
|
||||
// ApplyApplication preserves inherited session state for every omitted field.
|
||||
func (d *Document) ApplyApplication(base Settings) Settings {
|
||||
for path := range d.applicationFields {
|
||||
setting_value(reflect.ValueOf(&base).Elem(), path).Set(setting_value(reflect.ValueOf(d.Settings), path))
|
||||
settingValue(reflect.ValueOf(&base).Elem(), path).Set(settingValue(reflect.ValueOf(d.Settings), path))
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
func (d *Document) save_application(settings Settings) error {
|
||||
func (d *Document) saveApplication(settings Settings) error {
|
||||
fields := make(map[string]any)
|
||||
selectionChanged := false
|
||||
for _, path := range []string{"presentation.speech.module", "presentation.speech.language", "presentation.speech.voice"} {
|
||||
selectionChanged = selectionChanged || d.applicationFields[path] || !reflect.DeepEqual(setting_value(reflect.ValueOf(settings), path).Interface(), setting_value(reflect.ValueOf(*d.applicationBase), path).Interface())
|
||||
selectionChanged = selectionChanged || d.applicationFields[path] || !reflect.DeepEqual(settingValue(reflect.ValueOf(settings), path).Interface(), settingValue(reflect.ValueOf(*d.applicationBase), path).Interface())
|
||||
}
|
||||
var visit func(reflect.Value, reflect.Value, string)
|
||||
visit = func(value, base reflect.Value, prefix string) {
|
||||
@@ -103,7 +103,7 @@ func (d *Document) save_application(settings Settings) error {
|
||||
continue
|
||||
}
|
||||
speechSelection := selectionChanged && (path == "presentation.speech.module" || path == "presentation.speech.language" || path == "presentation.speech.voice")
|
||||
if !Application_setting(path) || (!speechSelection && !d.applicationFields[path] && reflect.DeepEqual(child.Interface(), inherited.Interface())) {
|
||||
if !ApplicationSetting(path) || (!speechSelection && !d.applicationFields[path] && reflect.DeepEqual(child.Interface(), inherited.Interface())) {
|
||||
continue
|
||||
}
|
||||
parts := strings.Split(path, ".")
|
||||
@@ -122,14 +122,14 @@ func (d *Document) save_application(settings Settings) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return save_data(d.path, data)
|
||||
return saveData(d.path, data)
|
||||
}
|
||||
|
||||
// Apply_application_settings copies the supported live settings only. Inherited
|
||||
// ApplyApplicationSettings copies the supported live settings only. Inherited
|
||||
// next-launch choices must never replace the running backend or layout.
|
||||
func Apply_application_settings(base Settings, source Settings) Settings {
|
||||
func ApplyApplicationSettings(base Settings, source Settings) Settings {
|
||||
for _, definition := range Definitions() {
|
||||
if Application_setting(definition.Path) {
|
||||
if ApplicationSetting(definition.Path) {
|
||||
if err := definition.Set(&base, definition.Value(source)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
func TestApplicationDocumentSparseInheritanceAndExplicitValues(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "applications", "ninjam.toml")
|
||||
base := Defaults()
|
||||
doc, err := Open_application_document(path, base)
|
||||
doc, err := OpenApplicationDocument(path, base)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func TestApplicationDocumentSparseInheritanceAndExplicitValues(t *testing.T) {
|
||||
// A new ordinary voice is inherited; explicitly saved rate/echo survive.
|
||||
base.Presentation.Speech.Voice = "New default"
|
||||
base.Presentation.Speech.Rate = 12
|
||||
doc, err = Open_application_document(path, base)
|
||||
doc, err = OpenApplicationDocument(path, base)
|
||||
if err != nil || doc.Settings.Presentation.Speech.Voice != "New default" || !doc.Settings.Keyboard.WordEcho {
|
||||
t.Fatal(doc, err)
|
||||
}
|
||||
@@ -42,14 +42,14 @@ func TestApplicationDocumentSparseInheritanceAndExplicitValues(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
base.Presentation.Speech.Rate = 60
|
||||
doc, err = Open_application_document(path, base)
|
||||
doc, err = OpenApplicationDocument(path, base)
|
||||
if err != nil || doc.Settings.Presentation.Speech.Rate != 12 {
|
||||
t.Fatal("explicit value equal to previous base lost", doc, err)
|
||||
}
|
||||
session := base
|
||||
session.Presentation.Speech.Enabled = false
|
||||
session.Reading.Automatic = false
|
||||
effective := doc.Apply_application(session)
|
||||
effective := doc.ApplyApplication(session)
|
||||
if effective.Presentation.Speech.Enabled || effective.Reading.Automatic || effective.Presentation.Speech.Rate != 12 {
|
||||
t.Fatal("session state overwritten", effective)
|
||||
}
|
||||
@@ -70,14 +70,14 @@ func TestApplicationDocumentRejectsInvalidProfilesAndExternalChanges(t *testing.
|
||||
if err := os.WriteFile(path, []byte(data), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := Open_application_document(path, Defaults()); err == nil {
|
||||
if _, err := OpenApplicationDocument(path, Defaults()); err == nil {
|
||||
t.Fatal("invalid profile accepted", data)
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile(path, []byte("[presentation.speech]\nrate = 10\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
doc, err := Open_application_document(path, Defaults())
|
||||
doc, err := OpenApplicationDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func TestApplicationVoiceSelectionSavedTogether(t *testing.T) {
|
||||
base := Defaults()
|
||||
base.Presentation.Speech.Module = "original-module"
|
||||
base.Presentation.Speech.Language = "en"
|
||||
doc, err := Open_application_document(path, base)
|
||||
doc, err := OpenApplicationDocument(path, base)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func TestApplicationVoiceSelectionSavedTogether(t *testing.T) {
|
||||
}
|
||||
base.Presentation.Speech.Module = "different-module"
|
||||
base.Presentation.Speech.Language = "fr"
|
||||
doc, err = Open_application_document(path, base)
|
||||
doc, err = OpenApplicationDocument(path, base)
|
||||
if err != nil || doc.Settings.Presentation.Speech.Module != "original-module" || doc.Settings.Presentation.Speech.Language != "en" || doc.Settings.Presentation.Speech.Voice != "Application voice" {
|
||||
t.Fatal("coupled voice selection changed", doc, err)
|
||||
}
|
||||
|
||||
+19
-18
@@ -172,17 +172,17 @@ type Reading struct {
|
||||
}
|
||||
|
||||
func Defaults() Settings {
|
||||
return Settings{InternalUI: InternalUI{AnnounceGridCoordinates: true, AnnounceItemPosition: true}, Screen: Screen{IgnoredVTs: []int{}}, Review: Review{LineBreak: true, EndOfScreen: true, LeaveReviewOnCursorChange: true, LeaveReviewOnScreenChange: true}, Prompt: Prompt{ExactMatches: []string{}, CustomPatterns: []string{}}, Version: 3, Presentation: Presentation{DateTime: DateTime{TimeFormat: "locale", DateFormat: "locale"}, Progress: Progress{Enabled: true}, Sound: Sound{Enabled: true, Volume: 0.7, Driver: "pulse", Theme: "default", Device: "default"}, Speech: Speech{Enabled: true, Rate: 0, Volume: 100, Driver: "speech-dispatcher"}}, Keyboard: Keyboard{MultiPressTimeoutMS: int(input.DefaultMultiPressTimeout / time.Millisecond), Layout: "desktop", CharacterEcho: true}, Reading: Reading{Emoticons: true, RepeatedSymbolsMin: 4, Spellcheck: true, SpellcheckSound: true, Attributes: "none", AttributeFormat: presentation.Default_attribute_format, Indentation: "none", RaisePitchForCapitals: true, Automatic: true, CursorEcho: true, Mode: "cursor", PunctuationProfile: "default", PunctuationLevel: "some"}, Clipboard: Clipboard{NumberOfClipboards: 200, ExportPath: "/tmp/fenrirClipboard"}, General: General{ScriptPath: "/usr/share/fenrirscreenreader/scripts", ScriptKeys: []string{"KEY_COMPOSE"}}, Scripts: Scripts{Workers: 2, QueueLimit: 16, OutputBytes: 1 << 20}, Remote: Remote{Enabled: true, EnableCommandRemote: true, EnableSettingsRemote: true}}
|
||||
return Settings{InternalUI: InternalUI{AnnounceGridCoordinates: true, AnnounceItemPosition: true}, Screen: Screen{IgnoredVTs: []int{}}, Review: Review{LineBreak: true, EndOfScreen: true, LeaveReviewOnCursorChange: true, LeaveReviewOnScreenChange: true}, Prompt: Prompt{ExactMatches: []string{}, CustomPatterns: []string{}}, Version: 3, Presentation: Presentation{DateTime: DateTime{TimeFormat: "locale", DateFormat: "locale"}, Progress: Progress{Enabled: true}, Sound: Sound{Enabled: true, Volume: 0.7, Driver: "pulse", Theme: "default", Device: "default"}, Speech: Speech{Enabled: true, Rate: 0, Volume: 100, Driver: "speech-dispatcher"}}, Keyboard: Keyboard{MultiPressTimeoutMS: int(input.DefaultMultiPressTimeout / time.Millisecond), Layout: "desktop", CharacterEcho: true}, Reading: Reading{Emoticons: true, RepeatedSymbolsMin: 4, Spellcheck: true, SpellcheckSound: true, Attributes: "none", AttributeFormat: presentation.DefaultAttributeFormat, Indentation: "none", RaisePitchForCapitals: true, Automatic: true, CursorEcho: true, Mode: "cursor", PunctuationProfile: "default", PunctuationLevel: "some"}, Clipboard: Clipboard{NumberOfClipboards: 200, ExportPath: "/tmp/fenrirClipboard"}, General: General{ScriptPath: "/usr/share/fenrirscreenreader/scripts", ScriptKeys: []string{"KEY_COMPOSE"}}, Scripts: Scripts{Workers: 2, QueueLimit: 16, OutputBytes: 1 << 20}, Remote: Remote{Enabled: true, EnableCommandRemote: true, EnableSettingsRemote: true}}
|
||||
}
|
||||
|
||||
func (s Settings) Validate() error {
|
||||
if err := s.VoiceProfiles.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := sound.Validate_selection(s.Presentation.Sound.Driver, s.Presentation.Sound.Device); err != nil {
|
||||
if err := sound.ValidateSelection(s.Presentation.Sound.Driver, s.Presentation.Sound.Device); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := sound.Validate_theme(s.Presentation.Sound.Theme); err != nil {
|
||||
if err := sound.ValidateTheme(s.Presentation.Sound.Theme); err != nil {
|
||||
return err
|
||||
}
|
||||
seenVTs := make(map[int]bool)
|
||||
@@ -198,26 +198,26 @@ func (s Settings) Validate() error {
|
||||
if _, err := prompt.New(s.Prompt.ExactMatches, s.Prompt.CustomPatterns); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := punctuation.Validate_name(s.Reading.PunctuationProfile); err != nil {
|
||||
if err := punctuation.ValidateName(s.Reading.PunctuationProfile); err != nil {
|
||||
return err
|
||||
}
|
||||
if s.Scripts.Workers < 1 || s.Scripts.Workers > 32 || s.Scripts.QueueLimit < 1 || s.Scripts.QueueLimit > 1024 || s.Scripts.OutputBytes < 1 || s.Scripts.OutputBytes > 4<<20 || s.Scripts.TimeoutSeconds < 0 || s.Scripts.TimeoutSeconds > 86400 {
|
||||
return fmt.Errorf("invalid script execution limits")
|
||||
}
|
||||
if s.Keyboard.FenrirKeys != nil {
|
||||
if err := input.Validate_modifier_keys(s.Keyboard.FenrirKeys, s.General.ScriptKeys); err != nil {
|
||||
if err := input.ValidateModifierKeys(s.Keyboard.FenrirKeys, s.General.ScriptKeys); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, key := range s.General.ScriptKeys {
|
||||
if _, ok := input.Key_code(key); !ok {
|
||||
if _, ok := input.KeyCode(key); !ok {
|
||||
return fmt.Errorf("invalid script key %q", key)
|
||||
}
|
||||
}
|
||||
if strings.ContainsAny(s.General.ScriptPath, "\x00\r\n") || strings.ContainsAny(s.Remote.SocketFile, "\x00\r\n") {
|
||||
return fmt.Errorf("invalid script or remote path")
|
||||
}
|
||||
if err := validate_definitions(s); err != nil {
|
||||
if err := validateDefinitions(s); err != nil {
|
||||
return err
|
||||
}
|
||||
if s.Clipboard.NumberOfClipboards < 1 || s.Clipboard.NumberOfClipboards > 10000 {
|
||||
@@ -230,7 +230,7 @@ func (s Settings) Validate() error {
|
||||
return fmt.Errorf("unsupported settings version %d (expected 3)", s.Version)
|
||||
}
|
||||
selected := s.Presentation.Speech
|
||||
if err := speech.Validate_driver_options(selected.Driver, speech.Options{Module: selected.Module, Language: selected.Language, Voice: selected.Voice, Hardware: speech.HardwareOptions{Device: selected.HardwareDevice, BaudRate: selected.HardwareBaudRate}}); err != nil {
|
||||
if err := speech.ValidateDriverOptions(selected.Driver, speech.Options{Module: selected.Module, Language: selected.Language, Voice: selected.Voice, Hardware: speech.HardwareOptions{Device: selected.HardwareDevice, BaudRate: selected.HardwareBaudRate}}); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, path := range s.Keyboard.Devices {
|
||||
@@ -269,10 +269,10 @@ func Decode(data []byte) (Settings, error) {
|
||||
return Settings{}, fmt.Errorf("parse settings: %w", err)
|
||||
}
|
||||
if header.Version == nil || *header.Version == 1 {
|
||||
return decode_v1(data)
|
||||
return decodeV1(data)
|
||||
}
|
||||
if *header.Version == 2 {
|
||||
return decode_v2(data)
|
||||
return decodeV2(data)
|
||||
}
|
||||
settings := Defaults()
|
||||
if err := toml.NewDecoder(bytes.NewReader(data)).DisallowUnknownFields().Decode(&settings); err != nil {
|
||||
@@ -309,10 +309,10 @@ func Load(requested string, paths []string) (Settings, string, error) {
|
||||
return Defaults(), "", nil
|
||||
}
|
||||
|
||||
// Load_startup loads settings and returns their save destination. System
|
||||
// LoadStartup loads settings and returns their save destination. System
|
||||
// fallback settings seed a user's first save without making /etc the destination.
|
||||
// An explicit --config path remains the destination; errors name the source.
|
||||
func Load_startup(requested string, paths []string) (Settings, string, error) {
|
||||
func LoadStartup(requested string, paths []string) (Settings, string, error) {
|
||||
settings, path, err := Load(requested, paths)
|
||||
if err == nil && requested == "" && len(paths) != 0 {
|
||||
path = paths[0]
|
||||
@@ -330,22 +330,22 @@ func Save(path string, settings Settings) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return save_data(path, data)
|
||||
return saveData(path, data)
|
||||
}
|
||||
|
||||
func save_data(path string, data []byte) error {
|
||||
func saveData(path string, data []byte) error {
|
||||
absolutePath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if absolutePath == SystemPath {
|
||||
// System settings also seed unprivileged users' first launch.
|
||||
return save_data_with_permissions(path, data, 0644, 0755)
|
||||
return saveDataWithPermissions(path, data, 0644, 0755)
|
||||
}
|
||||
return save_data_with_permissions(path, data, 0600, 0700)
|
||||
return saveDataWithPermissions(path, data, 0600, 0700)
|
||||
}
|
||||
|
||||
func save_data_with_permissions(path string, data []byte, fileMode, dirMode os.FileMode) error {
|
||||
func saveDataWithPermissions(path string, data []byte, fileMode, dirMode os.FileMode) error {
|
||||
dir := filepath.Dir(path)
|
||||
if err := os.MkdirAll(dir, dirMode); err != nil {
|
||||
return err
|
||||
@@ -354,7 +354,8 @@ func save_data_with_permissions(path string, data []byte, fileMode, dirMode os.F
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
// After a successful rename the temporary name no longer exists.
|
||||
defer func() { _ = os.Remove(file.Name()) }()
|
||||
if _, err := file.Write(data); err != nil {
|
||||
file.Close()
|
||||
return err
|
||||
|
||||
@@ -227,9 +227,9 @@ func TestAtomicSavePermissionsForSystemAndPersonalSettings(t *testing.T) {
|
||||
if system {
|
||||
// Exercise the system writer in a private directory, without
|
||||
// writing to the installed configuration or requiring root.
|
||||
return save_data_with_permissions(path, data, fileMode, dirMode)
|
||||
return saveDataWithPermissions(path, data, fileMode, dirMode)
|
||||
}
|
||||
return save_data(path, data)
|
||||
return saveData(path, data)
|
||||
}
|
||||
for _, data := range []string{"initial", "replacement"} {
|
||||
if err := save([]byte(data)); err != nil {
|
||||
|
||||
@@ -27,10 +27,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.stormux.org/storm/fenrir/internal/datetime"
|
||||
"git.stormux.org/storm/fenrir/internal/punctuation"
|
||||
"git.stormux.org/storm/fenrir/internal/sound"
|
||||
"git.stormux.org/storm/fenrir/internal/speech"
|
||||
"git.stormux.org/storm/screenreader-common/datetime"
|
||||
)
|
||||
|
||||
// Section and Definition are derived from the typed TOML schema. A labelled
|
||||
@@ -104,7 +104,7 @@ func Definitions() []Definition {
|
||||
return result
|
||||
}
|
||||
|
||||
func setting_value(settings reflect.Value, path string) reflect.Value {
|
||||
func settingValue(settings reflect.Value, path string) reflect.Value {
|
||||
for _, name := range strings.Split(path, ".") {
|
||||
structType := settings.Type()
|
||||
found := false
|
||||
@@ -123,7 +123,7 @@ func setting_value(settings reflect.Value, path string) reflect.Value {
|
||||
}
|
||||
|
||||
func (d Definition) Value(settings Settings) any {
|
||||
value := setting_value(reflect.ValueOf(settings), d.Path)
|
||||
value := settingValue(reflect.ValueOf(settings), d.Path)
|
||||
if value.Kind() == reflect.Slice {
|
||||
return append([]string(nil), value.Interface().([]string)...)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (d Definition) Value(settings Settings) any {
|
||||
|
||||
// Set assigns a typed draft value. Validation still runs on the entire draft.
|
||||
func (d Definition) Set(settings *Settings, value any) error {
|
||||
target := setting_value(reflect.ValueOf(settings).Elem(), d.Path)
|
||||
target := settingValue(reflect.ValueOf(settings).Elem(), d.Path)
|
||||
source := reflect.ValueOf(value)
|
||||
if !source.IsValid() || source.Type() != target.Type() {
|
||||
return fmt.Errorf("invalid value type for %s", d.Path)
|
||||
@@ -147,7 +147,7 @@ func (d Definition) Available(settings Settings) bool {
|
||||
if d.SpeechCapability == "" {
|
||||
return true
|
||||
}
|
||||
driver, err := speech.Find_driver(settings.Presentation.Speech.Driver)
|
||||
driver, err := speech.FindDriver(settings.Presentation.Speech.Driver)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func (d Definition) Choices(settings Settings) []Choice {
|
||||
home, _ := os.UserHomeDir()
|
||||
var result []Choice
|
||||
found := false
|
||||
for _, name := range sound.Theme_names(home) {
|
||||
for _, name := range sound.ThemeNames(home) {
|
||||
result = append(result, Choice{ID: name, Label: name})
|
||||
found = found || name == settings.Presentation.Sound.Theme
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (d Definition) Choices(settings Settings) []Choice {
|
||||
case "speech-baud":
|
||||
var result []Choice
|
||||
found := false
|
||||
for _, baud := range speech.Baud_rates() {
|
||||
for _, baud := range speech.BaudRates() {
|
||||
id := strconv.Itoa(baud)
|
||||
label := id
|
||||
if baud == 0 {
|
||||
@@ -212,9 +212,9 @@ func (d Definition) Choices(settings Settings) []Choice {
|
||||
return []Choice{{ID: "none", Label: "none"}, {ID: "speech", Label: "speech"}, {ID: "beeps", Label: "beeps"}, {ID: "both", Label: "speech and beeps"}}
|
||||
case "time-format", "date-format":
|
||||
now := time.Now()
|
||||
options := datetime.Time_options(now)
|
||||
options := datetime.TimeOptions(now)
|
||||
if d.ChoiceSource == "date-format" {
|
||||
options = datetime.Date_options(now)
|
||||
options = datetime.DateOptions(now)
|
||||
}
|
||||
var result []Choice
|
||||
for _, option := range options {
|
||||
@@ -249,7 +249,7 @@ func (d Definition) Choices(settings Settings) []Choice {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validate_definitions(settings Settings) error {
|
||||
func validateDefinitions(settings Settings) error {
|
||||
for _, definition := range Definitions() {
|
||||
if !definition.Available(settings) {
|
||||
continue
|
||||
@@ -269,7 +269,7 @@ func validate_definitions(settings Settings) error {
|
||||
// Driver support is independent of transient local availability. Module
|
||||
// choices are discovered by the selected backend, never a static allowlist.
|
||||
if definition.ChoiceSource == "speech-driver" {
|
||||
if _, err := speech.Find_driver(value.(string)); err != nil {
|
||||
if _, err := speech.FindDriver(value.(string)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -286,9 +286,9 @@ func validate_definitions(settings Settings) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ordered_sections preserves explicit sibling order and appends omitted sections
|
||||
// OrderedSections preserves explicit sibling order and appends omitted sections
|
||||
// in schema order. Nested paths never create duplicate top-level tabs.
|
||||
func Ordered_sections(sections []Section, order []string) []Section {
|
||||
func OrderedSections(sections []Section, order []string) []Section {
|
||||
result := append([]Section(nil), sections...)
|
||||
ranks := make(map[string]int)
|
||||
for index, id := range order {
|
||||
|
||||
@@ -44,7 +44,7 @@ type Document struct {
|
||||
applicationFields map[string]bool
|
||||
}
|
||||
|
||||
func read_document(path string) ([]byte, error) {
|
||||
func readDocument(path string) ([]byte, error) {
|
||||
// Remote SAVEAS can name an arbitrary destination. A FIFO must not
|
||||
// block opening before we can establish that it is a regular file.
|
||||
file, err := os.OpenFile(path, os.O_RDONLY|syscall.O_NONBLOCK, 0)
|
||||
@@ -66,9 +66,9 @@ func read_document(path string) ([]byte, error) {
|
||||
return data, err
|
||||
}
|
||||
|
||||
func Open_document(path string, fallback Settings) (*Document, error) {
|
||||
func OpenDocument(path string, fallback Settings) (*Document, error) {
|
||||
doc := &Document{Settings: fallback, path: path}
|
||||
data, err := read_document(path)
|
||||
data, err := readDocument(path)
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -143,7 +143,7 @@ func Open_document(path string, fallback Settings) (*Document, error) {
|
||||
// Save checks for external edits made since the menu opened before writing.
|
||||
// Atomic replacement uses the same system/private permissions policy as Save.
|
||||
func (d *Document) Save(settings Settings) error {
|
||||
data, err := read_document(d.path)
|
||||
data, err := readDocument(d.path)
|
||||
if d.existed {
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -160,14 +160,14 @@ func (d *Document) Save(settings Settings) error {
|
||||
return err
|
||||
}
|
||||
if d.applicationBase != nil {
|
||||
return d.save_application(settings)
|
||||
return d.saveApplication(settings)
|
||||
}
|
||||
// The same schema drives persistence and the form, including nested groups.
|
||||
var output bytes.Buffer
|
||||
fmt.Fprintf(&output, "version = %d\n", settings.Version)
|
||||
var encode func([]Section) error
|
||||
encode = func(sections []Section) error {
|
||||
for _, section := range Ordered_sections(sections, d.Order) {
|
||||
for _, section := range OrderedSections(sections, d.Order) {
|
||||
if section.ID == "voice_profiles" {
|
||||
if len(settings.VoiceProfiles.Profiles) == 0 {
|
||||
continue
|
||||
@@ -181,7 +181,7 @@ func (d *Document) Save(settings Settings) error {
|
||||
continue
|
||||
}
|
||||
|
||||
value := setting_value(reflect.ValueOf(settings), section.ID)
|
||||
value := settingValue(reflect.ValueOf(settings), section.ID)
|
||||
fields := make(map[string]any)
|
||||
for index := range value.NumField() {
|
||||
if value.Field(index).Kind() != reflect.Struct {
|
||||
@@ -209,5 +209,5 @@ func (d *Document) Save(settings Settings) error {
|
||||
if err := encode(Sections()); err != nil {
|
||||
return err
|
||||
}
|
||||
return save_data(d.path, output.Bytes())
|
||||
return saveData(d.path, output.Bytes())
|
||||
}
|
||||
@@ -30,7 +30,7 @@ func TestDocumentPreservesSectionOrderAndPrivateAtomicSave(t *testing.T) {
|
||||
if err := os.WriteFile(path, []byte("version=1\n[ 'speech' ]\nrate=40\n[reading]\nautomatic=false\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
doc, err := Open_document(path, Defaults())
|
||||
doc, err := OpenDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func TestDocumentPreservesSectionOrderAndPrivateAtomicSave(t *testing.T) {
|
||||
if err := doc.Save(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := Open_document(path, Defaults())
|
||||
loaded, err := OpenDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func TestDocumentRejectsExternalEditsAndInvalidSettings(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
doc, err := Open_document(path, Defaults())
|
||||
doc, err := OpenDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func TestDocumentRejectsExternalEditsAndInvalidSettings(t *testing.T) {
|
||||
|
||||
func TestDocumentDefaultsAndDottedTables(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "settings.toml")
|
||||
doc, err := Open_document(path, Defaults())
|
||||
doc, err := OpenDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -109,14 +109,14 @@ func TestDocumentDefaultsAndDottedTables(t *testing.T) {
|
||||
if err := os.WriteFile(path, []byte("reading.automatic=false\nspeech = {rate=30}\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
doc, err = Open_document(path, Defaults())
|
||||
doc, err = OpenDocument(path, Defaults())
|
||||
if err != nil || !reflect.DeepEqual(doc.Order, []string{"reading", "presentation", "presentation.speech"}) {
|
||||
t.Fatal(doc, err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(strings.Repeat("#", (1<<20)+1)), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := Open_document(path, Defaults()); err == nil {
|
||||
if _, err := OpenDocument(path, Defaults()); err == nil {
|
||||
t.Fatal("oversize document accepted")
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,9 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
// decode_v1 is the explicit migration boundary for the prototype's flat
|
||||
// decodeV1 is the explicit migration boundary for the prototype's flat
|
||||
// speech/sound tables. Unknown keys and mixed old/new schemas are rejected.
|
||||
func decode_v1(data []byte) (Settings, error) {
|
||||
func decodeV1(data []byte) (Settings, error) {
|
||||
defaults := Defaults()
|
||||
type oldSpeech struct {
|
||||
Enabled bool `toml:"enabled"`
|
||||
@@ -61,7 +61,7 @@ func decode_v1(data []byte) (Settings, error) {
|
||||
|
||||
// Version 2 briefly exposed Socket under Presentation. Migrate it away without
|
||||
// carrying an endpoint override into either runtime settings or future saves.
|
||||
func decode_v2(data []byte) (Settings, error) {
|
||||
func decodeV2(data []byte) (Settings, error) {
|
||||
defaults := Defaults()
|
||||
var old struct {
|
||||
Version int `toml:"version"`
|
||||
|
||||
@@ -54,7 +54,7 @@ cursor_echo = false
|
||||
if err := os.WriteFile(path, original, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
doc, err := Open_document(path, Defaults())
|
||||
doc, err := OpenDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -78,7 +78,7 @@ cursor_echo = false
|
||||
if err != nil || !strings.Contains(string(data), "version = 3") || strings.Contains(string(data), "\n[sound]") || strings.Contains(string(data), "socket =") {
|
||||
t.Fatal(string(data), err)
|
||||
}
|
||||
got, err := Open_document(path, Defaults())
|
||||
got, err := OpenDocument(path, Defaults())
|
||||
wantedOrder := []string{"clipboard", "presentation", "presentation.sound", "presentation.speech", "presentation.progress", "presentation.time_and_date", "keyboard", "reading", "internal_ui", "review", "screen", "general", "scripts", "remote", "prompt"}
|
||||
if err != nil || !reflect.DeepEqual(got.Settings, wanted) || !reflect.DeepEqual(got.Order, wantedOrder) {
|
||||
t.Fatal(got, err)
|
||||
@@ -114,7 +114,7 @@ func TestNestedDottedAndInlineSectionsShareOrder(t *testing.T) {
|
||||
if err := os.WriteFile(path, []byte(input), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
doc, err := Open_document(path, Defaults())
|
||||
doc, err := OpenDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func TestNestedDottedAndInlineSectionsShareOrder(t *testing.T) {
|
||||
if err := doc.Save(doc.Settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
saved, err := Open_document(path, Defaults())
|
||||
saved, err := OpenDocument(path, Defaults())
|
||||
if err == nil {
|
||||
saved.Settings.Keyboard.Devices = doc.Settings.Keyboard.Devices
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestMultiPressTimeoutDefaultsValidationAndSave(t *testing.T) {
|
||||
if err := Save(path, settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
doc, err := Open_document(path, Defaults())
|
||||
doc, err := OpenDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func TestPromptSettingsValidationAndSave(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(t.TempDir(), "settings.toml")
|
||||
doc, err := Open_document(path, settings)
|
||||
doc, err := OpenDocument(path, settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestReviewOptionsMigrationAndDocumentSave(t *testing.T) {
|
||||
if err := Save(path, settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
doc, err := Open_document(path, Defaults())
|
||||
doc, err := OpenDocument(path, Defaults())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestIgnoredVTValidationAndPersistence(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(t.TempDir(), "settings.toml")
|
||||
doc, err := Open_document(path, settings)
|
||||
doc, err := OpenDocument(path, settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestScriptDefaultsAndSaveRoundTrip(t *testing.T) {
|
||||
t.Fatal(version, settings, err)
|
||||
}
|
||||
path := filepath.Join(t.TempDir(), "settings.toml")
|
||||
doc, err := Open_document(path, settings)
|
||||
doc, err := OpenDocument(path, settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ func TestStartupSaveDestinationAndLegacySettingsIgnored(t *testing.T) {
|
||||
paths, destination = []string{systemPath}, systemPath
|
||||
}
|
||||
systemBefore, _ := os.ReadFile(systemPath)
|
||||
settings, path, err := Load_startup(requested, paths)
|
||||
settings, path, err := LoadStartup(requested, paths)
|
||||
if err != nil || path != destination || settings.Presentation.Speech.Rate != rate {
|
||||
t.Fatalf("startup: destination=%q rate=%d err=%v", path, settings.Presentation.Speech.Rate, err)
|
||||
}
|
||||
// Follow the settings menu's document save workflow, then restart.
|
||||
doc, err := Open_document(path, settings)
|
||||
doc, err := OpenDocument(path, settings)
|
||||
if err != nil || doc.Settings.Presentation.Speech.Rate != rate {
|
||||
t.Fatalf("open settings: %+v %v", doc, err)
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func TestStartupSaveDestinationAndLegacySettingsIgnored(t *testing.T) {
|
||||
if err := doc.Save(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
restarted, path, err := Load_startup(requested, paths)
|
||||
restarted, path, err := LoadStartup(requested, paths)
|
||||
if err != nil || path != destination || restarted.Presentation.Speech.Rate != 55 {
|
||||
t.Fatalf("restart: destination=%q rate=%d err=%v", path, restarted.Presentation.Speech.Rate, err)
|
||||
}
|
||||
@@ -86,10 +86,10 @@ func TestStartupErrorsIdentifySource(t *testing.T) {
|
||||
if err := os.WriteFile(systemPath, []byte("invalid=true"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, path, err := Load_startup("", []string{userPath, systemPath}); err == nil || path != systemPath {
|
||||
if _, path, err := LoadStartup("", []string{userPath, systemPath}); err == nil || path != systemPath {
|
||||
t.Fatal("invalid fallback did not identify source", path, err)
|
||||
}
|
||||
if _, path, err := Load_startup(userPath, []string{systemPath}); err == nil || path != userPath {
|
||||
if _, path, err := LoadStartup(userPath, []string{systemPath}); err == nil || path != userPath {
|
||||
t.Fatal("explicit missing file did not identify source", path, err)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ package config
|
||||
|
||||
import "git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
|
||||
func Primary_voice(settings Settings) voiceprofiles.Profile {
|
||||
func PrimaryVoice(settings Settings) voiceprofiles.Profile {
|
||||
s := settings.Presentation.Speech
|
||||
p := voiceprofiles.Profile{Driver: s.Driver, Module: s.Module, Language: s.Language, Voice: s.Voice, Rate: s.Rate, Pitch: s.Pitch, Volume: s.Volume}
|
||||
if s.Driver != "speech-dispatcher" {
|
||||
@@ -22,7 +22,7 @@ func Primary_voice(settings Settings) voiceprofiles.Profile {
|
||||
return p
|
||||
}
|
||||
|
||||
func Apply_primary_voice(settings Settings, p voiceprofiles.Profile) (Settings, error) {
|
||||
func ApplyPrimaryVoice(settings Settings, p voiceprofiles.Profile) (Settings, error) {
|
||||
if err := p.Normalize().Validate(); err != nil {
|
||||
return settings, err
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestVoiceProfilesPersistenceAndPrimaryScope(t *testing.T) {
|
||||
p := voiceprofiles.Profile{Name: "Reading", Driver: "speech-dispatcher", Module: "fixture", Voice: "Reader", Language: "es", Rate: 30, Pitch: -5, Volume: 80}
|
||||
settings.VoiceProfiles.Profiles = []voiceprofiles.Profile{p}
|
||||
path := filepath.Join(t.TempDir(), "settings.toml")
|
||||
doc, err := Open_document(path, settings)
|
||||
doc, err := OpenDocument(path, settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func TestVoiceProfilesPersistenceAndPrimaryScope(t *testing.T) {
|
||||
t.Fatal(loaded.VoiceProfiles, err)
|
||||
}
|
||||
original := loaded
|
||||
loaded, err = Apply_primary_voice(loaded, p)
|
||||
loaded, err = ApplyPrimaryVoice(loaded, p)
|
||||
if err != nil || loaded.Presentation.Speech.Voice != "Reader" || loaded.Presentation.Speech.Rate != 30 {
|
||||
t.Fatal(loaded, err)
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func TestVoiceProfilesPersistenceAndPrimaryScope(t *testing.T) {
|
||||
t.Fatal("profile changed unrelated settings")
|
||||
}
|
||||
loaded.VoiceProfiles = loaded.VoiceProfiles.Remove(0)
|
||||
doc, err = Open_document(path, loaded)
|
||||
doc, err = OpenDocument(path, loaded)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user