app: open the clips grid
The clips screen lists the clips folder: one card per mp4 the user exported, newest first, with the clip's 16:9 stage, the champion it stars when its recording is in the loaded history, share, and a menu whose Delete removes the file. The folder read runs when the screen opens, and again when an export finishes on it. Computed highlights were the first plan for the grid, but a real history parses hundreds of timelines and some run to tens of MB, so the grid now reads only what the user actually exported.
This commit is contained in:
1 parent
fac1ec00da
commit
3f82f87a81
9 files changed
+577
-9
No files matched your search
+100
-6
@@ -7,7 +7,7 @@ use std::time::Duration;
|
||||
use rune::tok::type_;
|
||||
use rune::{Cx, El, Key, KeyEvent, Tx, col, el, row, text};
|
||||
|
||||
use crate::export;
|
||||
use crate::export::{self, Clip};
|
||||
use crate::history::{self, QueueCategory, Summary, Timeline};
|
||||
use crate::ipc::{self, Daemon};
|
||||
use crate::os;
|
||||
@@ -21,6 +21,7 @@ use crate::ui::{self, Paint, body, heading};
|
||||
pub enum Screen {
|
||||
Settings,
|
||||
History,
|
||||
Clips,
|
||||
Review,
|
||||
}
|
||||
|
||||
@@ -138,6 +139,13 @@ pub struct App {
|
||||
/// 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>,
|
||||
/// Every clip the user exported, newest first. Read when the screen opens.
|
||||
pub clips: Vec<Clip>,
|
||||
pub clips_loaded: bool,
|
||||
/// The clip card whose actions menu is open, if any: its position, like the history's.
|
||||
pub clips_menu_open: Option<usize>,
|
||||
/// The clip the delete dialog is about, by its `id@start` key.
|
||||
pub confirm_clip_delete: Option<String>,
|
||||
pub review: screens::review::Review,
|
||||
pub portraits: Option<portraits::Portraits>,
|
||||
/// The icons of the processes the audio sources name, decoded from their executables.
|
||||
@@ -148,6 +156,7 @@ pub struct App {
|
||||
/// When the process table was last read, in the clock `poll` gets.
|
||||
pub processes_at: f64,
|
||||
pub scroll: ui::ScrollBar,
|
||||
pub clips_scroll: ui::ScrollBar,
|
||||
pub highlights_scroll: ui::ScrollBar,
|
||||
pub events_scroll: ui::ScrollBar,
|
||||
pub notice: Option<Notice>,
|
||||
@@ -190,6 +199,10 @@ impl App {
|
||||
filter: None,
|
||||
confirm_delete: None,
|
||||
menu_open: None,
|
||||
clips: Vec::new(),
|
||||
clips_loaded: false,
|
||||
clips_menu_open: None,
|
||||
confirm_clip_delete: None,
|
||||
review: screens::review::Review::default(),
|
||||
portraits: None,
|
||||
icons: None,
|
||||
@@ -197,6 +210,7 @@ impl App {
|
||||
processes_rx: None,
|
||||
processes_at: 0.0,
|
||||
scroll: ui::ScrollBar::new(),
|
||||
clips_scroll: ui::ScrollBar::new(),
|
||||
highlights_scroll: ui::ScrollBar::new(),
|
||||
events_scroll: ui::ScrollBar::new(),
|
||||
notice: None,
|
||||
@@ -231,6 +245,21 @@ impl App {
|
||||
}
|
||||
|
||||
/// State for `--scene` snapshots: sample history, a connected daemon, default settings.
|
||||
/// A demo clip like one the export writes: a name, an export time, a size.
|
||||
pub fn demo_clip(name: String, hours_ago: i64, bytes: u64) -> Clip {
|
||||
Clip {
|
||||
name,
|
||||
path: PathBuf::new(),
|
||||
exported: Some(
|
||||
std::time::SystemTime::now()
|
||||
- chrono::Duration::hours(hours_ago)
|
||||
.to_std()
|
||||
.unwrap_or_default(),
|
||||
),
|
||||
bytes,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn demo(&mut self) {
|
||||
self.connected = true;
|
||||
self.status = Status {
|
||||
@@ -239,11 +268,17 @@ impl App {
|
||||
current_game_id: None,
|
||||
client_connected: true,
|
||||
};
|
||||
self.games = history::sample()
|
||||
.iter()
|
||||
.map(|game| game.summary())
|
||||
.collect();
|
||||
let sample = history::sample();
|
||||
self.games = sample.iter().map(|game| game.summary()).collect();
|
||||
self.games_loaded = true;
|
||||
let id = |game: &Timeline| game.recording_id.clone();
|
||||
self.clips = vec![
|
||||
Self::demo_clip(format!("{}-clip", id(&sample[0])), 3, 22_000_000),
|
||||
Self::demo_clip("baron-steal".into(), 5, 9_400_000),
|
||||
Self::demo_clip(format!("{}-clip", id(&sample[1])), 26, 15_800_000),
|
||||
Self::demo_clip("pentakill".into(), 74, 31_200_000),
|
||||
];
|
||||
self.clips_loaded = true;
|
||||
self.devices = AudioDevices {
|
||||
input_devices: vec![AudioDevice {
|
||||
id: "mic-1".into(),
|
||||
@@ -439,6 +474,12 @@ impl App {
|
||||
self.games_rx = Some(rx);
|
||||
}
|
||||
|
||||
/// Read the clips folder into the grid. A directory read, quick enough for the UI thread.
|
||||
pub fn refresh_clips(&mut self) {
|
||||
self.clips = export::list_clips();
|
||||
self.clips_loaded = true;
|
||||
}
|
||||
|
||||
/// Read the next page of rows, if the list has one and none is already on its way.
|
||||
///
|
||||
/// Called from `poll` while the history list is scrolled near its end, and while the
|
||||
@@ -713,6 +754,12 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
// The clips grid reads the clips folder, so it loads once it is on screen, not at launch.
|
||||
if self.screen == Screen::Clips && !self.clips_loaded {
|
||||
self.refresh_clips();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// Taken out of the field so the notice helpers below can borrow the app.
|
||||
if let Some(rx) = self.ffmpeg_rx.take() {
|
||||
let mut finished = false;
|
||||
@@ -849,14 +896,22 @@ pub fn on_key(app: &mut App, event: &KeyEvent, _tx: &mut Tx) -> bool {
|
||||
match (&event.key, command) {
|
||||
(Key::Text(t), false) if t == "1" => {
|
||||
app.menu_open = None;
|
||||
app.clips_menu_open = None;
|
||||
app.screen = Screen::History;
|
||||
true
|
||||
}
|
||||
(Key::Text(t), false) if t == "2" => {
|
||||
app.menu_open = None;
|
||||
app.clips_menu_open = None;
|
||||
app.screen = Screen::Settings;
|
||||
true
|
||||
}
|
||||
(Key::Text(t), false) if t == "3" => {
|
||||
app.menu_open = None;
|
||||
app.clips_menu_open = None;
|
||||
app.screen = Screen::Clips;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.form.add_open => {
|
||||
app.form.close_add();
|
||||
true
|
||||
@@ -865,6 +920,19 @@ pub fn on_key(app: &mut App, event: &KeyEvent, _tx: &mut Tx) -> bool {
|
||||
app.confirm_delete = None;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.confirm_clip_delete.is_some() => {
|
||||
app.confirm_clip_delete = None;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.clips_menu_open.is_some() => {
|
||||
app.clips_menu_open = None;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.screen == Screen::Clips => {
|
||||
app.menu_open = None;
|
||||
app.screen = Screen::History;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.screen == Screen::Review => {
|
||||
screens::review::leave(app);
|
||||
app.screen = Screen::History;
|
||||
@@ -948,7 +1016,10 @@ fn titlebar(p: Paint, app: &App) -> El {
|
||||
// Leaving a screen is on the left, where a window's back arrow lives; the app's own
|
||||
// actions stay on the right.
|
||||
let mut leading = row().key("leading").gap(8.0).center_y();
|
||||
if matches!(app.screen, Screen::Settings | Screen::Review) {
|
||||
if matches!(
|
||||
app.screen,
|
||||
Screen::Settings | Screen::Clips | Screen::Review
|
||||
) {
|
||||
leading = leading.child(ui::button(
|
||||
p,
|
||||
"back",
|
||||
@@ -972,6 +1043,20 @@ fn titlebar(p: Paint, app: &App) -> 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 {
|
||||
if app.screen != Screen::Clips {
|
||||
actions = actions.child(ui::button(
|
||||
p,
|
||||
"open-clips",
|
||||
"Clips",
|
||||
false,
|
||||
|app: &mut App| {
|
||||
app.menu_open = None;
|
||||
app.clips_menu_open = None;
|
||||
screens::review::leave(app);
|
||||
app.screen = Screen::Clips;
|
||||
},
|
||||
));
|
||||
}
|
||||
actions = actions
|
||||
.child(ui::button(
|
||||
p,
|
||||
@@ -981,6 +1066,10 @@ fn titlebar(p: Paint, app: &App) -> El {
|
||||
|app: &mut App| {
|
||||
app.refresh_games();
|
||||
app.daemon.get_status();
|
||||
if app.screen == Screen::Clips {
|
||||
app.clips_loaded = false;
|
||||
app.refresh_clips();
|
||||
}
|
||||
},
|
||||
))
|
||||
.child(ui::button(
|
||||
@@ -1049,6 +1138,7 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
|
||||
let content = match app.screen {
|
||||
Screen::Settings => screens::settings::view(app, p),
|
||||
Screen::History => screens::history::view(app, p, &mut overlays),
|
||||
Screen::Clips => screens::clips::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);
|
||||
@@ -1074,6 +1164,7 @@ 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")),
|
||||
_ => window.child(app.scroll.thumb(
|
||||
p,
|
||||
"scroll-thumb",
|
||||
@@ -1090,6 +1181,9 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
|
||||
if app.confirm_delete.is_some() {
|
||||
screens::history::delete_dialog(app, p, &mut overlays);
|
||||
}
|
||||
if app.confirm_clip_delete.is_some() {
|
||||
screens::clips::delete_dialog(app, p, &mut overlays);
|
||||
}
|
||||
rune_kit::root(content, overlays)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user