| 1 |
From: Thomas Christensen <[email protected]> |
| 2 |
Date: Sun, 17 May 2026 04:54:42 +0700 |
| 3 |
Subject: app: normalize magnet URIs before adding |
| 4 |
MIME-Version: 1.0 |
| 5 |
Content-Type: text/plain; charset="utf-8" |
| 6 |
Content-Transfer-Encoding: 8bit |
| 7 |
|
| 8 |
gio::File::for_uri("magnet:?xt=…").uri() re-emits the URI in |
| 9 |
hierarchical form ("magnet:///?xt=…"). Transmission's torrent-add |
| 10 |
RPC rejects this form, so opening a magnet link from a browser via |
| 11 |
the D-Bus Open() path failed with the generic "Unable to add |
| 12 |
torrent" toast. |
| 13 |
|
| 14 |
Strip the spurious empty authority before handing the URI to |
| 15 |
add_torrent_by_link so transmission receives the canonical |
| 16 |
magnet:?xt=… form. Clipboard-detection and the add-link GAction |
| 17 |
were already unaffected because they bypass gio::File. |
| 18 |
|
| 19 |
Forwarded: https://gitlab.gnome.org/World/Fragments/-/merge_requests/202 |
| 20 |
--- |
| 21 |
src/app.rs | 15 ++++++++++++++- |
| 22 |
1 file changed, 14 insertions(+), 1 deletion(-) |
| 23 |
|
| 24 |
diff --git a/src/app.rs b/src/app.rs |
| 25 |
index f599bb4..0b95c22 100644 |
| 26 |
--- a/src/app.rs |
| 27 |
+++ b/src/app.rs |
| 28 |
@@ -563,12 +563,25 @@ impl FrgApplication { |
| 29 |
} else { |
| 30 |
// URI, means magnet or torrent link |
| 31 |
let uri = file.uri().to_string(); |
| 32 |
- self.imp().add_torrent_by_link(uri); |
| 33 |
+ self.imp().add_torrent_by_link(normalize_magnet_uri(uri)); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
+// `gio::File::for_uri("magnet:?xt=…").uri()` re-emits magnet URIs in |
| 40 |
+// hierarchical form (`magnet:///?xt=…`), which transmission's torrent-add |
| 41 |
+// rejects. Strip the spurious empty authority so we hand transmission the |
| 42 |
+// canonical `magnet:?xt=…` form. |
| 43 |
+fn normalize_magnet_uri(uri: String) -> String { |
| 44 |
+ if let Some(rest) = uri.strip_prefix("magnet:") { |
| 45 |
+ let rest = rest.trim_start_matches('/'); |
| 46 |
+ format!("magnet:{rest}") |
| 47 |
+ } else { |
| 48 |
+ uri |
| 49 |
+ } |
| 50 |
+} |
| 51 |
+ |
| 52 |
impl Default for FrgApplication { |
| 53 |
fn default() -> Self { |
| 54 |
gio::Application::default() |