app: show the game being recorded while it runs
record-daemon / Check and lint (Linux) (push) Successful in 1m13s
record-daemon / Build (Windows x64) (push) Successful in 1m56s

The daemon's protocol says whether it is recording and which game it is
on, and nothing else, so the app could not say what was being recorded
or stop it.

A Recording screen now opens by itself when a recording starts, and at
launch if one is already running, and a button in the title bar brings it
back from any other screen. It shows the champion, the queue and the
summoner, when the game began, two clocks, the live scoreline and both
teams, and the clip being written as it grows on disk. The game's own
data is read once a second on a thread of its own, from the endpoint the
daemon polls for its events, which needs no login. Without an answer the
screen keeps what it has and says it is waiting.

Stop recording and Stop and delete end the game. A stop over the
protocol is not the stop the recorder gives a game that ends by itself.
The video lands in a new timeline while the open one is left behind,
which showed in the match history as a game that never happened, next to
one with no champion. Stopping from the app closes the open timeline into
the one holding the video, and deleting removes the clip and both. The
history skips timelines that have no end meanwhile, so a recording in
progress is not listed as a game.
This commit is contained in:
vhaudiquet committed 2026-11-23 22:46:44 +01:00
1 parent b9d97d0724
commit e546ab6969
6 files changed
+1522 -9

No files matched your search

