prefs.rs

crates/veilvoice-gui/src/prefs.rs

veilvoice-gui · 1012 lines · read the source here · or on GitHub

What the user has chosen about how the app looks and moves.

Nothing here is secret, and nothing here is required

Preferences are a convenience. Every field has a working default, a missing file is not an error, and a corrupt one is not either -- it falls back to the defaults and says so in the settings panel rather than refusing to start. An app that will not open because its preferences file has a stray byte in it has turned a cosmetic setting into an outage.

This is deliberately not written through veilvoice_crypto::privatefile. That module exists for files whose contents are sensitive, and using it here would blur a distinction worth keeping: your choice of colour scheme is not a secret, and treating it like one would make the real protections look like decoration.

The format

One key = value per line, ASCII, with # comments -- readable and editable with any text editor, for the same reason the integrity manifest is a text format. No parser dependency, and no way for a malformed file to do anything more interesting than be ignored.

Animations

On by default, and switchable off in two places: the settings panel, and the VEILVOICE_NO_ANIMATION environment variable, which wins over the file so that a machine which struggles with them can be fixed without opening the UI that is struggling.

The system's own "reduce motion" setting is honoured above both. Someone who has told their operating system they do not want movement has already answered this question, and a privacy tool asking again -- and defaulting to yes -- would be ignoring them.

Two kinds of default, and which one this file holds

Roadmap item 170. Prefs::default is the written-down starting point: constants, chosen once, the same on every machine. It is what the tests construct and what a build with nothing to ask falls back to.

Prefs::starting_point is the one a real first run takes, and it is not the same thing. Where a value can be established by asking this machine, it is asked. Which is not most of them: a theme, a notification style and a vault folder are preferences and there is nothing to measure. The one that can be measured is the drawing path, and crate::probe is where that question is put. The other two the roadmap item names were already measured and were not described that way: frame_rate of 0 means the display's own rate, which crate::pace takes from the intervals between frames, and whether anything animates is resolved against the system's reduce-motion setting every frame by Motion::resolve.

The measurement happens once, on the run with no file to read, and is written into the file with everything else. Prefs::defaults_measured records that it happened, so the interface can say the machine was asked rather than implying it.

In plain words

What you have chosen about how VeilVoice looks and behaves, kept in a small text file.

The first time it runs, the things that can be worked out from your computer are worked out from your computer rather than guessed, and written down here so it only has to look once. All of them are still settings.

Nothing in it is secret and nothing in it is required: delete the file and the application opens with its defaults. You can read it and edit it by hand.

A setting this version does not recognise falls back to the default rather than stopping the program, and where the safe direction matters, the default is the one that keeps a protection on.

WHAT THIS FILE CONTAINS

1012 lines defining 11 functions (9 public), 2 types and 0 constants. Everything below is read out of the source, so it cannot disagree with the code.

The types it owns.

  • struct Prefs line 79 · Everything the user can choose about presentation.
  • struct Motion line 596 · Whether movement is allowed, and how much.

What happens when it runs. These are the ways in: public, and nothing else in this file calls them, so they are what an outside caller reaches first.

  • default_path line 273 · Where preferences live: beside the app lock, in this platform's config directory.
  • Prefs::starting_point line 314 · The preferences to open with: the file if there is one, and otherwise a look at this machine.
    reaches load, measured, default, parse, parse_bool
  • Prefs::save line 554 · Write preferences to path, creating the directory if needed.
    reaches to_text
  • Motion::resolve line 608 · Resolve for this frame.
  • Motion::secs line 626 · A duration scaled by whether motion is allowed.

WHAT CALLS WHAT

Prefs::default line 222 default_path line 273 Prefs::load line 284 Prefs::starting_point line 314 Prefs::measured line 344 Prefs::parse line 354 Prefs::to_text line 517 Prefs::save line 554 parse_bool line 578 Motion::resolve line 608 Motion::secs line 626 entry: a way in: public, and nothing in this file calls it api: public, and also used inside this file helper: private to this file dashed: a call that goes back up, or across a wrapped rank The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one.

The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one.

The same graph as Mermaid source
%%{init: {"theme":"base","themeVariables":{"background":"#1a1b26","primaryColor":"#1f2335","primaryTextColor":"#c0caf5","primaryBorderColor":"#7aa2f7","secondaryColor":"#16161e","tertiaryColor":"#16161e","lineColor":"#737aa2","textColor":"#c0caf5","mainBkg":"#1f2335","nodeBorder":"#7aa2f7","clusterBkg":"#16161e","clusterBorder":"#2f3549","fontFamily":"ui-monospace, SFMono-Regular, Consolas, monospace","fontSize":"14px"}}}%%
flowchart TD
    n_default["Prefs::default<br/>line 222"]
    n_default_path(["default_path<br/>line 273"])
    n_load["Prefs::load<br/>line 284"]
    n_starting_point(["Prefs::starting_point<br/>line 314"])
    n_measured["Prefs::measured<br/>line 344"]
    n_parse["Prefs::parse<br/>line 354"]
    n_to_text["Prefs::to_text<br/>line 517"]
    n_save(["Prefs::save<br/>line 554"])
    n_parse_bool["parse_bool<br/>line 578"]
    n_resolve(["Motion::resolve<br/>line 608"])
    n_secs(["Motion::secs<br/>line 626"])
    n_load --> n_default
    n_load --> n_parse
    n_measured --> n_default
    n_parse --> n_default
    n_parse --> n_parse_bool
    n_save --> n_to_text
    n_starting_point --> n_load
    n_starting_point --> n_measured
    click n_default href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L222" "open the source"
    click n_default_path href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L273" "open the source"
    click n_load href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L284" "open the source"
    click n_starting_point href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L314" "open the source"
    click n_measured href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L344" "open the source"
    click n_parse href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L354" "open the source"
    click n_to_text href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L517" "open the source"
    click n_save href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L554" "open the source"
    click n_parse_bool href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L578" "open the source"
    click n_resolve href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L608" "open the source"
    click n_secs href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-gui/src/prefs.rs#L626" "open the source"
    classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
    class n_default_path,n_starting_point,n_save,n_resolve,n_secs entry
    classDef api fill:#1f2335,stroke:#7dcfff,color:#c0caf5
    class n_load,n_measured,n_parse,n_to_text api
    classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
    class n_default,n_parse_bool helper
    subgraph chart_key ["Key"]
        direction LR
        key_entry["entry: a way in: public, and nothing in this file calls it"]
        key_api["api: public, and also used inside this file"]
        key_helper["helper: private to this file"]
    end
    class key_entry entry
    class key_api api
    class key_helper helper

This site loads no third-party script, so it cannot run Mermaid; the diagram above is the same nodes and edges drawn by the generator instead. GitHub renders the source below directly.

ITEMS

ItemLineDocumentation
Prefs pub struct79Everything the user can choose about presentation.
Prefs::default fn222
default_path pub fn273Where preferences live: beside the app lock, in this platform's config directory.
Prefs::load pub fn284Read preferences from path.
Prefs::starting_point pub fn314The preferences to open with: the file if there is one, and otherwise a look at this machine.
Prefs::measured pub fn344The starting point for a machine that has just been asked about itself.
Prefs::parse pub fn354Parse the key = value format.
Prefs::to_text pub fn517Serialise to the text format.
Prefs::save pub fn554Write preferences to path, creating the directory if needed.
parse_bool fn578One of the spellings people write for yes and no, as a bool.
Motion pub struct596Whether movement is allowed, and how much.
Motion::resolve pub fn608Resolve for this frame.
Motion::secs pub fn626A duration scaled by whether motion is allowed.