diff --git a/ROADMAP.md b/ROADMAP.md index be1df62..599c499 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -21,7 +21,7 @@ Abnahme M0: Ein gekauftes Buch läuft lokal mit Kapiteln. | ID | Titel | Status | |----|-------|--------| | T-010 | Tauri-Projekt aufsetzen (Rust-Backend, Svelte-Frontend) | fertig | -| T-011 | Login-Flow in der App (Auth-Datei sicher unter ~/.config speichern) | offen | +| T-011 | Login-Flow in der App (Auth-Datei sicher unter ~/.config speichern) | fertig | | T-012 | Bibliotheksansicht mit Covern, Suche, Sortierung | offen | | T-013 | Download-Manager (Queue, Fortschritt, Abbruch) | offen | | T-014 | Entschlüsseln nach dem Download, Ablage als .m4b mit Kapiteln und Cover | offen | diff --git a/index.html b/index.html index 78f8867..45c556c 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - hw-vite + Hörwerk
diff --git a/src-tauri/src/audible.rs b/src-tauri/src/audible.rs new file mode 100644 index 0000000..c3fe0e1 --- /dev/null +++ b/src-tauri/src/audible.rs @@ -0,0 +1,292 @@ +use std::env; +use std::fs; +use std::path::{Path, PathBuf}; +use std::process::Command; + +use serde::{Deserialize, Serialize}; + +/// Status der Anmeldung beim Audible-Konto. +#[derive(Debug, Serialize)] +pub struct AuthStatus { + pub logged_in: bool, + pub profiles: Vec, + pub auth_dir: String, +} + +/// Ein Buch aus der Audible-Bibliothek (Export-JSON, Felder nach Spike). +#[derive(Debug, Deserialize, Clone, Serialize)] +pub struct Book { + pub asin: String, + pub title: String, + #[serde(default)] + pub authors: String, + #[serde(default)] + pub narrators: String, + #[serde(default)] + pub runtime_length_min: i64, + #[serde(default)] + pub cover_url: String, + #[serde(default)] + pub percent_complete: f64, + #[serde(default)] + pub is_finished: bool, +} + +/// Zugriffsschicht auf Audible — hinter diesem Trait kapseln, damit +/// `audible-cli` später austauschbar bleibt (spec E-02). +pub trait AudibleClient: Send + Sync { + fn auth_status(&self) -> Result; + /// Startet die interaktive Anmeldung (audible quickstart) im Terminal. + /// true = Terminal gestartet, der Nutzer meldet sich dort an; dann + /// `auth_status` erneut prüfen. + fn start_login(&self) -> Result; + fn library(&self) -> Result, String>; +} + +pub struct CliAudibleClient { + auth_dir: PathBuf, +} + +impl CliAudibleClient { + /// Standard: `~/.audible` (audible-cli-Standardpfad), per + /// `HOERWERK_AUDIBLE_DIR` überschreibbar (z. B. für KT-010). + pub fn new() -> Self { + Self::with_auth_dir(default_auth_dir()) + } + + 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 { + if let Some(home) = home_dir() { + let p = home.join(".local/bin/audible"); + if p.is_file() { + return Ok(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()) + } +} + +impl Default for CliAudibleClient { + fn default() -> Self { + Self::new() + } +} + +fn home_dir() -> Option { + env::var("HOME").ok().map(PathBuf::from) +} + +fn default_auth_dir() -> PathBuf { + home_dir() + .map(|h| h.join(".audible")) + .unwrap_or_else(|| PathBuf::from(".")) +} + +impl AudibleClient for CliAudibleClient { + fn auth_status(&self) -> Result { + let mut profiles = Vec::new(); + let entries = fs::read_dir(&self.auth_dir).map_err(|e| { + format!( + "Auth-Verzeichnis nicht lesbar ({}): {e}", + self.auth_dir.display() + ) + })?; + for entry in entries.flatten() { + let p = entry.path(); + let is_json = p + .extension() + .and_then(|e| e.to_str()) + .map(|e| e.eq_ignore_ascii_case("json")) + .unwrap_or(false); + if is_json { + if let Some(stem) = p.file_stem().and_then(|s| s.to_str()) { + profiles.push(stem.to_string()); + } + } + } + Ok(AuthStatus { + logged_in: !profiles.is_empty(), + profiles, + auth_dir: self.auth_dir.display().to_string(), + }) + } + + fn start_login(&self) -> Result { + let bin = self.audible_binary()?; + let Some((term, needs_e)) = find_terminal() else { + return Err("kein unterstütztes Terminal gefunden — bitte in deiner Shell ausführen: audible quickstart".to_string()); + }; + // Argumentliste, keine Shell und kein zusammengesetzter String (spec). + let mut cmd = Command::new(term); + if needs_e { + cmd.arg("-e"); + } + cmd.arg(&bin).arg("quickstart"); + cmd.spawn() + .map_err(|e| format!("Terminal konnte nicht gestartet werden: {e}"))?; + Ok(true) + } + + fn library(&self) -> Result, String> { + let bin = self.audible_binary()?; + let out = env::temp_dir().join(format!("hoerwerk-library-{}.json", std::process::id())); + let exported = Command::new(&bin) + .args(["library", "export", "-f", "json", "-o"]) + .arg(&out) + .output() + .map_err(|e| format!("audible library export fehlgeschlagen: {e}"))?; + let stderr = String::from_utf8_lossy(&exported.stderr); + if !exported.status.success() { + let _ = fs::remove_file(&out); + return Err(reduce_noise(&stderr)); + } + let content = match fs::read_to_string(&out) { + Ok(c) => c, + Err(e) => { + return Err(format!("Export-Datei nicht lesbar: {e}")); + } + }; + let _ = fs::remove_file(&out); + parse_library(&content) + } +} + +/// Wandelt den Bibliotheks-Export in `Book`s (separat getestet). +pub fn parse_library(content: &str) -> Result, String> { + serde_json::from_str(content).map_err(|e| format!("Bibliothek-JSON nicht parsebar: {e}")) +} + +/// Taugt stderr von audible-cli: Warnungen und Passwort-Prompts raus, +/// echte Fehlertexte bleiben. +fn reduce_noise(s: &str) -> String { + let lower = |l: &str| l.to_lowercase(); + let kept: Vec<&str> = s + .lines() + .filter(|l| { + let l = lower(l); + !(l.contains("userwarning") + || l.contains("warning: password input") + || l.contains("please enter") + || l.contains("getpass") + || l.contains("passwd =") + || l.contains("press enter")) + }) + .collect(); + let joined = kept.join("\n"); + if joined.trim().is_empty() { + "audible-cli meldete keinen Fehler, aber der Befehl schlug fehl.".to_string() + } else { + joined + } +} + +fn find_terminal() -> Option<(&'static str, bool)> { + // (Programm, heißt „-e Programm Args“) + const CANDIDATES: [(&str, bool); 5] = [ + ("konsole", true), + ("kitty", true), + ("alacritty", true), + ("foot", false), + ("xterm", true), + ]; + for (name, needs_e) in CANDIDATES { + if is_in_path(name) { + return Some((name, needs_e)); + } + } + None +} + +fn is_in_path(name: &str) -> bool { + if let Ok(path) = env::var("PATH") { + for dir in env::split_paths(&path) { + if dir.join(name).is_file() { + return true; + } + } + } + false +} + +#[cfg(test)] +mod tests { + use super::*; + + fn temp_dir() -> PathBuf { + let d = env::temp_dir().join(format!( + "hoerwerk-test-{}-{}", + std::process::id(), + chrono_len() + )); + fs::create_dir_all(&d).unwrap(); + d + } + + fn chrono_len() -> String { + // kleiner uniq-Suffix ohne chrono: nanos seit Start via std + use std::time::{SystemTime, UNIX_EPOCH}; + let n = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); + format!("{}", n.subsec_nanos()) + } + + #[test] + fn logged_in_wenn_auth_datei_vorhanden() { + let d = temp_dir(); + fs::write(d.join("testprof.json"), "{}").unwrap(); + let c = CliAudibleClient::with_auth_dir(d.clone()); + let s = c.auth_status().unwrap(); + assert!(s.logged_in); + assert_eq!(s.profiles, vec!["testprof".to_string()]); + fs::remove_dir_all(d).unwrap(); + } + + #[test] + fn ausgeloggt_wenn_nichts_da() { + let d = temp_dir(); + let c = CliAudibleClient::with_auth_dir(d); + let s = c.auth_status().unwrap(); + assert!(!s.logged_in); + } + + #[test] + fn json_nur_fuer_auth_dateien() { + let d = temp_dir(); + fs::write(d.join("a.json"), "{}").unwrap(); + fs::write(d.join("config.toml"), "").unwrap(); + fs::write(d.join("txt.txt"), "{}").unwrap(); + let c = CliAudibleClient::with_auth_dir(d); + let s = c.auth_status().unwrap(); + assert_eq!(s.profiles.len(), 1); + assert!(s.profiles[0] == "a"); + } + + #[test] + fn parse_library_nimmt_pfelder() { + let json = r#"[{"asin":"B08L4WJMDM","title":"Elfe 2"}]"#; + let books = parse_library(json).unwrap(); + assert_eq!(books.len(), 1); + assert_eq!(books[0].asin, "B08L4WJMDM"); + assert_eq!(books[0].runtime_length_min, 0); + assert!(!books[0].is_finished); + assert!(parse_library("kaputt").is_err()); + } + + #[test] + fn noise_wird_gefiltert() { + let s = "UserWarning: legace\nerror: 401\nPlease enter the auth-file password"; + assert_eq!(reduce_noise(s), "error: 401"); + } +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 4a277ef..c23941f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,14 +1,28 @@ -// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ +mod audible; + +use audible::{AudibleClient, AuthStatus, Book, CliAudibleClient}; + #[tauri::command] -fn greet(name: &str) -> String { - format!("Hello, {}! You've been greeted from Rust!", name) +fn auth_status(client: tauri::State) -> Result { + client.auth_status() +} + +#[tauri::command] +fn start_login(client: tauri::State) -> Result { + client.start_login() +} + +#[tauri::command] +fn get_library(client: tauri::State) -> Result, String> { + client.library() } #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_opener::init()) - .invoke_handler(tauri::generate_handler![greet]) + .manage(CliAudibleClient::new()) + .invoke_handler(tauri::generate_handler![auth_status, start_login, get_library]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src/App.svelte b/src/App.svelte index dafc575..bb878b0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,89 +1,126 @@ - -
-
- - Svelte logo - Vite logo -
-
-

