Tastatursteuerung (SPACE Play/Pause, ←/→ ±30 s, ESC schließt Overlays) + Klappentext-Cache in books/<asin>/details.json
This commit is contained in:
@ -363,6 +363,7 @@ pub fn set_alter_note(asin: &str, note: Option<String>) -> 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<BookExtra, String> {
|
||||
// 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::<BookExtra>(&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<BookExtra, String> {
|
||||
let bin = audible_binary().ok_or_else(|| {
|
||||
"audible-cli nicht gefunden — pipx install audible-cli".to_string()
|
||||
})?;
|
||||
|
||||
@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user