← Otto Developer Guideotto-foundations

components/otto-foundations/ holds the small rules that several Otto programs have to agree on: where the XDG directories are, how a path becomes a file:// URI and back, how typed text is scored against a name, how a config or state file is replaced in one step, how a desktop entry’s keys are read and set, what the login name is, and how a program sets up its logging. It has no UI, no async runtime and no D-Bus. Its dependencies are percent-encoding and, for logging, tracing-subscriber.

It sits in the foundation layer (see Architecture Rules) and depends on no other workspace crate.

otto-foundations: the xdg, uri and matching modules, and the crates that link them

ModuleWhat it does
xdgThe XDG base directories (config_home, data_home, state_home, cache_home, runtime_dir, data_dirs, config_dirs), home, Otto’s config paths, the user’s folders from user-dirs.dirs (user_dirs, user_dir, parse_user_dirs), and the ~/… spelling of a path (tilde, tilde_in)
urifile:// URIs over a path’s bytes: path_to_uri, path_to_glib_uri (the thumbnail standard’s form), uri_to_path, encode_path, and two decoders: a lenient decode_path and a strict try_decode_path
matchingSubsequence scoring for typed queries (score, positions, word_positions), shared by the launcher, every toolkit list and file search
fswrite_atomically: replace a file so a reader sees the old one or the new one, never half of one
desktop_fileThe [Desktop Entry] group of a desktop entry’s text: value and entries read it, with_value sets a key and keeps every other line. The greeter’s sessions, Settings’ startup and autostart entries and the portal’s program names use it
userThe login name (login_name): $USER, then $LOGNAME
logginginit(default_filter): tracing events to stderr, filtered by RUST_LOG when it is set and parses, else by the program’s default

otto-kit re-exports every module (otto_kit::xdg, otto_kit::uri, otto_kit::matching, otto_kit::desktop_file, otto_kit::user, otto_kit::logging, and fs::write_atomically as otto_kit::fs::write_atomically beside the toolkit’s own file helpers), and toolkit apps import them from there. Crates that do not link the toolkit depend on otto-foundations directly:

Before this crate existed otto-kit depended on otto-search, a crate with zbus and tokio, only for name matching. The portal and the agents crates each carried their own copies of these helpers, and the copies did not always behave the same way.

The rules

Writing a file

fs::write_atomically(path, bytes) is how Settings writes files.toml, agents.toml, dictation.toml, the startup list and the autostart entry, and how Files writes files.toml and the desk’s desk.toml. Each of those is read by another program while it may be mid-write, so:

Adding to it

A helper belongs here when a program that does not link otto-kit needs it, and it needs only the standard library. logging is the one exception, with tracing-subscriber, because every program has to log the same way. A helper that draws, talks D-Bus or needs a runtime belongs somewhere else: otto-kit, otto-dbus or the crate that uses it.

See also

XDG specifications, otto-kit, otto-dbus.