T-013: Download-Manager — Queue mit Bytes-Fortschritt-Events, Abbruch, Wiederaufnahme per Manifest nach Neustart, UI: Laden/Abbrechen auf Cards
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -66,26 +66,26 @@ impl CliAudibleClient {
|
||||
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<PathBuf, String> {
|
||||
if let Some(home) = home_dir() {
|
||||
let p = home.join(".local/bin/audible");
|
||||
if p.is_file() {
|
||||
return Ok(p);
|
||||
}
|
||||
/// Findet die audible-CLI: bevorzugt `~/.local/bin/audible` (pipx),
|
||||
/// sonst `$PATH`. Übergabe als Argumentliste, nie über eine Shell.
|
||||
pub fn audible_binary() -> Option<PathBuf> {
|
||||
if let Some(home) = home_dir() {
|
||||
let p = home.join(".local/bin/audible");
|
||||
if p.is_file() {
|
||||
return Some(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())
|
||||
}
|
||||
if let Ok(path) = env::var("PATH") {
|
||||
for dir in env::split_paths(&path) {
|
||||
let p = dir.join("audible");
|
||||
if p.is_file() {
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
impl Default for CliAudibleClient {
|
||||
@ -94,7 +94,7 @@ impl Default for CliAudibleClient {
|
||||
}
|
||||
}
|
||||
|
||||
fn home_dir() -> Option<PathBuf> {
|
||||
pub(crate) fn home_dir() -> Option<PathBuf> {
|
||||
env::var("HOME").ok().map(PathBuf::from)
|
||||
}
|
||||
|
||||
@ -148,7 +148,9 @@ 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 bin = audible_binary().ok_or_else(|| {
|
||||
"audible-cli nicht gefunden — Installation: pipx install audible-cli".to_string()
|
||||
})?;
|
||||
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());
|
||||
};
|
||||
@ -171,7 +173,9 @@ impl AudibleClient for CliAudibleClient {
|
||||
}
|
||||
|
||||
fn start_login(&self) -> Result<bool, String> {
|
||||
let bin = self.audible_binary()?;
|
||||
let bin = audible_binary().ok_or_else(|| {
|
||||
"audible-cli nicht gefunden — Installation: pipx install audible-cli".to_string()
|
||||
})?;
|
||||
let Some((term, needs_e, hold)) = find_terminal() else {
|
||||
return Err("kein unterstütztes Terminal gefunden — bitte in deiner Shell ausführen: audible manage auth-file add".to_string());
|
||||
};
|
||||
@ -194,7 +198,9 @@ impl AudibleClient for CliAudibleClient {
|
||||
}
|
||||
|
||||
fn library(&self) -> Result<Vec<Book>, String> {
|
||||
let bin = self.audible_binary()?;
|
||||
let bin = audible_binary().ok_or_else(|| {
|
||||
"audible-cli nicht gefunden — Installation: pipx install audible-cli".to_string()
|
||||
})?;
|
||||
let out = env::temp_dir().join(format!("hoerwerk-library-{}.json", std::process::id()));
|
||||
let exported = Command::new(&bin)
|
||||
.args(["library", "export", "-f", "json", "-o"])
|
||||
@ -229,7 +235,7 @@ pub fn parse_library(content: &str) -> Result<Vec<Book>, String> {
|
||||
|
||||
/// Taugt stderr von audible-cli: Warnungen und Passwort-Prompts raus,
|
||||
/// echte Fehlertexte bleiben.
|
||||
fn reduce_noise(s: &str) -> String {
|
||||
pub(crate) fn reduce_noise(s: &str) -> String {
|
||||
let lower = |l: &str| l.to_lowercase();
|
||||
let kept: Vec<&str> = s
|
||||
.lines()
|
||||
|
||||
458
src-tauri/src/download.rs
Normal file
458
src-tauri/src/download.rs
Normal file
@ -0,0 +1,458 @@
|
||||
//! Download-Manager: Queue mit sequenziellen Jobs über `audible-cli`.
|
||||
//! Fortschritt = Größe der heruntergeladenen AAXC-Datei (Bytes-Events),
|
||||
//! Abbruch = Kindprozess stoppen, Wiederaufnahme = Queue-Manifest bei Neustart.
|
||||
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Child;
|
||||
use std::sync::{Arc, Condvar, Mutex, OnceLock};
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::{AppHandle, Emitter};
|
||||
|
||||
use crate::audible::{audible_binary, reduce_noise};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum DlStatus {
|
||||
#[serde(rename = "queued")]
|
||||
Queued,
|
||||
#[serde(rename = "running")]
|
||||
Running,
|
||||
#[serde(rename = "done")]
|
||||
Done,
|
||||
#[serde(rename = "failed")]
|
||||
Failed,
|
||||
#[serde(rename = "cancelled")]
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DlItem {
|
||||
pub asin: String,
|
||||
pub status: DlStatus,
|
||||
pub bytes: u64,
|
||||
#[serde(default)]
|
||||
pub msg: String,
|
||||
}
|
||||
|
||||
struct Inner {
|
||||
queue: VecDeque<String>,
|
||||
items: BTreeMap<String, DlItem>,
|
||||
cancel_requested: bool,
|
||||
child: Mutex<Option<Child>>,
|
||||
}
|
||||
|
||||
pub struct DownloadMgr {
|
||||
inner: Mutex<Inner>,
|
||||
wake: Condvar,
|
||||
app: OnceLock<AppHandle>,
|
||||
}
|
||||
|
||||
pub type SharedDownloadMgr = Arc<DownloadMgr>;
|
||||
|
||||
/// Ablageort laufender Downloads (spec: temporär, später T-014 konsumiert).
|
||||
pub fn download_root() -> PathBuf {
|
||||
match std::env::var("HOERWERK_DOWNLOAD_DIR") {
|
||||
Ok(p) => PathBuf::from(p),
|
||||
Err(_) => crate::audible::home_dir()
|
||||
.map(|h| h.join(".cache/hoerwerk/download"))
|
||||
.unwrap_or_else(|| std::env::temp_dir().join("hoerwerk-download")),
|
||||
}
|
||||
}
|
||||
|
||||
fn manifest_path() -> PathBuf {
|
||||
download_root().join("queue.json")
|
||||
}
|
||||
|
||||
impl DownloadMgr {
|
||||
/// Erstellt den Manager; laufende/offene Einträge aus dem Manifest
|
||||
/// werden nach Neustart erneut eingereiht.
|
||||
pub fn new() -> SharedDownloadMgr {
|
||||
let mut items: BTreeMap<String, DlItem> = BTreeMap::new();
|
||||
if let Ok(txt) = fs::read_to_string(manifest_path()) {
|
||||
if let Ok(open) = serde_json::from_str::<Vec<DlItem>>(&txt) {
|
||||
for mut it in open {
|
||||
if matches!(it.status, DlStatus::Running | DlStatus::Queued) {
|
||||
it.status = DlStatus::Queued;
|
||||
it.msg = String::new();
|
||||
items.insert(it.asin.clone(), it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let this = Arc::new(DownloadMgr {
|
||||
inner: Mutex::new(Inner {
|
||||
queue: items.keys().cloned().collect(),
|
||||
items,
|
||||
cancel_requested: false,
|
||||
child: Mutex::new(None),
|
||||
}),
|
||||
wake: Condvar::new(),
|
||||
app: OnceLock::new(),
|
||||
});
|
||||
this.persist();
|
||||
let worker = Arc::clone(&this);
|
||||
let _ = std::thread::Builder::new()
|
||||
.name("hoerwerk-downloads".into())
|
||||
.spawn(move || worker_loop(worker));
|
||||
this
|
||||
}
|
||||
|
||||
/// Wird im Tauri-Setup aufgerufen: Events aktivieren.
|
||||
pub fn attach(&self, app: AppHandle) {
|
||||
let _ = self.app.set(app);
|
||||
}
|
||||
|
||||
pub fn list(&self) -> Vec<DlItem> {
|
||||
self.inner.lock().unwrap().items.values().cloned().collect()
|
||||
}
|
||||
|
||||
/// Buch in die Queue aufnehmen (idempotent).
|
||||
pub fn enqueue(&self, asin: &str) -> Result<DlItem, String> {
|
||||
let asin = asin.trim().to_string();
|
||||
if asin.is_empty() {
|
||||
return Err("keine ASIN angegeben".into());
|
||||
}
|
||||
let mut g = self.inner.lock().unwrap();
|
||||
if let Some(it) = g.items.get(&asin) {
|
||||
if matches!(it.status, DlStatus::Queued | DlStatus::Running) {
|
||||
return Ok(it.clone());
|
||||
}
|
||||
}
|
||||
let item = DlItem {
|
||||
asin: asin.clone(),
|
||||
status: DlStatus::Queued,
|
||||
bytes: 0,
|
||||
msg: String::new(),
|
||||
};
|
||||
g.items.insert(asin.clone(), item.clone());
|
||||
g.queue.push_back(asin);
|
||||
self.wake.notify_one();
|
||||
self.persist_locked(&g);
|
||||
drop(g);
|
||||
self.emit(&item);
|
||||
Ok(item)
|
||||
}
|
||||
|
||||
/// Laufenden/geplanten Download abbrechen (Kindprozess stoppen).
|
||||
pub fn cancel(&self, asin: &str) -> Result<DlItem, String> {
|
||||
let mut g = self.inner.lock().unwrap();
|
||||
g.queue.retain(|a| a != asin);
|
||||
g.cancel_requested = true;
|
||||
let mut child = g.child.lock().unwrap();
|
||||
if let Some(c) = child.as_mut() {
|
||||
let _ = c.kill();
|
||||
let _ = c.wait();
|
||||
}
|
||||
*child = None;
|
||||
drop(child);
|
||||
let it = match g.items.get_mut(asin) {
|
||||
Some(it) => {
|
||||
it.status = DlStatus::Cancelled;
|
||||
it.msg = "abgebrochen".into();
|
||||
it.clone()
|
||||
}
|
||||
None => return Err(format!("{} nicht in der Queue", asin)),
|
||||
};
|
||||
self.persist_locked(&g);
|
||||
drop(g);
|
||||
self.emit(&it);
|
||||
Ok(it)
|
||||
}
|
||||
|
||||
fn persist_locked(&self, g: &Inner) {
|
||||
let list: Vec<DlItem> = g
|
||||
.items
|
||||
.values()
|
||||
.filter(|i| matches!(i.status, DlStatus::Queued | DlStatus::Running))
|
||||
.cloned()
|
||||
.collect();
|
||||
let _ = fs::create_dir_all(download_root());
|
||||
let tmp = manifest_path().with_extension("json.tmp");
|
||||
if fs::write(&tmp, serde_json::to_vec(&list).unwrap_or_default()).is_ok() {
|
||||
let _ = fs::rename(&tmp, manifest_path());
|
||||
}
|
||||
}
|
||||
|
||||
fn persist(&self) {
|
||||
let g = self.inner.lock().unwrap();
|
||||
self.persist_locked(&g);
|
||||
}
|
||||
|
||||
fn emit(&self, item: &DlItem) {
|
||||
if let Some(app) = self.app.get() {
|
||||
let _ = app.emit("download-update", item);
|
||||
}
|
||||
}
|
||||
|
||||
fn item(&self, asin: &str) -> DlItem {
|
||||
self.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.items
|
||||
.get(asin)
|
||||
.cloned()
|
||||
.expect("Item vorhanden")
|
||||
}
|
||||
|
||||
fn finish(&self, asin: &str, status: DlStatus, bytes: u64, msg: String) {
|
||||
let mut g = self.inner.lock().unwrap();
|
||||
if let Some(it) = g.items.get_mut(asin) {
|
||||
it.status = status;
|
||||
it.bytes = bytes;
|
||||
it.msg = msg;
|
||||
}
|
||||
self.persist_locked(&g);
|
||||
let it = self.item_locked(&g, asin);
|
||||
drop(g);
|
||||
self.emit(&it);
|
||||
}
|
||||
|
||||
fn item_locked(&self, g: &Inner, asin: &str) -> DlItem {
|
||||
g.items.get(asin).cloned().expect("Item vorhanden")
|
||||
}
|
||||
}
|
||||
|
||||
fn worker_loop(mgr: SharedDownloadMgr) {
|
||||
loop {
|
||||
let asin = {
|
||||
let mut g = mgr.inner.lock().unwrap();
|
||||
while g.queue.is_empty() {
|
||||
g = mgr.wake.wait(g).unwrap();
|
||||
}
|
||||
let a = g.queue.pop_front().unwrap();
|
||||
if let Some(it) = g.items.get_mut(&a) {
|
||||
it.status = DlStatus::Running;
|
||||
it.bytes = 0;
|
||||
it.msg.clear();
|
||||
}
|
||||
mgr.persist_locked(&g);
|
||||
drop(g);
|
||||
let it = mgr.item(&a);
|
||||
mgr.emit(&it);
|
||||
a
|
||||
};
|
||||
run_download(&mgr, &asin);
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Job: audible-cli ins Job-Verzeichnis, Fortschritt per Dateigröße.
|
||||
fn run_download(mgr: &DownloadMgr, asin: &str) {
|
||||
let Some(bin) = audible_binary() else {
|
||||
mgr.finish(
|
||||
asin,
|
||||
DlStatus::Failed,
|
||||
0,
|
||||
"audible-cli nicht gefunden — pipx install audible-cli".into(),
|
||||
);
|
||||
return;
|
||||
};
|
||||
let dir = download_root().join(asin);
|
||||
if let Err(e) = fs::create_dir_all(&dir) {
|
||||
mgr.finish(asin, DlStatus::Failed, 0, format!("Verzeichnis: {e}"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Falls eine vorherige Partialdatei liegt: Größe als Startpunkt fürs
|
||||
// Fortschrittsmessen (audible-cli schreibt dort weiter/neu).
|
||||
let mut last_bytes = current_bytes(&dir);
|
||||
|
||||
let spawned = std::process::Command::new(&bin)
|
||||
.args([
|
||||
"download",
|
||||
"-y",
|
||||
"-j",
|
||||
"1",
|
||||
"--asin",
|
||||
asin,
|
||||
"--aaxc",
|
||||
"--cover",
|
||||
"--cover-size",
|
||||
"500",
|
||||
"--chapter",
|
||||
"--filename-mode",
|
||||
"asin_only",
|
||||
"-o",
|
||||
])
|
||||
.arg(&dir)
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.spawn();
|
||||
|
||||
let child = match spawned {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
mgr.finish(asin, DlStatus::Failed, 0, format!("Start fehlgeschlagen: {e}"));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Kind für Abbruch dem Manager übergeben
|
||||
{
|
||||
let mut g = mgr.inner.lock().unwrap();
|
||||
g.cancel_requested = false;
|
||||
let mut c = g.child.lock().unwrap();
|
||||
*c = Some(child);
|
||||
}
|
||||
|
||||
loop {
|
||||
std::thread::sleep(Duration::from_millis(600));
|
||||
let exited = {
|
||||
let g = mgr.inner.lock().unwrap();
|
||||
let mut guard = g.child.lock().unwrap();
|
||||
match guard.as_mut() {
|
||||
Some(c) => c
|
||||
.try_wait()
|
||||
.map(|st| st.is_some())
|
||||
.unwrap_or(true),
|
||||
None => true,
|
||||
}
|
||||
};
|
||||
if exited {
|
||||
break;
|
||||
}
|
||||
let size = current_bytes(&dir);
|
||||
if size > last_bytes {
|
||||
last_bytes = size;
|
||||
let mut g = mgr.inner.lock().unwrap();
|
||||
if let Some(it) = g.items.get_mut(asin) {
|
||||
it.bytes = size;
|
||||
}
|
||||
let it = mgr.item_locked(&g, asin);
|
||||
drop(g);
|
||||
mgr.emit(&it);
|
||||
}
|
||||
}
|
||||
|
||||
// Kind zurückholen, Rest stderr lesen, Reap
|
||||
let stderr_text = {
|
||||
let g = mgr.inner.lock().unwrap();
|
||||
let mut guard = g.child.lock().unwrap();
|
||||
match guard.as_mut() {
|
||||
Some(c) => {
|
||||
let _ = c.wait();
|
||||
c.stderr
|
||||
.take()
|
||||
.map(|mut s| {
|
||||
use std::io::Read;
|
||||
let mut buf = Vec::new();
|
||||
let _ = s.read_to_end(&mut buf);
|
||||
reduce_noise(&String::from_utf8_lossy(&buf))
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
None => String::new(),
|
||||
}
|
||||
};
|
||||
|
||||
// Abbruch vermerken
|
||||
{
|
||||
let mut g = mgr.inner.lock().unwrap();
|
||||
if g.cancel_requested {
|
||||
// Abbruch wurde vorgemerkt — Status bleibt Cancelled
|
||||
g.cancel_requested = false; drop(g);
|
||||
let it = {
|
||||
let mut g = mgr.inner.lock().unwrap();
|
||||
if let Some(it) = g.items.get_mut(asin) {
|
||||
it.status = DlStatus::Cancelled;
|
||||
it.msg = "abgebrochen".into();
|
||||
}
|
||||
mgr.item_locked(&g, asin)
|
||||
};
|
||||
mgr.emit(&it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let aaxc = find_any_aaxc(&dir).or_else(|| find_any_aaxc(&dir));
|
||||
let final_bytes = current_bytes(&dir);
|
||||
let ok = aaxc
|
||||
.and_then(|p| fs::metadata(&p).ok())
|
||||
.map(|m| m.len() > 1000)
|
||||
.unwrap_or(false);
|
||||
|
||||
if ok {
|
||||
mgr.finish(asin, DlStatus::Done, final_bytes, String::new());
|
||||
} else {
|
||||
let msg = if stderr_text.trim().is_empty() {
|
||||
"Download endete ohne vollständige AAXC-Datei".to_string()
|
||||
} else {
|
||||
stderr_text.lines().last().unwrap_or("unbekannter Fehler").to_string()
|
||||
};
|
||||
mgr.finish(asin, DlStatus::Failed, final_bytes, msg);
|
||||
}
|
||||
}
|
||||
|
||||
/// Größe der größten AAXC/AXP-Datei im Job-Verzeichnis.
|
||||
fn current_bytes(dir: &Path) -> u64 {
|
||||
let mut best = 0u64;
|
||||
if let Ok(rd) = fs::read_dir(dir) {
|
||||
for e in rd.flatten() {
|
||||
let p = e.path();
|
||||
let matches = p
|
||||
.extension()
|
||||
.and_then(|x| x.to_str())
|
||||
.map(|x| x.eq_ignore_ascii_case("aaxc") || x.eq_ignore_ascii_case("axp"))
|
||||
.unwrap_or(false);
|
||||
if matches {
|
||||
if let Ok(md) = fs::metadata(&p) {
|
||||
best = best.max(md.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
best
|
||||
}
|
||||
|
||||
fn find_any_aaxc(dir: &Path) -> Option<PathBuf> {
|
||||
if let Ok(rd) = fs::read_dir(dir) {
|
||||
for e in rd.flatten() {
|
||||
let p = e.path();
|
||||
if p.extension()
|
||||
.and_then(|x| x.to_str())
|
||||
.map(|x| x.eq_ignore_ascii_case("aaxc"))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn dl_item_serde_status() {
|
||||
let it = DlItem {
|
||||
asin: "A1".into(),
|
||||
status: DlStatus::Done,
|
||||
bytes: 5,
|
||||
msg: "".into(),
|
||||
};
|
||||
let js = serde_json::to_string(&it).unwrap();
|
||||
assert!(js.contains("\"status\":\"done\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manifest_manifest_liest_running_zurueck() {
|
||||
let d = std::env::temp_dir().join(format!("hw-dl-manifest-{}", std::process::id()));
|
||||
let _ = fs::remove_dir_all(&d);
|
||||
fs::create_dir_all(&d).unwrap();
|
||||
let m = d.join("queue.json");
|
||||
let items = vec![DlItem {
|
||||
asin: "B08L4WJMDM".into(),
|
||||
status: DlStatus::Running,
|
||||
bytes: 123,
|
||||
msg: String::new(),
|
||||
}];
|
||||
fs::write(&m, serde_json::to_vec(&items).unwrap()).unwrap();
|
||||
let open: Vec<DlItem> =
|
||||
serde_json::from_str(&fs::read_to_string(&m).unwrap()).unwrap();
|
||||
assert!(matches!(open[0].status, DlStatus::Running));
|
||||
fs::remove_dir_all(d).unwrap();
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,10 @@
|
||||
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<CliAudibleClient>) -> Result<AuthStatus, String> {
|
||||
@ -17,6 +21,21 @@ fn start_decrypt(client: tauri::State<CliAudibleClient>) -> Result<bool, String>
|
||||
client.start_decrypt()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn download_list(dl: tauri::State<SharedDownloadMgr>) -> Vec<download::DlItem> {
|
||||
dl.list()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn download_enqueue(dl: tauri::State<SharedDownloadMgr>, asin: String) -> Result<download::DlItem, String> {
|
||||
dl.enqueue(&asin)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn download_cancel(dl: tauri::State<SharedDownloadMgr>, asin: String) -> Result<download::DlItem, String> {
|
||||
dl.cancel(&asin)
|
||||
}
|
||||
|
||||
/// Bibliothek laden: externer CLI-Export dauert (Netzwerk) — läuft deshalb
|
||||
/// auf einem Blocking-Thread, damit die UI nicht friert.
|
||||
#[tauri::command]
|
||||
@ -33,11 +52,20 @@ pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.manage(CliAudibleClient::new())
|
||||
.manage(DownloadMgr::new())
|
||||
.setup(|app| {
|
||||
app.state::<SharedDownloadMgr>()
|
||||
.attach(app.handle().clone());
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
auth_status,
|
||||
start_login,
|
||||
start_decrypt,
|
||||
get_library
|
||||
get_library,
|
||||
download_list,
|
||||
download_enqueue,
|
||||
download_cancel
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user