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");
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { authStatus, startLogin, getLibrary, type Book } from './lib/audible'
|
||||
import { authStatus, startLogin, startDecrypt, getLibrary, type Book } from './lib/audible'
|
||||
|
||||
type View = 'loading' | 'login' | 'library'
|
||||
type SortKey = 'added' | 'title' | 'author' | 'runtime' | 'percent'
|
||||
@ -61,10 +61,16 @@
|
||||
books = await getLibrary()
|
||||
view = 'library'
|
||||
} catch (e) {
|
||||
// Fehler sichtbar machen, nicht in der Lade-Ansicht hängen
|
||||
error = String(e)
|
||||
view = 'library'
|
||||
books = []
|
||||
const msg = String(e)
|
||||
if (msg.toLowerCase().includes('encrypted')) {
|
||||
// Auth-Datei verschlüsselt — Entschlüsselung im Terminal anbieten
|
||||
error = 'Auth-Datei ist verschlüsselt. Bitte einmal entschriften:'
|
||||
view = 'login'
|
||||
} else {
|
||||
error = msg
|
||||
view = 'library'
|
||||
books = []
|
||||
}
|
||||
} finally {
|
||||
checking = false
|
||||
loadingMsg = 'Prüfe Anmeldung…'
|
||||
@ -78,6 +84,7 @@
|
||||
const s = await authStatus()
|
||||
if (s.logged_in) {
|
||||
clearPoll()
|
||||
view = 'loading'
|
||||
loadingMsg = 'Lade Bibliothek…'
|
||||
await loadLibrary()
|
||||
} else if (view !== 'login') {
|
||||
@ -136,6 +143,11 @@
|
||||
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>
|
||||
{checking ? 'Prüfe…' : 'Jetzt prüfen'}
|
||||
</button>
|
||||
{#if error === 'Auth-Datei ist verschlüsselt. Bitte einmal entschriften:'}
|
||||
<button class="ghost" onclick={() => startDecrypt().catch((e) => (error = String(e)))}>
|
||||
Entschlüsseln im Terminal…
|
||||
</button>
|
||||
{/if}
|
||||
{#if info}<p class="info">{info}</p>{/if}
|
||||
{#if error}<p class="error">{error}</p>{/if}
|
||||
</main>
|
||||
|
||||
@ -21,4 +21,5 @@ export interface Book {
|
||||
|
||||
export const authStatus = () => invoke<AuthStatus>('auth_status')
|
||||
export const startLogin = () => invoke<boolean>('start_login')
|
||||
export const startDecrypt = () => invoke<boolean>('start_decrypt')
|
||||
export const getLibrary = () => invoke<Book[]>('get_library')
|
||||
|
||||
Reference in New Issue
Block a user