app: delete a recording from its card's menu

The list could only open the review, so a clip that was not worth
keeping stayed on disk forever. The dots beside Review open a menu
drawn over this window, so it stays inside it, with room for more
actions later. Delete asks before the clip and its timeline leave
the disk and the row leaves the list.
This commit is contained in:
vhaudiquet committed 2026-11-21 19:01:41 +01:00
1 parent b1cde7e783
commit 6ca825990d
6 files changed
+290 -7

No files matched your search

+39 -3
View File
@@ -133,6 +133,11 @@ pub struct App {
/// The timeline the review is waiting for, once a row is opened.
pub review_rx: Option<Receiver<Option<Timeline>>>,
pub filter: Option<QueueCategory>,
/// The row the delete dialog is about, once its menu has asked to delete it.
pub confirm_delete: Option<String>,
/// The card whose actions menu is open, if any. The card's position, not its recording:
/// demo data repeats ids across rows, and a menu opens for one card alone.
pub menu_open: Option<usize>,
pub review: screens::review::Review,
pub portraits: Option<portraits::Portraits>,
/// The icons of the processes the audio sources name, decoded from their executables.
@@ -183,6 +188,8 @@ impl App {
games_next: 0,
review_rx: None,
filter: None,
confirm_delete: None,
menu_open: None,
review: screens::review::Review::default(),
portraits: None,
icons: None,
@@ -461,6 +468,23 @@ impl App {
self.games_next < self.games_paths.len()
}
/// Drop a recording out of the list once it has been deleted from disk, and drop a page
/// of rows already on its way: it may still hold the deleted file.
pub fn forget_game(&mut self, recording_id: &str) {
self.games.retain(|game| game.recording_id != recording_id);
if let Some(at) = self
.games_paths
.iter()
.position(|path| path.file_stem().and_then(|s| s.to_str()) == Some(recording_id))
{
self.games_paths.remove(at);
if at < self.games_next {
self.games_next -= 1;
}
}
self.games_rx = None;
}
/// The game the review screen is showing, if any.
pub fn reviewed(&self) -> Option<&Timeline> {
self.review.game.as_ref()
@@ -824,10 +848,12 @@ pub fn on_key(app: &mut App, event: &KeyEvent, _tx: &mut Tx) -> bool {
let command = event.mods.ctrl || event.mods.cmd;
match (&event.key, command) {
(Key::Text(t), false) if t == "1" => {
app.menu_open = None;
app.screen = Screen::History;
true
}
(Key::Text(t), false) if t == "2" => {
app.menu_open = None;
app.screen = Screen::Settings;
true
}
@@ -835,12 +861,17 @@ pub fn on_key(app: &mut App, event: &KeyEvent, _tx: &mut Tx) -> bool {
app.form.close_add();
true
}
(Key::Escape, _) if app.confirm_delete.is_some() => {
app.confirm_delete = None;
true
}
(Key::Escape, _) if app.screen == Screen::Review => {
screens::review::leave(app);
app.screen = Screen::History;
true
}
(Key::Escape, _) if app.screen == Screen::Settings => {
app.menu_open = None;
app.screen = Screen::History;
true
}
@@ -958,6 +989,7 @@ fn titlebar(p: Paint, app: &App) -> El {
"Settings",
false,
|app: &mut App| {
app.menu_open = None;
screens::review::leave(app);
app.screen = Screen::Settings;
},
@@ -1011,9 +1043,12 @@ fn notice(p: Paint, notice: &Notice) -> El {
pub fn view(app: &App, cx: &mut Cx<App>) -> El {
let p = Paint::new(app.dark, cx.env().scale);
// Menus and dialogs cover the whole window, title bar and status bar included: the
// history row menus, the add-application form and the delete confirmation.
let mut overlays = Vec::new();
let content = match app.screen {
Screen::Settings => screens::settings::view(app, p),
Screen::History => screens::history::view(app, p),
Screen::History => screens::history::view(app, p, &mut overlays),
Screen::Review => screens::review::view(app, p),
};
let mut main = col().key("main").grow(1.0).min_h(0.0).w_full().fill(p.t.bg);
@@ -1049,11 +1084,12 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
},
)),
};
// The add-application dialog covers the whole window, title bar included.
let mut overlays = Vec::new();
if app.screen == Screen::Settings && app.form.add_open {
screens::settings::add_dialog(app, p, &mut overlays);
}
if app.confirm_delete.is_some() {
screens::history::delete_dialog(app, p, &mut overlays);
}
rune_kit::root(content, overlays)
}
+48
View File
@@ -186,6 +186,8 @@ pub struct Summary {
pub recording_id: String,
pub start_time: DateTime<Utc>,
pub duration_secs: i64,
/// The video file the row names, kept so deleting a row does not re-read its timeline.
pub video_file: Option<String>,
champion: Option<String>,
summoner: Option<String>,
queue_label: String,
@@ -233,6 +235,7 @@ impl Timeline {
recording_id: self.recording_id.clone(),
start_time: self.start_time,
duration_secs: self.duration_secs,
video_file: self.video_file.clone(),
champion: self.champion(),
summoner: self.summoner(),
queue_label: self.queue_label(),
@@ -251,6 +254,35 @@ pub fn load(recording_id: &str) -> Option<Timeline> {
serde_json::from_str(&text).ok()
}
/// Remove a recording: its timeline JSON and its video file.
///
/// The video is found the way review finds it, so a clip renamed but keeping the timestamp
/// prefix goes too. A file that is already gone is fine: the list shows what was read
/// earlier, and a tidy-up elsewhere should not turn into an error here.
pub fn delete(recording_id: &str, video_file: Option<&str>) -> Result<(), String> {
delete_in(recording_id, video_file, &daemon::recordings_dir())
}
/// [`delete`] inside one recordings folder, so a test can point it at a temporary one.
fn delete_in(
recording_id: &str,
video_file: Option<&str>,
recordings: &Path,
) -> Result<(), String> {
let json = recordings
.join("timelines")
.join(format!("{recording_id}.json"));
if json.exists() {
std::fs::remove_file(&json)
.map_err(|e| format!("could not delete {}: {e}", json.display()))?;
}
if let Some(video) = video_file.and_then(|name| find_video_file(recordings, name)) {
std::fs::remove_file(&video)
.map_err(|e| format!("could not delete {}: {e}", video.display()))?;
}
Ok(())
}
impl Timeline {
fn end_stats(&self) -> Option<&Value> {
self.raw_end_game_stats.as_ref()
@@ -682,4 +714,20 @@ mod tests {
assert!(found.ends_with("2026-03-27_16-42-52_kai_sa.mp4"));
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn deleting_a_recording_removes_its_timeline_and_its_clip() {
let dir = std::env::temp_dir().join(format!("leaguerecorder-{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(dir.join("timelines")).unwrap();
std::fs::write(dir.join("timelines").join("game.json"), TIMELINE).unwrap();
std::fs::write(dir.join("2026-03-27_16-42-52_kai_sa.mp4"), b"x").unwrap();
delete_in("game", Some("2026-03-27_16-42-52_unknown.mp4"), &dir).unwrap();
assert!(!dir.join("timelines").join("game.json").exists());
assert!(!dir.join("2026-03-27_16-42-52_kai_sa.mp4").exists());
// What is already gone is not an error.
delete_in("game", Some("2026-03-27_16-42-52_unknown.mp4"), &dir).unwrap();
let _ = std::fs::remove_dir_all(dir);
}
}
+7
View File
@@ -42,3 +42,10 @@ pub static CHEVRON_RIGHT: Icon = Icon {
view: 16.0,
body: r#"<path d="M6 3.6 10.6 8 6 12.4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>"#,
};
/// Three vertical dots: the button that opens a card's menu of actions.
pub static DOTS: Icon = Icon {
name: "app-dots",
view: 16.0,
body: r#"<circle cx="8" cy="3.6" r="1.7" fill="currentColor"/><circle cx="8" cy="8" r="1.7" fill="currentColor"/><circle cx="8" cy="12.4" r="1.7" fill="currentColor"/>"#,
};
+3
View File
@@ -97,6 +97,9 @@ fn main() {
app.form.source_name = rune::TextEdit::new("Discord");
app.form.source_device = rune::TextEdit::new("Discord.exe");
}),
("delete", |app| {
app.confirm_delete = app.games.first().map(|game| game.recording_id.clone());
}),
("daemon", |app| {
app.screen = app::Screen::Settings;
app.settings_tab = app::SettingsTab::Advanced;
+142 -4
View File
@@ -8,10 +8,13 @@ use rune::{Color, El, col, el, row, text};
use crate::app::App;
use crate::format;
use crate::history::{Outcome, QueueCategory, Summary};
use crate::history::{self, Outcome, QueueCategory, Summary};
use crate::icons;
use crate::screens::review;
use crate::ui::{self, Paint, body, heading};
use rune_kit::{Kit, Menu, MenuItem, Placement};
const FILTERS: [Option<QueueCategory>; 6] = [
None,
Some(QueueCategory::RankedSolo),
@@ -33,7 +36,8 @@ fn outcome_color(p: Paint, outcome: Outcome) -> Color {
}
}
pub fn view(app: &App, p: Paint) -> El {
pub fn view(app: &App, p: Paint, layer: &mut Vec<El>) -> El {
let kit = rune_kit::Kit::neutral(app.dark);
let filtered: Vec<&Summary> = app
.games
.iter()
@@ -64,7 +68,7 @@ pub fn view(app: &App, p: Paint) -> El {
));
} else {
for (index, game) in filtered.iter().enumerate() {
list = list.child(game_card(app, p, game, index));
list = list.child(game_card(app, p, &kit, layer, game, index));
}
}
@@ -159,7 +163,14 @@ fn empty(p: Paint, title: &str, detail: &str) -> El {
)
}
fn game_card(app: &App, p: Paint, game: &Summary, index: usize) -> El {
fn game_card(
app: &App,
p: Paint,
k: &Kit,
layer: &mut Vec<El>,
game: &Summary,
index: usize,
) -> El {
let outcome = game.outcome();
let ink = outcome_color(p, outcome);
let id = game.recording_id.clone();
@@ -304,11 +315,18 @@ fn game_card(app: &App, p: Paint, game: &Summary, index: usize) -> El {
),
)
.child(stats_row)
.child(
row()
.key("actions")
.gap(space::S3)
.center_y()
.child(
text("Review →")
.key("open")
.font(type_::LABEL)
.color(p.accent),
)
.child(card_menu(app, k, layer, p, game, index)),
),
),
)
@@ -326,3 +344,123 @@ fn stat(p: Paint, value: &str, label: &str) -> El {
)
.child(text(label).key("label").font(body(10.5)).color(p.muted()))
}
/// The dots at the end of a card: they open the menu of actions a recording offers. The menu
/// is drawn over this window, so it stays inside it, and more actions can join `Delete` later.
/// The key is the card's position, so rows stay distinct even where ids repeat.
fn card_menu(
app: &App,
k: &Kit,
layer: &mut Vec<El>,
p: Paint,
game: &Summary,
index: usize,
) -> El {
let menu = Menu::new(format!("menu-{index}"))
.trigger(ui::menu_button(
p,
format!("menu-{index}"),
&icons::DOTS,
"Recording options",
move |app: &mut App| app.menu_open = Some(index),
))
.placement(Placement::BottomEnd)
.open(app.menu_open == Some(index))
.on_close(|app: &mut App| app.menu_open = None)
.item({
let id = game.recording_id.clone();
MenuItem::new("Delete")
.danger(true)
.on_select(move |app: &mut App| {
app.menu_open = None;
app.confirm_delete = Some(id.clone());
})
});
menu.build(k, layer)
}
/// The confirmation the menu's Delete opens: the row leaves the list and its files leave the
/// disk. `app::view` draws it over the whole window, title bar included.
pub fn delete_dialog(app: &App, p: Paint, layer: &mut Vec<El>) {
let panel = col()
.key("delete-dialog")
.role("dialog")
.label("Delete this recording")
.w(380.0)
.padding(space::S6)
.gap(space::S3)
.radius(radius::LG)
.fill(p.t.card)
.border(p.hair, p.t.card_border)
.shadow(4.0, 12.0, p.t.shadow)
.shadow(24.0, 48.0, p.t.shadow_soft)
.modal(true, |app: &mut App| app.confirm_delete = None)
.child(
text("Are you sure you want to delete this entry?")
.key("delete-question")
.font(heading(15.0))
.color(p.t.text),
)
.child(
text("The recording and its timeline are removed from disk.")
.key("delete-note")
.font(body(12.0))
.color(p.muted()),
)
.child(
row()
.key("delete-actions")
.w_full()
.gap(space::S2)
.justify_end()
.child(ui::button(p, "delete-no", "No", false, |app: &mut App| {
app.confirm_delete = None;
}))
.child(ui::button_danger(
p,
"delete-yes",
"Yes",
|app: &mut App| {
delete_confirmed(app);
},
)),
);
layer.push(
el().key("delete-scrim")
.absolute(0.0, 0.0)
.w_full()
.h_full()
.fill(Color::BLACK.alpha(if app.dark { 0.55 } else { 0.28 }))
.a11y_hidden(),
);
layer.push(
el().key("delete-layer")
.absolute(0.0, 0.0)
.w_full()
.h_full()
.padding(16.0)
.center()
.child(panel),
);
}
/// Yes on the dialog: the files go, the row goes, the dialog closes.
fn delete_confirmed(app: &mut App) {
let Some(id) = app.confirm_delete.take() else {
return;
};
// A review left open keeps the clip's file in use, and the delete would fail on it.
if app.reviewed().is_some_and(|game| game.recording_id == id) {
review::leave(app);
}
let Some(summary) = app.games.iter().find(|g| g.recording_id == id).cloned() else {
return;
};
if let Err(e) = history::delete(&id, summary.video_file.as_deref()) {
app.notify_error(e);
return;
}
app.forget_game(&id);
app.notify("Recording deleted");
}
+51
View File
@@ -754,3 +754,54 @@ fn place(thumb: &rune::Live<[f32; 4]>, [x, y, w, h]: [f32; 4], at: rune::ScrollP
let progress = (at.offset[1] / at.max[1]).clamp(0.0, 1.0);
thumb.set([x + w - 12.0, y + progress * (h - height), 10.0, height]);
}
/// A small square button holding an icon: the trigger a menu opens from. Its handler says what
/// opening means; the menu itself is drawn in the window, so it can never leave it.
pub fn menu_button(
p: Paint,
key: impl Into<String>,
icon: &'static rune::Icon,
label: &str,
on_press: impl Fn(&mut App) + Send + Sync + 'static,
) -> El {
el().key(key.into())
.role("button")
.label(label)
.focusable(true)
.size(24.0, 24.0)
.center()
.radius(radius::MD)
.hover(p.t.hover)
.press(p.t.press)
.on_press(on_press)
.child(rune::icon(icon, 18.0).color(p.muted()).a11y_hidden())
}
/// A quiet destructive button: danger ink for a confirm whose answer cannot be undone.
pub fn button_danger(
p: Paint,
key: &str,
label: &str,
on_press: impl Fn(&mut App) + Send + Sync + 'static,
) -> El {
el().key(key)
.role("button")
.label(label)
.focusable(true)
.h(28.0)
.px(14.0)
.center()
.radius(radius::MD)
.fill(p.danger.alpha(0.14))
.border(p.hair, p.danger.alpha(0.32))
.hover(p.danger.alpha(0.22))
.press(p.danger.alpha(0.3))
.on_press(on_press)
.child(
text(label)
.key("label")
.font(type_::LABEL)
.color(p.danger)
.a11y_hidden(),
)
}