Get started

-

Edit src/App.svelte and save to test HMR

-
- -
+{#if view === 'loading'} +
+

Hörwerk

+

Prüfe Anmeldung…

+
+{:else if view === 'login'} +
+

Hörwerk

+

+ Melden dich mit deinem Audible-Konto an. Die Anmeldung läuft über + audible-cli im Terminal. Nur dein eigenes, gekauftes Konto — + keine Daten gehen über die App hinaus. +

+ + + {#if info}

{info}

{/if} + {#if error}

{error}

{/if} +
+{:else if view === 'library'} +
+
+

Hörwerk

+ {books.length} Titel + +
-
- -
-
- -

Documentation

-

Your questions, answered

- -
-
- -

Connect with us

-

Join the Vite community

- -
-
- -
-
+ {#if error} +

{error}

+ {:else} + + + + + + {#each books as b (b.asin)} + + + + + + + {/each} + +
TitelAutorSprecherMin
{b.title}{b.authors}{b.narrators}{b.runtime_length_min}
+

Bibliotheksansicht minimal (T-012: Cover, Suche, Sortierung, Status).

+ {/if} +
+{/if} diff --git a/src/app.css b/src/app.css index 527d4fb..8bccccb 100644 --- a/src/app.css +++ b/src/app.css @@ -1,296 +1,113 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); - --shadow: - rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; - - --sans: system-ui, 'Segoe UI', Roboto, sans-serif; - --heading: system-ui, 'Segoe UI', Roboto, sans-serif; - --mono: ui-monospace, Consolas, monospace; - - font: 18px/145% var(--sans); - letter-spacing: 0.18px; - color-scheme: light dark; - color: var(--text); - background: var(--bg); - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - - @media (max-width: 1024px) { - font-size: 16px; - } -} - -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } - - #social .button-icon { - filter: invert(1) brightness(2); - } + color-scheme: dark; + --bg: #16181d; + --bg-card: #1e2127; + --fg: #e8e6e3; + --fg-muted: #9aa0a8; + --accent: #c2762f; + --error: #d4645c; + --border: #2a2e36; } body { margin: 0; + background: var(--bg); + color: var(--fg); + font-family: system-ui, sans-serif; + font-size: 14px; } -h1, -h2 { - font-family: var(--heading); - font-weight: 500; - color: var(--text-h); +main.center { + display: flex; + flex-direction: column; + gap: 0.9rem; + max-width: 34rem; + margin: 9vh auto; + padding: 1rem; } h1 { - font-size: 56px; - letter-spacing: -1.68px; - margin: 32px 0; - @media (max-width: 1024px) { - font-size: 36px; - margin: 20px 0; - } -} -h2 { - font-size: 24px; - line-height: 118%; - letter-spacing: -0.24px; - margin: 0 0 8px; - @media (max-width: 1024px) { - font-size: 20px; - } -} -p { + font-size: 1.4rem; + font-weight: 600; margin: 0; } -code, -.counter { - font-family: var(--mono); - display: inline-flex; - border-radius: 4px; - color: var(--text-h); +.muted { + color: var(--fg-muted); + line-height: 1.5; } -code { - font-size: 15px; - line-height: 135%; - padding: 4px 8px; - background: var(--code-bg); -} - -.counter { - font-size: 16px; - padding: 5px 10px; - border-radius: 5px; - color: var(--accent); - background: var(--accent-bg); - border: 2px solid transparent; - transition: border-color 0.3s; - margin-bottom: 24px; - - &:hover { - border-color: var(--accent-border); - } - &:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 2px; - } -} - -.hero { - position: relative; - - .base, - .framework, - .vite { - inset-inline: 0; - margin: 0 auto; - } - - .base { - width: 170px; - position: relative; - z-index: 0; - } - - .framework, - .vite { - position: absolute; - } - - .framework { - z-index: 1; - top: 34px; - height: 28px; - transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg) - scale(1.4); - } - - .vite { - z-index: 0; - top: 107px; - height: 26px; - width: auto; - transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg) - scale(0.8); - } -} - -#app { - width: 1126px; - max-width: 100%; - margin: 0 auto; - text-align: center; - border-inline: 1px solid var(--border); - min-height: 100svh; +.bar { display: flex; - flex-direction: column; - box-sizing: border-box; + align-items: center; + gap: 1rem; + padding: 0.8rem 1.2rem; + border-bottom: 1px solid var(--border); + position: sticky; + top: 0; + background: var(--bg); } -#center { - display: flex; - flex-direction: column; - gap: 25px; - place-content: center; - place-items: center; - flex-grow: 1; - - @media (max-width: 1024px) { - padding: 32px 20px 24px; - gap: 18px; - } +.bar .muted { + flex: 1; } -#next-steps { - display: flex; - border-top: 1px solid var(--border); +button { + border: 1px solid var(--border); + border-radius: 6px; + padding: 0.45rem 0.9rem; + background: var(--bg-card); + color: var(--fg); + cursor: pointer; +} + +button:hover:enabled { + filter: brightness(1.15); +} + +button:disabled { + opacity: 0.55; + cursor: default; +} + +button.primary { + background: var(--accent); + border-color: var(--accent); + color: #fff; + font-weight: 600; +} + +button.ghost { + background: transparent; +} + +table { + width: calc(100% - 2.4rem); + margin: 1rem 1.2rem; + border-collapse: collapse; +} + +th, +td { + border-bottom: 1px solid var(--border); + padding: 0.4rem 0.6rem; text-align: left; - - & > div { - flex: 1 1 0; - padding: 32px; - @media (max-width: 1024px) { - padding: 24px 20px; - } - } - - .icon { - margin-bottom: 16px; - width: 22px; - height: 22px; - } - - @media (max-width: 1024px) { - flex-direction: column; - text-align: center; - } } -#docs { - border-right: 1px solid var(--border); - - @media (max-width: 1024px) { - border-right: none; - border-bottom: 1px solid var(--border); - } +th.num, +td.num { + text-align: right; } -#next-steps ul { - list-style: none; - padding: 0; - display: flex; - gap: 8px; - margin: 32px 0 0; - - .logo { - height: 18px; - } - - a { - color: var(--text-h); - font-size: 16px; - border-radius: 6px; - background: var(--social-bg); - display: flex; - padding: 6px 12px; - align-items: center; - gap: 8px; - text-decoration: none; - transition: box-shadow 0.3s; - - &:hover { - box-shadow: var(--shadow); - } - .button-icon { - height: 18px; - width: 18px; - } - } - - @media (max-width: 1024px) { - margin-top: 20px; - flex-wrap: wrap; - justify-content: center; - - li { - flex: 1 1 calc(50% - 8px); - } - - a { - width: 100%; - justify-content: center; - box-sizing: border-box; - } - } +.footnote { + margin: 0.6rem 1.2rem 2rem; + font-size: 0.85rem; } -#spacer { - height: 88px; - border-top: 1px solid var(--border); - @media (max-width: 1024px) { - height: 48px; - } +.info { + color: #7fa9d4; } -.ticks { - position: relative; - width: 100%; - - &::before, - &::after { - content: ''; - position: absolute; - top: -4.5px; - border: 5px solid transparent; - } - - &::before { - left: 0; - border-left-color: var(--border); - } - &::after { - right: 0; - border-right-color: var(--border); - } +.error { + color: var(--error); } diff --git a/src/assets/hero.png b/src/assets/hero.png deleted file mode 100644 index 02251f4..0000000 Binary files a/src/assets/hero.png and /dev/null differ diff --git a/src/assets/svelte.svg b/src/assets/svelte.svg deleted file mode 100644 index c5e0848..0000000 --- a/src/assets/svelte.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/assets/vite.svg b/src/assets/vite.svg deleted file mode 100644 index 5101b67..0000000 --- a/src/assets/vite.svg +++ /dev/null @@ -1 +0,0 @@ -Vite diff --git a/src/lib/Counter.svelte b/src/lib/Counter.svelte deleted file mode 100644 index 5f046bd..0000000 --- a/src/lib/Counter.svelte +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/src/lib/audible.ts b/src/lib/audible.ts new file mode 100644 index 0000000..40de561 --- /dev/null +++ b/src/lib/audible.ts @@ -0,0 +1,22 @@ +import { invoke } from '@tauri-apps/api/core' + +export interface AuthStatus { + logged_in: boolean + profiles: string[] + auth_dir: string +} + +export interface Book { + asin: string + title: string + authors: string + narrators: string + runtime_length_min: number + cover_url: string + percent_complete: number + is_finished: boolean +} + +export const authStatus = () => invoke('auth_status') +export const startLogin = () => invoke('start_login') +export const getLibrary = () => invoke('get_library')