mod audible; mod download; use audible::{AudibleClient, AuthStatus, Book, CliAudibleClient}; use download::{DownloadMgr, SharedDownloadMgr}; use tauri::Manager; #[tauri::command] 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 start_decrypt(client: tauri::State) -> Result { client.start_decrypt() } #[tauri::command] fn download_list(dl: tauri::State) -> Vec { dl.list() } #[tauri::command] fn download_enqueue(dl: tauri::State, asin: String) -> Result { dl.enqueue(&asin) } #[tauri::command] fn download_cancel(dl: tauri::State, asin: String) -> Result { dl.cancel(&asin) } #[tauri::command] fn download_delete(dl: tauri::State, asin: String) -> Result<(), String> { dl.delete(&asin) } /// Bibliothek laden: externer CLI-Export dauert (Netzwerk) — läuft deshalb /// auf einem Blocking-Thread, damit die UI nicht friert. #[tauri::command] async fn get_library( client: tauri::State<'_, CliAudibleClient>, ) -> Result, String> { let c = client.inner().clone(); tauri::async_runtime::spawn_blocking(move || c.library()) .await .map_err(|e| format!("Hintergrundthread fehlgeschlagen: {e}"))? } /// Lokale Titel auch ohne Netz/Anmeldung — ffprobe-basiert. #[tauri::command] async fn get_local_books() -> Result, String> { tauri::async_runtime::spawn_blocking(audible::local_books) .await .map_err(|e| format!("Hintergrundthread fehlgeschlagen: {e}")) } /// Titel, die Audible bewusst nicht als Datei liefert (Nur-Streaming). #[tauri::command] async fn stream_only() -> Result, String> { tauri::async_runtime::spawn_blocking(download::stream_only_load) .await .map_err(|e| format!("Hintergrundthread fehlgeschlagen: {e}")) } #[tauri::command] async fn get_alter_notes() -> Result { tauri::async_runtime::spawn_blocking(audible::alter_notes) .await .map_err(|e| format!("Hintergrundthread fehlgeschlagen: {e}")) } #[tauri::command] async fn set_alter_note( asin: String, note: Option, ) -> Result<(), String> { tauri::async_runtime::spawn_blocking(move || audible::set_alter_note(&asin, note)) .await .map_err(|e| format!("Hintergrundthread fehlgeschlagen: {e}"))? } #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_opener::init()) .manage(CliAudibleClient::new()) .manage(DownloadMgr::new()) .setup(|app| { app.state::() .attach(app.handle().clone()); Ok(()) }) .invoke_handler(tauri::generate_handler![ auth_status, start_login, start_decrypt, get_library, get_local_books, stream_only, get_alter_notes, set_alter_note, download_list, download_enqueue, download_cancel, download_delete ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); }