download marking in place

This commit is contained in:
2026-02-16 16:08:53 -06:00
parent 6fe294f19b
commit 26a79ecb7e
2 changed files with 134 additions and 14 deletions

View File

@@ -7,6 +7,7 @@ use std::{
path::PathBuf,
process::{Child, Command, Stdio},
time::{Duration, Instant},
collections::HashSet,
thread,
};
@@ -182,6 +183,8 @@ struct App {
downloads: Option<downloads::DownloadManager>,
downloads_focus: bool,
downloads_selected: usize,
downloaded_ids: HashSet<String>,
last_download_message: Option<String>,
autoplay: bool,
autoplay_view_depth: usize,
@@ -256,6 +259,8 @@ impl Default for App {
downloads: None,
downloads_focus: false,
downloads_selected: 0,
downloaded_ids: downloads::scan_downloaded_ids().unwrap_or_default(),
last_download_message: None,
}
}
}
@@ -336,6 +341,21 @@ fn run_app(terminal: &mut Terminal<CrosstermBackend<io::Stdout>>) -> io::Result<
app.mpv_state = MpvState::default();
}
// Refresh local-download index when downloads complete
if let Some(dm) = &app.downloads {
if let Ok(st) = dm.state.lock() {
let msg = st.last_message.clone();
if msg != app.last_download_message {
app.last_download_message = msg.clone();
if matches!(msg.as_deref(), Some("download complete")) {
app.downloaded_ids = downloads::scan_downloaded_ids().unwrap_or_default();
}
}
}
}
// Option A: always tick autoplay by polling eof-reached (window stays open)
autoplay_tick(&mut app);
@@ -2699,9 +2719,10 @@ fn is_music_item(it: &core::jellyfin::JfItem) -> bool {
matches!(it.item_type.as_deref(), Some("Audio" | "MusicAlbum" | "MusicArtist"))
}
// Placeholder for later
fn is_downloaded(_it: &core::jellyfin::JfItem) -> bool {
false
fn is_downloaded(app: &App, it: &core::jellyfin::JfItem) -> bool {
// Basic: only exact item-id matches.
// (No container inference for Series/Season/Album right now.)
app.downloaded_ids.contains(&it.id)
}
fn is_played(it: &core::jellyfin::JfItem) -> bool {
@@ -2777,15 +2798,30 @@ fn is_in_progress_fast(it: &core::jellyfin::JfItem) -> bool {
}
}
fn emoji_prefix_for(app: &App, it: &core::jellyfin::JfItem) -> String {
// Keep your existing behavior: no emojis for music items (optional).
// If you DO want 💾 for music too, remove this early return.
if is_music_item(it) {
return String::new();
}
let downloaded = is_downloaded(app, it);
let played = is_played(it);
let inprog = is_in_progress_fast(it);
let mut s = String::new();
fn emoji_prefix_for(_app: &App, it: &core::jellyfin::JfItem) -> &'static str {
if is_music_item(it) { return ""; }
if downloaded {
s.push_str("💾 ");
}
if is_played(it) { return ""; }
if is_in_progress_fast(it) { return "🟠 "; }
""
if played {
s.push_str(" ");
} else if inprog {
s.push_str("🟠 ");
}
s
}
/*