hex/src/screenshots/narration.rs
Kit Langton a65a5e375f
feat(screenshots): record the screen, and keep captures until you close them (#1371)
* Talk over a screenshot: dictation words go with the shot

* Regenerate the screenshot editor goldens with the words row

* Cover the card held while someone talks over it

* Add the listening card's goldens

* Record the screen from Screenshots, ending in the corner card and a trim editor

* Move the capture timeline out, add the recording goldens and feature map

* Keep the replay's start on Windows quiet

* Keep the timeline move's imports and the replay start quiet off macOS

* Clear the record shortcut without returning its change

* Fix the macOS lints the recording left

* screenshots: only the open editor takes a dictation

A dictation taken while only the corner card showed used to talk over the
shot: the card held, showed "Listening…", and the words opened the shot in
the editor. That took the shortcut's normal paste away from everyone who
never asked for it.

Now only an open editor takes the words. While the card shows, a dictation
pastes as it did before the Lab, the card keeps its few seconds, and its
listening pill, hold and the narration path that opened the shot are gone.
The card's own card/listen/heard API goes with it, so nothing else can reach
the shot but the editor.

The i18n Screenshots rows move to i18n/labs.rs, where the Labs rows live,
so the main table stays under the source cap after dev's merge.

* screenshots: the editor's pieces come from the kit, and a shot grows in from where it was taken

The editor's toolbar was hand-made: five canvas-drawn tool glyphs in bespoke
hover chips, a bare ✕, a bare microphone, and action buttons stretched past
the kit's own height. The card's ✕ was a filled button beside them. They now
come from the rest of Hex: the tools are line icons beside the theme's own,
drawn by rune-kit icon buttons that fill while a tool is picked, ✕ and the
microphone and clear-words are the kit's ghost icon buttons like a capsule's,
and Copy, Save and Send to… are the kit's buttons at their own size. The
trim handles take the kit's corner.

A shot now grows in from the rectangle it was taken from. The card's overlay
is the whole display, so it can start anywhere on it: an area or window shot
starts at exactly the rectangle captured, at that size and place, and springs
into its corner slot on one spring that never overshoots its size, leaving
the same way. A whole-display shot keeps the slide in from the edge, and
Reduce Motion still only fades.

* screenshots: regenerate the editor and card goldens for the look pass

* docs: the card grows in from the shot's rectangle, and the editor is the kit's

* screenshots: a recording saves itself to the screenshots folder, as a shot does

* screenshots: cards stay until closed, stack in the corner, and take CleanShot's keys

* screenshots: Restore Last Capture in the menu bar brings back the card closed last

* screenshots: a Captures pane lists the last 30 days of shots and recordings

* screenshots: goldens for the card stack and the Captures pane, and its playground paths

* screenshots: the card's Return and the editor's file are macOS-only

* screenshots: pin that cards of any shape share the corner's right edge

* screenshots: keep macos_rune.rs and app_settings.rs under the file cap
2026-11-09 08:18:56 -08:00

92 lines
3.4 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! Labs › Screenshots: talking over a shot. A dictation that starts while a
//! shot's editor is open talks over that shot: its words show under the shot
//! and go with it to a session instead of being pasted. The corner card that
//! shows a fresh shot never takes words: a dictation while it shows pastes as
//! usual, so the shortcut behaves the way it did before the Lab.
//!
//! The dictation itself is the shortcut's own, on the loaded model and
//! through the same processing; only where its text lands changes.
//!
//! The listener calls [`started`], [`claim`], and [`ended`] from its own
//! thread at the dictation's start, finish, and discard or cancel.
use std::sync::atomic::{AtomicBool, Ordering};
use crate::control::{CaptureAction, PrintReply, PrintedTranscript};
use crate::rune_ui::screenshot_thumbnail::editor;
use editor::{Listen, Talk};
/// Whether the dictation now recording talks over the open shot.
static OVER: AtomicBool = AtomicBool::new(false);
/// A dictation started: with the Lab on and a shot's editor open, it talks
/// over that shot.
pub(crate) fn started() {
let talking = crate::labs::screenshots() && editor::is_open();
let before = OVER.swap(talking, Ordering::SeqCst);
if talking {
editor::listen(Listen::Recording);
} else if before {
editor::listen(Listen::Idle);
}
}
/// The dictation was discarded or cancelled: nothing lands.
pub(crate) fn ended() {
if OVER.swap(false, Ordering::SeqCst) {
editor::listen(Listen::Idle);
}
}
/// The dictation finished: the reply that carries its words to the open
/// shot, or `None` to paste them as usual. A dropped reply (a short, silent,
/// cancelled, or failed clip) lands nothing.
pub(crate) fn claim() -> Option<PrintReply> {
if !OVER.swap(false, Ordering::SeqCst) {
return None;
}
editor::listen(Listen::Transcribing);
let (reply, printed) = PrintReply::channel();
let spawned = std::thread::Builder::new()
.name("hex-screenshot-narration".into())
.spawn(move || {
let words = match printed.recv_timeout(crate::control::PRINT_WAIT) {
Ok(PrintedTranscript::Text(words)) => Some(words),
Ok(PrintedTranscript::Failed(error)) => {
tracing::warn!(%error, "the words over the screenshot failed");
None
}
_ => None,
};
editor::heard(words);
});
match spawned {
Ok(_) => Some(reply),
Err(error) => {
tracing::warn!(%error, "could not wait for the words over the screenshot");
None
}
}
}
/// The editor's microphone and Escape, through the listener as `hex
/// dictation` goes, so the shortcut and the chip finish each other's.
pub(crate) fn talk(talk: Talk) {
let Some(runtime) = crate::macos_rune::runtime() else {
return;
};
let action = match talk {
Talk::Toggle => CaptureAction::Toggle,
Talk::Cancel => CaptureAction::Cancel,
};
// The listener answers a reply nobody waits for.
let (reply, _) = std::sync::mpsc::sync_channel(1);
if let Err(error) = runtime.recognition(crate::recognition::RecognitionControl::Capture {
action,
print: None,
raw: false,
reply,
}) {
tracing::warn!(%error, "could not reach the listener for the screenshot");
}
}