T-013: Download-Manager — Queue mit Bytes-Fortschritt-Events, Abbruch, Wiederaufnahme per Manifest nach Neustart, UI: Laden/Abbrechen auf Cards

This commit is contained in:
2026-11-06 19:49:16 +01:00
parent eace05f180
commit eb97f183e7
8 changed files with 673 additions and 34 deletions

View File

@ -1,6 +1,6 @@
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::process::Command;
use serde::{Deserialize, Serialize};
@ -66,26 +66,26 @@ impl CliAudibleClient {
pub fn with_auth_dir(dir: PathBuf) -> Self {
Self { auth_dir: dir }
}
}
/// Findet die audible-CLI: bevorzugt `~/.local/bin/audible` (pipx),
/// sonst `$PATH`. Übergabe als Argumentliste, nie über eine Shell.
fn audible_binary(&self) -> Result<PathBuf, String> {
if let Some(home) = home_dir() {
let p = home.join(".local/bin/audible");
if p.is_file() {
return Ok(p);
}
/// Findet die audible-CLI: bevorzugt `~/.local/bin/audible` (pipx),
/// sonst `$PATH`. Übergabe als Argumentliste, nie über eine Shell.
pub fn audible_binary() -> Option<PathBuf> {
if let Some(home) = home_dir() {
let p = home.join(".local/bin/audible");
if p.is_file() {
return Some(p);
}
if let Ok(path) = env::var("PATH") {
for dir in env::split_paths(&path) {
let p = dir.join("audible");
if p.is_file() {
return Ok(p);
}
}
}
Err("audible-cli nicht gefunden — Installation: pipx install audible-cli".to_string())
}
if let Ok(path) = env::var("PATH") {
for dir in env::split_paths(&path) {
let p = dir.join("audible");
if p.is_file() {
return Some(p);
}
}
}
None
}
impl Default for CliAudibleClient {
@ -94,7 +94,7 @@ impl Default for CliAudibleClient {
}
}
fn home_dir() -> Option<PathBuf> {
pub(crate) fn home_dir() -> Option<PathBuf> {
env::var("HOME").ok().map(PathBuf::from)
}
@ -148,7 +148,9 @@ impl AudibleClient for CliAudibleClient {
/// Startet `manage auth-file decrypt` im Terminal (interaktiv, Passwort
/// bleibt im Terminal). Bekannter Profilname wird mitgeliefert.
fn start_decrypt(&self) -> Result<bool, String> {
let bin = self.audible_binary()?;
let bin = audible_binary().ok_or_else(|| {
"audible-cli nicht gefunden — Installation: pipx install audible-cli".to_string()
})?;
let Some((term, needs_e, hold)) = find_terminal() else {
return Err("kein unterstütztes Terminal gefunden — bitte in deiner Shell: audible manage auth-file decrypt".to_string());
};
@ -171,7 +173,9 @@ impl AudibleClient for CliAudibleClient {
}
fn start_login(&self) -> Result<bool, String> {
let bin = self.audible_binary()?;
let bin = audible_binary().ok_or_else(|| {
"audible-cli nicht gefunden — Installation: pipx install audible-cli".to_string()
})?;
let Some((term, needs_e, hold)) = find_terminal() else {
return Err("kein unterstütztes Terminal gefunden — bitte in deiner Shell ausführen: audible manage auth-file add".to_string());
};
@ -194,7 +198,9 @@ impl AudibleClient for CliAudibleClient {
}
fn library(&self) -> Result<Vec<Book>, String> {
let bin = self.audible_binary()?;
let bin = audible_binary().ok_or_else(|| {
"audible-cli nicht gefunden — Installation: pipx install audible-cli".to_string()
})?;
let out = env::temp_dir().join(format!("hoerwerk-library-{}.json", std::process::id()));
let exported = Command::new(&bin)
.args(["library", "export", "-f", "json", "-o"])
@ -229,7 +235,7 @@ pub fn parse_library(content: &str) -> Result<Vec<Book>, String> {
/// Taugt stderr von audible-cli: Warnungen und Passwort-Prompts raus,
/// echte Fehlertexte bleiben.
fn reduce_noise(s: &str) -> String {
pub(crate) fn reduce_noise(s: &str) -> String {
let lower = |l: &str| l.to_lowercase();
let kept: Vec<&str> = s
.lines()