Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

fix: address magnet download review issues

InstaZDLLd1a3eb9a1f14
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index d841ad5c..0fa8c77c 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -96,15 +96,15 @@ pub fn run() {
telegram_session.clone(),
),
));
- // Generic yt-dlp fallback — MUST be last so specific downloaders take priority
- registry.register(Arc::new(
- platforms::generic_ytdlp::GenericYtdlpDownloader::new(),
- ));
let torrent_session: Arc<tokio::sync::Mutex<Option<Arc<librqbit::Session>>>> =
Arc::new(tokio::sync::Mutex::new(None));
registry.register(Arc::new(
platforms::magnet::MagnetDownloader::new(torrent_session.clone()),
));
+ // Generic yt-dlp fallback — MUST be last so specific downloaders take priority
+ registry.register(Arc::new(
+ platforms::generic_ytdlp::GenericYtdlpDownloader::new(),
+ ));
let auth_registry = core::auth::AuthRegistry::new();
@@ -131,7 +131,7 @@ pub fn run() {
.plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {
tray::show_window(app);
if let Some(url) = argv.get(1) {
- if url.starts_with("http://") || url.starts_with("https://") {
+ if url.starts_with("http://") || url.starts_with("https://") || url.starts_with("magnet:") {
let _ = app.emit("deep-link", url.clone());
}
}
diff --git a/src-tauri/src/platforms/magnet/mod.rs b/src-tauri/src/platforms/magnet/mod.rs
index 472304a6..d28d142b 100644
--- a/src-tauri/src/platforms/magnet/mod.rs
+++ b/src-tauri/src/platforms/magnet/mod.rs
@@ -89,9 +89,15 @@ impl PlatformDownloader for MagnetDownloader {
listen_port_range: Some(listen_port..listen_port.saturating_add(10)),
..Default::default()
};
- let s = Session::new_with_opts(output_dir.into(), session_opts)
- .await
- .map_err(|e| anyhow::anyhow!("Failed to initialize torrent session: {}", e))?;
+ let cancel_rx = opts.cancel_token.clone();
+ let s = tokio::select! {
+ result = Session::new_with_opts(output_dir.into(), session_opts) => {
+ result.map_err(|e| anyhow::anyhow!("Failed to initialize torrent session: {}", e))?
+ }
+ _ = cancel_rx.cancelled() => {
+ anyhow::bail!("Download cancelled during session creation");
+ }
+ };
*guard = Some(s.clone());
s
}
@@ -100,6 +106,7 @@ impl PlatformDownloader for MagnetDownloader {
let add_torrent = AddTorrent::from_url(url);
let torrent_opts = AddTorrentOptions {
overwrite: true,
+ output_folder: Some(output_dir.to_string_lossy().to_string()),
..Default::default()
};
@@ -130,6 +137,9 @@ impl PlatformDownloader for MagnetDownloader {
loop {
tokio::select! {
_ = tokio::time::sleep(std::time::Duration::from_millis(500)) => {
+ if managed_torrent.is_paused() {
+ continue;
+ }
let stats = managed_torrent.stats();
let total = stats.total_bytes;
let downloaded = stats.progress_bytes;