T-012: Fix — Bibliothek async (spawn_blocking, kein UI-Freeze), Lade-Übergang, decrypt-Button für verschlüsselte Auth-Dateien
This commit is contained in:
@ -41,13 +41,17 @@ pub struct Book {
|
||||
/// `audible-cli` später austauschbar bleibt (spec E-02).
|
||||
pub trait AudibleClient: Send + Sync {
|
||||
fn auth_status(&self) -> Result<AuthStatus, String>;
|
||||
/// Startet die interaktive Anmeldung (audible quickstart) im Terminal.
|
||||
/// Startet die interaktive Anmeldung (audible-cli) im Terminal.
|
||||
/// true = Terminal gestartet, der Nutzer meldet sich dort an; dann
|
||||
/// `auth_status` erneut prüfen.
|
||||
fn start_login(&self) -> Result<bool, String>;
|
||||
/// Startet `manage auth-file decrypt` im Terminal — nötig, wenn die
|
||||
/// Auth-Datei verschlüsselt erzeugt wurde.
|
||||
fn start_decrypt(&self) -> Result<bool, String>;
|
||||
fn library(&self) -> Result<Vec<Book>, String>;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CliAudibleClient {
|
||||
auth_dir: PathBuf,
|
||||
}
|
||||
@ -141,6 +145,31 @@ 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 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());
|
||||
};
|
||||
let mut cmd = Command::new(term);
|
||||
if !hold.is_empty() {
|
||||
cmd.arg(hold);
|
||||
}
|
||||
if needs_e {
|
||||
cmd.arg("-e");
|
||||
}
|
||||
cmd.arg(&bin).args(["manage", "auth-file", "decrypt"]);
|
||||
if let Ok(s) = self.auth_status() {
|
||||
if let Some(name) = s.profiles.first() {
|
||||
cmd.arg("-f").arg(name);
|
||||
}
|
||||
}
|
||||
cmd.spawn()
|
||||
.map_err(|e| format!("Terminal konnte nicht gestartet werden: {e}"))?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn start_login(&self) -> Result<bool, String> {
|
||||
let bin = self.audible_binary()?;
|
||||
let Some((term, needs_e, hold)) = find_terminal() else {
|
||||
|
||||
@ -13,16 +13,32 @@ fn start_login(client: tauri::State<CliAudibleClient>) -> Result<bool, String> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_library(client: tauri::State<CliAudibleClient>) -> Result<Vec<Book>, String> {
|
||||
client.library()
|
||||
fn start_decrypt(client: tauri::State<CliAudibleClient>) -> Result<bool, String> {
|
||||
client.start_decrypt()
|
||||
}
|
||||
|
||||
/// 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<Vec<Book>, String> {
|
||||
let c = client.inner().clone();
|
||||
tauri::async_runtime::spawn_blocking(move || c.library())
|
||||
.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())
|
||||
.invoke_handler(tauri::generate_handler![auth_status, start_login, get_library])
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
auth_status,
|
||||
start_login,
|
||||
start_decrypt,
|
||||
get_library
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user