app: add native rune client for record-daemon

Replaces the Vue/Tauri front end with a rune app that speaks the daemon's
existing IPC protocol: settings (general, recording, audio), match history
and game review with a scrubber, event markers and ffmpeg highlight export.
Includes tray icon, launch at login, single instance, toasts, a headless
snapshot path for checking screens, and a cargo-packager NSIS config.

Rune is pinned to 4ddf696b0f and its three patched crates are vendored under
app/vendor, since a dependency's [patch.crates-io] does not apply to the app.

The daemon's OBS bootstrap never reached its IPC server on this machine, so
the live check is a `--probe` command; the wire format is covered by tests.
This commit is contained in:
vhaudiquet committed 2026-11-15 21:53:44 +01:00
1 parent d712c4ea85
commit 0377141e4f
349 files changed
+142819

No files matched your search

+617
View File
@@ -0,0 +1,617 @@
//! Game review: the recorded clip, a scrubber with event markers, highlights and export.
use std::sync::mpsc::{Receiver, channel};
use rune::tok::{radius, space, type_};
use rune::{El, Player, SurfaceFit, Tx, col, el, row, text};
use crate::app::{App, Screen};
use crate::format;
use crate::highlight::{self, Highlight};
use crate::history::{Outcome, Timeline};
use crate::ui::{self, Paint, body, heading};
#[derive(Default)]
pub struct Review {
pub game: Option<String>,
pub player: Option<Player>,
pub time: f64,
pub duration: f64,
pub scrubber_width: f32,
pub highlights: Vec<Highlight>,
pub export: Option<Receiver<Result<String, String>>>,
pub export_note: Option<String>,
pub error: Option<String>,
}
impl Review {
fn playback(&mut self) {
if let Some(player) = &self.player {
if player.is_playing() {
player.pause();
} else {
player.play();
}
}
}
fn seek(&mut self, seconds: f64) {
let at = seconds.clamp(0.0, self.duration.max(0.0));
if let Some(player) = &self.player {
player.seek(at);
self.time = at;
}
}
}
/// Open a game in the review screen and load its clip.
pub fn open(app: &mut App, index: usize) {
leave(app);
app.screen = Screen::Review;
let Some(game) = app.games.get(index) else {
return;
};
// Keep the recording id, not the row number: a new recording can re-sort the list.
app.review.game = Some(game.recording_id.clone());
let path = game.video_path();
let highlights = highlight::compute(
game,
game.summoner().as_deref(),
highlight::Options::default(),
);
let duration = game.duration_secs.max(0) as f64;
app.review.highlights = highlights;
app.review.duration = duration;
let Some(path) = path else {
app.review.error = Some(format!(
"No video file found for this recording ({}).",
game.video_file.as_deref().unwrap_or("unnamed")
));
return;
};
let player = Player::file(&path);
player.set_looping(false);
if let Some(waker) = &app.waker {
player.set_waker(waker.clone());
}
app.review.player = Some(player);
}
/// Leave the review screen and stop playback.
pub fn leave(app: &mut App) {
app.review.player = None;
app.review.game = None;
app.review.highlights.clear();
app.review.time = 0.0;
app.review.duration = 0.0;
app.review.error = None;
app.review.export_note = None;
app.review.export = None;
}
/// Called from `poll` while the review screen is up.
pub fn tick(app: &mut App, tx: &mut Tx) -> bool {
let mut changed = false;
if let Some(player) = &app.review.player {
let time = player.time();
if (time - app.review.time).abs() > 0.001 {
app.review.time = time;
changed = true;
}
if let Some(duration) = player.duration() {
if duration > 0.0 && (duration - app.review.duration).abs() > 0.05 {
app.review.duration = duration;
changed = true;
}
}
if app.review.error.is_none() {
if let rune::PlayerState::Failed(message) = player.state() {
app.review.error = Some(message);
changed = true;
}
}
if player.is_playing() {
tx.wake_after(std::time::Duration::from_millis(33));
}
}
if let Some(rx) = &app.review.export {
match rx.try_recv() {
Ok(Ok(path)) => {
app.review.export_note = Some(format!("Clip saved to {path}"));
app.review.export = None;
changed = true;
}
Ok(Err(e)) => {
app.review.export_note = Some(format!("Export failed: {e}"));
app.review.export = None;
changed = true;
}
Err(_) => {}
}
}
changed
}
pub fn view(app: &App, p: Paint) -> El {
let Some(game) = app.reviewed() else {
return col()
.key("review")
.padding(space::S6)
.child(text("No game selected.").font(body(13.0)).color(p.muted()));
};
let outcome = game.outcome();
let ink = match outcome {
Outcome::Victory => p.success(),
Outcome::Defeat => p.danger(),
Outcome::Terminated => p.muted(),
};
let header = row()
.key("review-header")
.w_full()
.center_y()
.justify_between()
.child(
row()
.key("review-title")
.gap(10.0)
.center_y()
.child(ui::button(
p,
"back",
"← Match history",
false,
|app: &mut App| {
leave(app);
app.screen = Screen::History;
},
))
.child(
text(game.champion().unwrap_or_else(|| "Unknown champion".into()))
.key("champion")
.font(heading(20.0))
.color(p.t.text),
)
.child(
text(outcome.label())
.key("outcome")
.font(type_::LABEL)
.color(ink),
)
.child(
text(format!(
"{} · {}",
game.queue_label(),
format::duration(app.review.duration)
))
.key("meta")
.font(body(12.0))
.color(p.muted()),
),
)
.child(
text(format::game_start(game.start_time))
.key("started")
.font(body(11.5))
.color(p.muted()),
);
col()
.key("review")
.w_full()
.h_full()
.padding(space::S6)
.gap(space::S3)
.child(header)
.child(video_stage(app, p))
.child(scrubber(app, p))
.child(
row()
.key("review-body")
.w_full()
.grow(1.0)
.min_h(0.0)
.gap(space::S3)
.child(highlights(app, p, game))
.child(events(app, p, game)),
)
}
fn video_stage(app: &App, p: Paint) -> El {
let mut stage = el()
.key("stage")
.w_full()
.grow(1.0)
.min_h(0.0)
.radius(radius::LG)
.fill(rune::Color::BLACK)
.clip_soft(radius::LG);
if let Some(player) = &app.review.player {
stage = stage.child(
el().key("video")
.w_full()
.h_full()
.video(player, SurfaceFit::Fit),
);
} else {
stage = stage.child(
col()
.key("stage-empty")
.w_full()
.h_full()
.center()
.gap(6.0)
.child(
text(
app.review
.error
.clone()
.unwrap_or_else(|| "Loading the clip…".into()),
)
.key("stage-message")
.font(body(13.0))
.color(p.muted()),
),
);
}
col()
.key("stage-column")
.w_full()
.grow(1.0)
.min_h(0.0)
.gap(space::S2)
.child(stage)
.child(
row()
.key("transport")
.w_full()
.center_y()
.gap(space::S3)
.child(ui::button(
p,
"play-pause",
if playing(app) { "Pause" } else { "Play" },
false,
|app: &mut App| {
app.review.playback();
},
))
.child(ui::button(p, "rewind", "-10 s", false, |app: &mut App| {
let at = app.review.time - 10.0;
app.review.seek(at);
}))
.child(ui::button(p, "advance", "+10 s", false, |app: &mut App| {
let at = app.review.time + 10.0;
app.review.seek(at);
}))
.child(
text(format!(
"{} / {}",
format::clock(app.review.time),
format::clock(app.review.duration)
))
.key("time")
.font(type_::MONO_CAPTION)
.color(p.muted()),
)
.child(el().grow(1.0))
.child(
text(
app.review.export_note.clone().unwrap_or_else(|| {
format!("{} highlights", app.review.highlights.len())
}),
)
.key("export-note")
.font(body(11.5))
.color(p.muted()),
),
)
}
fn playing(app: &App) -> bool {
app.review.player.as_ref().is_some_and(Player::is_playing)
}
fn scrubber(app: &App, p: Paint) -> El {
let width = if app.review.scrubber_width > 0.0 {
app.review.scrubber_width
} else {
800.0
};
let duration = app.review.duration.max(0.001);
let progress = (app.review.time / duration).clamp(0.0, 1.0) as f32;
let knob = 14.0;
let mut bar = el()
.key("scrubber")
.role("slider")
.label("Playback position")
.range_value(app.review.time, 0.0, duration)
.w_full()
.h(26.0)
.on_layout(|app: &mut App, [_, _, w, _]| {
app.review.scrubber_width = w;
})
.on_step(|app: &mut App, steps, _| {
let at = app.review.time + steps as f64 * 5.0;
app.review.seek(at);
})
.on_drag(move |app: &mut App, d: &mut rune::Drag, tx| {
let w = app.review.scrubber_width.max(1.0);
let at = (d.x / w).clamp(0.0, 1.0) as f64 * app.review.duration;
app.review.seek(at);
tx.instant();
})
.child(
el().key("track")
.w_full()
.h(6.0)
.absolute(0.0, 10.0)
.radius(3.0)
.fill(p.t.control_off)
.a11y_hidden(),
)
.child(
el().key("played")
.w((width * progress).max(2.0))
.h(6.0)
.absolute(0.0, 10.0)
.radius(3.0)
.fill(p.accent)
.a11y_hidden(),
);
for (index, clip) in app.review.highlights.iter().enumerate() {
let x = (clip.start / duration).clamp(0.0, 1.0) as f32 * (width - 6.0);
let start = clip.start;
bar = bar.child(
el().key(format!("marker-{index}"))
.role("button")
.label(format!("{} at {}", clip.kind.label(), format::clock(start)))
.w(6.0)
.h(12.0)
.absolute(x, 2.0)
.radius(3.0)
.fill(match clip.kind {
highlight::Kind::Death => p.danger(),
highlight::Kind::Assist => p.muted(),
_ => p.success(),
})
.on_press(move |app: &mut App| app.review.seek(start))
.a11y_hidden(),
);
}
bar.child(
el().key("knob")
.size(knob, knob)
.absolute(progress * (width - knob), 6.0)
.radius(knob / 2.0)
.fill(p.t.knob)
.shadow(1.0, 3.0, p.t.knob_shadow)
.shadow(0.0, 0.5, p.t.edge)
.a11y_hidden(),
)
}
fn highlights(app: &App, p: Paint, game: &Timeline) -> El {
let mut list = col().key("highlight-rows").w_full().gap(4.0);
if app.review.highlights.is_empty() {
list = list.child(
text("No kills or deaths in this recording.")
.key("no-highlights")
.font(body(12.0))
.color(p.muted())
.padding(space::S2),
);
}
for (index, clip) in app.review.highlights.iter().enumerate() {
let start = clip.start;
let end = clip.end;
let video = game.video_path().map(|path| path.display().to_string());
let name = format!("{}-highlight-{}", game.recording_id, index);
let kind_ink = match clip.kind {
highlight::Kind::Death => p.danger(),
highlight::Kind::Assist => p.muted(),
highlight::Kind::MultiKill | highlight::Kind::TradeKill => p.accent,
highlight::Kind::Kill => p.success(),
};
let mut actions = row().key("actions").gap(6.0).center_y().child(ui::button(
p,
&format!("play-{index}"),
"Play",
false,
move |app: &mut App| {
app.review.seek(start);
if let Some(player) = &app.review.player {
player.play();
}
},
));
if video.is_some() {
actions = actions.child(ui::button(
p,
&format!("export-{index}"),
"Export",
false,
move |app: &mut App| {
let (tx, rx) = channel();
let Some(video) = video.clone() else { return };
let name = name.clone();
std::thread::spawn(move || {
let result =
crate::export::export_clip(&video, start, end, &name, true, "high");
let _ = tx.send(result);
});
app.review.export = Some(rx);
app.review.export_note = Some("Exporting clip…".into());
},
));
}
list = list.child(
row()
.key(format!("highlight-{index}"))
.w_full()
.h(44.0)
.px(space::S3)
.center_y()
.justify_between()
.radius(radius::MD)
.hover(p.t.hover)
.on_press({
let start = clip.start;
move |app: &mut App| app.review.seek(start)
})
.child(
col()
.key("labels")
.gap(1.0)
.child(
row()
.key("title-row")
.gap(6.0)
.center_y()
.child(ui::dot(kind_ink))
.child(
text(clip.title.clone())
.key("title")
.font(type_::LABEL)
.color(p.t.text),
)
.child(
text(format!(
"{} to {}",
format::clock(start),
format::clock(end)
))
.key("range")
.font(type_::MONO_CAPTION)
.color(p.muted()),
),
)
.child(
text(clip.subtitle.clone())
.key("subtitle")
.font(body(11.0))
.color(p.muted()),
),
)
.child(actions),
);
}
col()
.key("highlights-panel")
.w(360.0)
.h_full()
.gap(space::S2)
.child(
text("Highlights")
.key("header")
.font(type_::SECTION)
.color(p.muted()),
)
.child(
col()
.key("highlight-scroller")
.w_full()
.grow(1.0)
.min_h(0.0)
.scroll(rune::ScrollSpec {
stick_bottom: false,
})
.child(list),
)
}
fn events(_app: &App, p: Paint, game: &Timeline) -> El {
let interesting = |kind: &str| {
matches!(
kind,
"kill" | "death" | "objective" | "game_start" | "game_end" | "lp_change"
)
};
let mut list = col().key("event-rows").w_full().gap(1.0);
let mut shown = 0;
for event in game.events.iter().filter(|e| interesting(&e.event_type)) {
let at = event.time();
let label = match event.event_type.as_str() {
"kill" => "Kill",
"death" => "Death",
"objective" => "Objective",
"game_start" => "Game start",
"game_end" => "Game end",
"lp_change" => "LP change",
other => other,
};
let detail = if event.description.is_empty() {
label.to_string()
} else {
event.description.clone()
};
list = list.child(
row()
.key(format!("event-{shown}"))
.w_full()
.h(30.0)
.px(space::S2)
.center_y()
.gap(space::S2)
.radius(radius::SM)
.hover(p.t.hover)
.on_press(move |app: &mut App| app.review.seek(at))
.child(
text(format::clock(at))
.key("time")
.font(type_::MONO_CAPTION)
.color(p.muted()),
)
.child(
text(detail)
.key("detail")
.font(body(11.5))
.color(p.t.text)
.grow(1.0)
.shrink()
.truncate(),
),
);
shown += 1;
}
if shown == 0 {
list = list.child(
text("No timeline events.")
.key("no-events")
.font(body(12.0))
.color(p.muted()),
);
}
col()
.key("events-panel")
.grow(1.0)
.min_w(240.0)
.h_full()
.gap(space::S2)
.child(
text("Timeline")
.key("header")
.font(type_::SECTION)
.color(p.muted()),
)
.child(
col()
.key("event-scroller")
.w_full()
.grow(1.0)
.min_h(0.0)
.scroll(rune::ScrollSpec {
stick_bottom: false,
})
.child(list),
)
}