+70 -3
View File
@@ -27,6 +27,7 @@ pub enum Screen {
Clips,
Clip,
Review,
Recording,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -118,6 +119,9 @@ pub struct Notice {
pub struct App {
pub screen: Screen,
/// Whether the screens show `history::sample` rather than the disk: a snapshot run, which
/// never starts the daemon and has nothing live to read.
pub sample: bool,
/// The screens behind this one, oldest first: the back arrow returns through them.
pub behind: Vec<Screen>,
pub settings_tab: SettingsTab,
@@ -160,6 +164,8 @@ pub struct App {
pub clips_menu_open: Option<usize>,
/// The clip the delete dialog is about, by its `id@start` key.
pub confirm_clip_delete: Option<String>,
/// The game being recorded: what the recording screen has read of it.
pub recording: screens::recording::State,
pub review: screens::review::Review,
pub portraits: Option<portraits::Portraits>,
/// The icons of the processes the audio sources name, decoded from their executables.
@@ -173,6 +179,7 @@ pub struct App {
pub clips_scroll: ui::ScrollBar,
pub highlights_scroll: ui::ScrollBar,
pub events_scroll: ui::ScrollBar,
pub recording_scroll: ui::ScrollBar,
pub notice: Option<Notice>,
/// ffmpeg being downloaded on the first run, and the whole percent it last reported.
pub ffmpeg_rx: Option<Receiver<export::FetchEvent>>,
@@ -194,6 +201,7 @@ impl App {
// `--live` renders headless but talks to the daemon and reads the real recordings.
let live = std::env::args().any(|arg| arg == "--live");
let mut app = Self {
sample: headless && !live,
screen: Screen::History,
behind: Vec::new(),
settings_tab: SettingsTab::Quick,
@@ -222,6 +230,7 @@ impl App {
thumbs_rx: None,
clips_menu_open: None,
confirm_clip_delete: None,
recording: screens::recording::State::default(),
review: screens::review::Review::default(),
portraits: None,
icons: None,
@@ -232,6 +241,7 @@ impl App {
clips_scroll: ui::ScrollBar::new(),
highlights_scroll: ui::ScrollBar::new(),
events_scroll: ui::ScrollBar::new(),
recording_scroll: ui::ScrollBar::new(),
notice: None,
ffmpeg_rx: None,
ffmpeg_pct: None,
@@ -574,6 +584,14 @@ impl App {
}
}
/// The container the recorder writes new recordings in, as the settings say.
pub fn container(&self) -> String {
self.settings
.as_ref()
.map(|settings| settings.output.container.clone())
.unwrap_or_else(|| self.form.draft.output.container.clone())
}
/// The folders a recording's clip may be in: the configured output folder first, then the
/// default one, where timelines and the clips folder live.
pub fn video_roots(&self) -> Vec<PathBuf> {
@@ -793,9 +811,23 @@ impl App {
self.refresh_games();
// A stop can take a moment to write the timeline; read it again shortly.
tx.wake_after(Duration::from_millis(1500));
if self.screen == Screen::Recording {
self.jump(Screen::History);
}
self.recording.forget();
}
self.tray_recording = self.status.is_recording;
}
// The screen a game opens: what is being recorded, until it stops. A recording that is
// already running when the app starts is the first thing it shows too.
if self.status.is_recording && !was_recording {
self.recording.begin();
if first {
self.jump(Screen::Recording);
} else {
self.go(Screen::Recording);
}
}
true
}
}
@@ -873,11 +905,13 @@ impl App {
(ipc::Request::StartRecording, Err(e)) => {
self.notify_error(format!("Cannot start recording: {e}"))
}
(ipc::Request::StopRecording, Ok(_)) => {
self.notify("Recording stopped");
self.refresh_games();
(ipc::Request::StopRecording, Ok(data)) => {
screens::recording::stopped(self, &data);
}
(ipc::Request::StopRecording, Err(e)) => {
// The stop never happened, so nothing was written: a "stop and delete" that
// failed must not turn into a plain stop later.
self.recording.deleting = false;
self.notify_error(format!("Cannot stop recording: {e}"))
}
(ipc::Request::Logs, Ok(data)) => {
@@ -1081,6 +1115,11 @@ impl App {
if self.screen == Screen::Review {
changed |= screens::review::tick(self, tx);
}
// The recording screen reads the game and the disk; it only does it while it shows,
// and reads them again on the way back in.
if self.screen == Screen::Recording {
changed |= screens::recording::tick(self, t);
}
changed |= screens::clip::tick(self, tx);
changed
}
@@ -1133,6 +1172,10 @@ pub fn on_key(app: &mut App, event: &KeyEvent, _tx: &mut Tx) -> bool {
app.confirm_delete = None;
true
}
(Key::Escape, _) if app.recording.confirm_delete => {
app.recording.confirm_delete = false;
true
}
(Key::Escape, _) if app.confirm_clip_delete.is_some() => {
app.confirm_clip_delete = None;
true
@@ -1224,6 +1267,7 @@ fn back_label(screen: Screen) -> &'static str {
Screen::Clip => "← Clip",
Screen::Review => "← Game",
Screen::Settings => "← Settings",
Screen::Recording => "← Recording",
}
}
@@ -1246,6 +1290,20 @@ fn titlebar(p: Paint, app: &App, insets: ChromeInsets) -> El {
// On the settings screen the title bar has nothing to offer: refreshing and opening
// settings again would only repeat what the screen already does.
if app.screen != Screen::Settings {
// A game being recorded is one click away, whatever screen the viewer wandered to.
if app.status.is_recording && app.screen != Screen::Recording {
actions = actions.child(ui::button(
p,
"open-recording",
"Recording",
false,
|app: &mut App| {
app.menu_open = None;
app.clips_menu_open = None;
app.jump(Screen::Recording);
},
));
}
if !matches!(app.screen, Screen::Clips | Screen::Clip) {
actions = actions.child(ui::button(
p,
@@ -1348,6 +1406,7 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
Screen::Clips => screens::clips::view(app, p, &mut overlays),
Screen::Clip => screens::clip::view(app, p),
Screen::Review => screens::review::view(app, p),
Screen::Recording => screens::recording::view(app, p),
};
let mut main = col().key("main").grow(1.0).min_h(0.0).w_full().fill(p.t.bg);
if let Some(banner) = &app.notice {
@@ -1373,6 +1432,11 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
.child(app.events_scroll.thumb(p, "events-thumb", "event-scroller")),
Screen::Review => window,
Screen::Clips => window.child(app.clips_scroll.thumb(p, "clips-thumb", "clips-scroller")),
Screen::Recording => window.child(app.recording_scroll.thumb(
p,
"recording-thumb",
"recording-scroller",
)),
Screen::Settings => window.child(app.scroll.thumb(p, "scroll-thumb", "scroller")),
Screen::History => window.child(app.scroll.thumb(p, "scroll-thumb", "list-scroller")),
// A clip fills its screen with a player, not a list: the history or settings thumb would
@@ -1388,6 +1452,9 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
if app.confirm_clip_delete.is_some() {
screens::clips::delete_dialog(app, p, &mut overlays);
}
if app.recording.confirm_delete {
screens::recording::confirm_dialog(app, p, &mut overlays);
}
rune_kit::root(content, overlays)
}
+343 -3
View File
@@ -147,8 +147,11 @@ pub fn timeline_dir() -> PathBuf {
/// recording is written when its game ends, which matches when it started closely enough for
/// a list that gets re-sorted by `start_time` as pages arrive.
pub fn timeline_paths() -> Vec<PathBuf> {
let dir = timeline_dir();
let Ok(entries) = std::fs::read_dir(&dir) else {
paths_in(&timeline_dir())
}
fn paths_in(dir: &Path) -> Vec<PathBuf> {
let Ok(entries) = std::fs::read_dir(dir) else {
return Vec::new();
};
let mut found: Vec<(std::time::SystemTime, PathBuf)> = entries
@@ -176,7 +179,10 @@ pub fn summaries(paths: &[PathBuf]) -> Vec<Summary> {
fn summary_of(path: &Path) -> Option<Summary> {
let text = std::fs::read_to_string(path).ok()?;
match serde_json::from_str::<Timeline>(&text) {
Ok(timeline) => Some(timeline.summary()),
// A game the recorder is still writing has no end yet: it is the recording screen's,
// and Match history is what has been recorded.
Ok(timeline) if timeline.end_time.is_some() => Some(timeline.summary()),
Ok(_) => None,
Err(e) => {
eprintln!("skipping {}: {e}", path.display());
None
@@ -300,6 +306,197 @@ fn delete_in(recording_id: &str, video: Option<&Path>, recordings: &Path) -> Res
Ok(())
}
/// The timeline a recording is being written into: the newest file with no end yet.
///
/// The recorder opens a timeline when a game starts and writes its end when it stops, so a
/// file without `end_time` is a game that is still going. The game id picks it out when the
/// client reported one; the newest open file is the answer otherwise.
/// The timeline a recording is being written into: the newest file with no end yet.
///
/// The recorder opens a timeline when a game starts and writes its end when it stops, so a
/// file without `end_time` is a game that is still going. The game id picks it out when the
/// client reported one; the newest open file is the answer otherwise.
pub fn open_timeline(game_id: Option<u64>) -> Option<(PathBuf, Timeline)> {
open_in(&timeline_dir(), game_id)
}
fn open_in(dir: &Path, game_id: Option<u64>) -> Option<(PathBuf, Timeline)> {
let mut newest = None;
// The file being written is the newest. One left open by an earlier stop can only be
// older than everything written since, so a few of the newest is enough.
for path in paths_in(dir).into_iter().take(4) {
let Ok(text) = std::fs::read_to_string(&path) else {
continue;
};
let Ok(timeline) = serde_json::from_str::<Timeline>(&text) else {
continue;
};
if timeline.end_time.is_some() {
continue;
}
if game_id.is_none() || timeline.game_id == game_id {
return Some((path, timeline));
}
if newest.is_none() {
newest = Some((path, timeline));
}
}
newest
}
/// The clip a recording is writing into `dir`, with the bytes on disk so far.
///
/// The recorder names the file when it starts and only reports it when it stops, so the file
/// is found rather than asked for: the newest one of the container the settings name that was
/// written since the recording began. `None` until it exists, and in a folder the recorder
/// writes nothing to.
pub fn writing_file(dir: &Path, container: &str, since: DateTime<Utc>) -> Option<(PathBuf, u64)> {
let since: std::time::SystemTime = (since - chrono::Duration::minutes(2)).into();
let entries = std::fs::read_dir(dir).ok()?;
let mut newest: Option<(std::time::SystemTime, PathBuf, u64)> = None;
for entry in entries.flatten() {
let path = entry.path();
if !path.is_file() {
continue;
}
let ours = path
.extension()
.and_then(|e| e.to_str())
.is_some_and(|e| e.eq_ignore_ascii_case(container));
if !ours {
continue;
}
let Ok(meta) = entry.metadata() else {
continue;
};
let Ok(written) = meta.modified() else {
continue;
};
if written < since {
continue;
}
if newest.as_ref().is_none_or(|(at, _, _)| written > *at) {
newest = Some((written, path, meta.len()));
}
}
newest.map(|(_, path, bytes)| (path, bytes))
}
/// Finish the timeline the recorder left open for a game the app stopped.
///
/// A game the recorder ends by itself is finalized: one timeline with the game, the video and
/// the end. Stopped over the protocol it writes the video into a new timeline and leaves the
/// open one behind, so Match history would show two rows for one game: a game that never
/// happened, and one with a video but no champion or queue. What the open timeline knows
/// moves to the one holding the video, and the leftover is deleted.
///
/// `discard` is the app's "stop and delete": the video goes with both timelines, so a game
/// stopped that way leaves nothing behind at all.
pub fn close_stopped(open: Option<&Path>, video: &Path, discard: bool) -> Result<(), String> {
close_stopped_in(&timeline_dir(), open, video, discard)
}
fn close_stopped_in(
dir: &Path,
open: Option<&Path>,
video: &Path,
discard: bool,
) -> Result<(), String> {
let held = timeline_for_video(dir, video);
if discard {
let mut failed = None;
let files = [
held.map(|(path, _)| path),
Some(video.to_path_buf()),
open.map(Path::to_path_buf),
];
for path in files.into_iter().flatten() {
if let Err(e) = remove(&path) {
failed.get_or_insert(e);
}
}
return failed.map_or(Ok(()), Err);
}
let (Some(open), Some((held, mut finished))) = (open, held) else {
return Ok(());
};
if held == open {
// The recorder finished this timeline itself: there is nothing to move.
return Ok(());
}
let text = std::fs::read_to_string(open)
.map_err(|e| format!("could not read {}: {e}", open.display()))?;
let game: Value = serde_json::from_str(&text)
.map_err(|e| format!("{} is not a timeline: {e}", open.display()))?;
// A file left open by some other game is not this one's to finish: merging two recordings
// would name one game with another's video.
let wanted = finished.get("game_id").and_then(Value::as_u64);
let offered = game.get("game_id").and_then(Value::as_u64);
if wanted.is_some() && offered.is_some() && wanted != offered {
return Ok(());
}
// The fields the recorder fills in when a game starts, which only the open timeline
// holds: everything a row names the game by.
for key in [
"game_id",
"raw_session",
"raw_summoner",
"raw_champion_select",
"raw_rune_page",
"raw_live_client_data",
] {
if finished.get(key).is_none_or(Value::is_null)
&& let Some(value) = game.get(key)
{
finished[key] = value.clone();
}
}
let json = serde_json::to_string_pretty(&finished)
.map_err(|e| format!("could not write {}: {e}", held.display()))?;
std::fs::write(&held, json).map_err(|e| format!("could not write {}: {e}", held.display()))?;
remove(open)
}
/// The timeline holding `video`, with its JSON, as the recorder writes it when it stops.
///
/// The clip's file name ties the two together: the recorder stores it in the timeline it
/// wrote for that clip.
fn timeline_for_video(dir: &Path, video: &Path) -> Option<(PathBuf, Value)> {
let name = video.file_name()?.to_str()?;
let entries = std::fs::read_dir(dir).ok()?;
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(|e| e.to_str()) != Some("json") {
continue;
}
let Ok(text) = std::fs::read_to_string(&path) else {
continue;
};
let Ok(value) = serde_json::from_str::<Value>(&text) else {
continue;
};
let stored = value.get("video_file").and_then(Value::as_str).or_else(|| {
value
.get("video_path")
.and_then(Value::as_str)
.and_then(|path| Path::new(path).file_name())
.and_then(|name| name.to_str())
});
if stored == Some(name) {
return Some((path, value));
}
}
None
}
/// Remove a file, saying which one could not go.
fn remove(path: &Path) -> Result<(), String> {
if !path.exists() {
return Ok(());
}
std::fs::remove_file(path).map_err(|e| format!("could not delete {}: {e}", path.display()))
}
impl Timeline {
fn end_stats(&self) -> Option<&Value> {
self.raw_end_game_stats.as_ref()
@@ -825,4 +1022,147 @@ mod tests {
let _ = std::fs::remove_dir_all(dir);
}
/// A timeline the recorder opened for a game, without an end yet.
fn open_game(game_id: u64, champion: &str) -> String {
serde_json::json!({
"recording_id": uuid::Uuid::new_v4().to_string(),
"start_time": "2026-03-27T16:42:52Z",
"end_time": null,
"duration_secs": 0,
"events": [],
"game_id": game_id,
"raw_session": {"gameData": {"queue": {"name": "Ranked Solo", "id": 420}}},
"raw_summoner": {"gameName": "Demo", "tagLine": "EUW"},
"raw_live_client_data": {"activePlayer": {"championName": champion}},
"video_file": null
})
.to_string()
}
fn write_timeline(dir: &Path, name: &str, json: &str) -> PathBuf {
let path = dir.join(format!("{name}.json"));
std::fs::write(&path, json).unwrap();
path
}
fn temp_dir() -> PathBuf {
let dir = std::env::temp_dir().join(format!("leaguerecorder-{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(&dir).unwrap();
dir
}
#[test]
fn the_game_being_recorded_is_the_timeline_without_an_end() {
let dir = temp_dir();
write_timeline(&dir, "finished", TIMELINE);
// Written last, so it is the newest: the game the recorder is writing.
let open = write_timeline(&dir, "open", &open_game(70, "Kai'Sa"));
assert_eq!(
open_in(&dir, Some(70)).map(|(path, _)| path),
Some(open.clone())
);
// The game id of a game that is not open falls back to the newest open file.
assert_eq!(open_in(&dir, Some(99)).map(|(path, _)| path), Some(open));
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn a_game_still_being_recorded_is_not_in_the_history() {
let dir = temp_dir();
let finished = write_timeline(&dir, "finished", TIMELINE);
let open = write_timeline(&dir, "open", &open_game(70, "Kai'Sa"));
let rows = summaries(&[finished, open]);
assert_eq!(rows.len(), 1, "only the game that ended has a row");
assert_eq!(rows[0].recording_id, parsed().recording_id);
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn a_stop_from_the_app_moves_the_game_onto_its_video() {
let dir = temp_dir();
let open = write_timeline(&dir, "open", &open_game(70, "Kai'Sa"));
// What the recorder writes when it stops over the protocol: the video, and no game.
let stopped = write_timeline(
&dir,
"stopped",
&serde_json::json!({
"recording_id": uuid::Uuid::new_v4().to_string(),
"start_time": "2026-03-27T16:42:52Z",
"end_time": "2026-03-27T16:55:00Z",
"duration_secs": 728,
"events": [],
"game_id": 70,
"video_file": "2026-03-27_16-42-52_7000000.mp4",
"video_path": "C:/clips/2026-03-27_16-42-52_7000000.mp4"
})
.to_string(),
);
let video = Path::new("C:/clips/2026-03-27_16-42-52_7000000.mp4");
close_stopped_in(&dir, Some(&open), video, false).unwrap();
assert!(!open.exists(), "the leftover timeline is deleted");
let merged: Value =
serde_json::from_str(&std::fs::read_to_string(&stopped).unwrap()).unwrap();
let game = Timeline {
raw_session: merged.get("raw_session").cloned(),
raw_summoner: merged.get("raw_summoner").cloned(),
..parsed()
};
assert_eq!(game.champion().as_deref(), Some("Kai'Sa"));
assert_eq!(game.summoner().as_deref(), Some("Demo#EUW"));
assert_eq!(game.queue_label(), "Ranked Solo");
// What the recorder wrote stays: the video and the end.
assert_eq!(merged["duration_secs"], 728);
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn stopping_and_deleting_takes_the_video_with_both_timelines() {
let dir = temp_dir();
let open = write_timeline(&dir, "open", &open_game(70, "Kai'Sa"));
let stopped = write_timeline(
&dir,
"stopped",
&serde_json::json!({
"recording_id": uuid::Uuid::new_v4().to_string(),
"start_time": "2026-03-27T16:42:52Z",
"end_time": "2026-03-27T16:55:00Z",
"duration_secs": 728,
"events": [],
"game_id": 70,
"video_file": "game.mp4"
})
.to_string(),
);
let clips = temp_dir();
let video = clips.join("game.mp4");
std::fs::write(&video, b"x").unwrap();
close_stopped_in(&dir, Some(&open), &video, true).unwrap();
assert!(!open.exists());
assert!(!stopped.exists());
assert!(!video.exists(), "the clip goes with it");
let _ = std::fs::remove_dir_all(dir);
let _ = std::fs::remove_dir_all(clips);
}
#[test]
fn the_clip_being_written_is_the_newest_of_its_container() {
let dir = temp_dir();
std::fs::write(dir.join("notes.txt"), b"n").unwrap();
std::fs::write(dir.join("old.mp4"), b"old").unwrap();
std::fs::write(dir.join("new.mp4"), b"newer!").unwrap();
let since = Utc::now() - chrono::Duration::minutes(1);
let (path, bytes) = writing_file(&dir, "mp4", since).unwrap();
assert_eq!(path.file_name().and_then(|n| n.to_str()), Some("new.mp4"));
assert_eq!(bytes, 6);
// Nothing was written since a folder scan later than every file: there is nothing to
// name until the recorder starts.
let later = Utc::now() + chrono::Duration::minutes(5);
assert!(writing_file(&dir, "mp4", later).is_none());
let _ = std::fs::remove_dir_all(dir);
}
}
+21
View File
@@ -42,6 +42,17 @@ fn attach_console() {}
use rune::AppSpec;
/// `--scene recording-live`: the daemon recording, with the sample game on the screen.
fn demo_recording(app: &mut app::App) {
app.status = app::Status {
status: "recording".into(),
is_recording: true,
current_game_id: Some(7_000_000),
client_connected: true,
};
screens::recording::demo(app);
}
fn main() {
attach_console();
if std::env::args().any(|arg| arg == "--games") {
@@ -82,6 +93,16 @@ fn main() {
rune::App::new(AppSpec {
scenes: &[
("history", |_app: &mut app::App| {}),
("recording-live", |app| {
demo_recording(app);
app.jump(app::Screen::Recording);
}),
("recording-live-delete", |app| {
demo_recording(app);
app.jump(app::Screen::Recording);
app.recording.confirm_delete = true;
}),
("recording-idle", |app| app.jump(app::Screen::Recording)),
("settings", |app| app.jump(app::Screen::Settings)),
("recording", |app| {
app.jump(app::Screen::Settings);
+3 -1
View File
@@ -1,7 +1,9 @@
//! The screens: settings, match history, the clips grid, one open clip and the game review.
//! The screens: settings, match history, the clips grid, one open clip, the game review and
//! the recording in progress.
pub mod clip;
pub mod clips;
pub mod history;
pub mod recording;
pub mod review;
pub mod settings;
File diff suppressed because it is too large. Load diff