← Otto Developer Guideotto-peek

User guide: Files
Specs: Peek, Peek text recognition

otto-peek is Peek, the preview that opens when you press Space on a file, in components/otto-peek/. It is a library the file views embed, not a service they call: a host draws the preview into a subsurface of its own window, so Peek has no window and no process of its own. What does run apart is the decoder. Every untrusted file is parsed in a sandboxed decode worker, which is the host’s own binary run again with --decode-worker. The crate also holds the shared thumbnail lookup and a background thumbnailer for apps that show files. It sits in the kit layer of architecture.toml.

Inside the host process a Session draws the preview and asks for decodes, which run in a sandboxed decode worker that may run rasterisers or tesseract; video plays in otto-media-worker

The decode worker, the payload, the decoders, the sandbox, thumbnails and the Peek panel in Files are described in depth in File Previews. Text recognised in pictures has its own page, Text in Pictures. This page is the map of the crate.

Modules

ModuleWhat it does
lib.rsrun_worker_if_requested, which every host calls first thing in main; thumbnail and generate_thumbnail
session.rsSession, the preview a host drives: zoom, pan, pages, word selection, links and video playback. Hosts hand it rects in their own coordinates
draw.rsPaints a Session’s content and badge, the same in every host
opening.rsThe opening animation’s geometry: the card grows out of the file’s rect
spawn.rsThe host side of a decode: open the file, start a contained worker, enforce the deadline
payload.rsThe wire format between worker and host, and its validation
decode/The decoders, one per kind (image, PDF, Markdown, text, listing, media), plus external.rs for programs run over the file. They run only inside the worker
sandbox.rsThe worker’s containment, and --sandbox-selftest
decode_cache.rsRecent decodes, so opening a file again skips the worker
ocr.rs, ocrcache.rs, badge.rsText in pictures: the recogniser, the words kept between runs, the corner badge
thumbcache.rs, thumbnailer.rsThe freedesktop thumbnail cache, and a thread that makes thumbnails off the UI thread
config.rsThe [peek] section of ~/.config/otto/files.toml
imagesize.rsA picture’s size from its header, for layout before any decode

How it runs

Each of these calls otto_peek::run_worker_if_requested() as the first line of main. Without it the worker would start a second copy of the host.

otto-peek depends on otto-kit for the preview vocabulary and drawing, otto-md-kit for Markdown, otto-media-kit without its default features for playback; image codecs and SVG come from Skia, through otto_kit::skia.

The otto-peek binary

The crate’s binary is the worker for its own runs and a previewer with no display: --describe PATH prints what the decoders made of a file, --render OUT.png PATH draws it through the same otto_kit::preview::draw a host uses, --filmstrip OUT.png PATH samples the opening animation, and --sandbox-selftest reports which containment measures hold on this machine.

Going deeper