diff --git a/src-tauri/src/audible.rs b/src-tauri/src/audible.rs index 7fcff90..964a40d 100644 --- a/src-tauri/src/audible.rs +++ b/src-tauri/src/audible.rs @@ -363,6 +363,7 @@ pub fn set_alter_note(asin: &str, note: Option) -> Result<(), String> { /// Einzeldetails per Audible-API (Beschreibung u. a.) — on demand. #[derive(Debug, Clone, Serialize)] +#[derive(serde::Deserialize)] pub struct BookExtra { pub description: String, pub language: String, @@ -371,6 +372,21 @@ pub struct BookExtra { } pub fn fetch_details(asin: &str) -> Result { + // Cache im Buchordner (falls lokal vorhanden): einmalig holen, danach offline nutzbar + let cache = books_dir().join(asin).join("details.json"); + if let Ok(txt) = fs::read_to_string(&cache) { + if let Ok(x) = serde_json::from_str::(&txt) { + return Ok(x); + } + } + let fetched = fetch_details_online(asin)?; + if cache.parent().is_some_and(|p| p.is_dir()) { + let _ = fs::write(&cache, serde_json::to_vec(&fetched).unwrap_or_default()); + } + Ok(fetched) +} + +fn fetch_details_online(asin: &str) -> Result { let bin = audible_binary().ok_or_else(|| { "audible-cli nicht gefunden — pipx install audible-cli".to_string() })?; diff --git a/src/App.svelte b/src/App.svelte index 75405c5..7a83e10 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -464,10 +464,32 @@ // Beim Start: auth prüfen, Download-Events abonnieren, Abstammung + Abgleich. $effect(() => { playerSnapshot().then((s) => (player = s)).catch(() => {}) - const unlistenPlayer = onPlayerState((st) => { + const unlistenPlayer = onPlayerState((st) => { player = st sleepChapterWatch() }) + // Tastatursteuerung (SPEC UI): Leertaste Play/Pause, ←/→ = ±30 s, + // Entf schließt Overlays. Nicht aktiv in Eingabefeldern. + const onKey = (e: KeyboardEvent): void => { + const t = e.target as HTMLElement | null + const tag = t?.tagName?.toLowerCase() ?? '' + if (tag === 'input' || tag === 'select' || tag === 'textarea' || t?.isContentEditable) return + if (e.key === ' ' && player.loaded) { + e.preventDefault() + playerToggle() + } else if (e.key === 'ArrowLeft' && player.loaded) { + e.preventDefault() + playerSeek(-30) + } else if (e.key === 'ArrowRight' && player.loaded) { + e.preventDefault() + playerSeek(30) + } else if (e.key === 'Escape') { + if (detail) closeDetail() + else if (bmOpen) bmOpen = false + else if (settingsOpen) settingsOpen = false + } + } + window.addEventListener('keydown', onKey) checkAuth() const unlisten = onDownloadUpdate((it) => { downloads = { ...downloads, [it.asin]: it } @@ -489,6 +511,7 @@ return () => { clearPoll() clearInterval(syncId) + window.removeEventListener('keydown', onKey) unlisten.then((f) => f()) unlistenPlayer.then((f) => f()) }