fix: cannot add magnet links from the command line (#8415)

This commit is contained in:
Charles Kerr
2026-02-10 09:05:32 -06:00
committed by GitHub
parent 3d8363a8d4
commit abb9b05ff2

View File

@@ -144,7 +144,7 @@ private:
void inc_busy(); void inc_busy();
void dec_busy(); void dec_busy();
bool add(Glib::ustring const& name, bool do_start, bool do_prompt, bool do_notify); bool add(Glib::ustring const& name_in, bool do_start, bool do_prompt, bool do_notify);
void add_file_async_callback( void add_file_async_callback(
Glib::RefPtr<Gio::File> const& file, Glib::RefPtr<Gio::File> const& file,
Glib::RefPtr<Gio::AsyncResult>& result, Glib::RefPtr<Gio::AsyncResult>& result,
@@ -822,8 +822,18 @@ void Session::Impl::add_file_async_callback(
} }
// Add `name,` which might be a local filename, a magnet link, or a URI. // Add `name,` which might be a local filename, a magnet link, or a URI.
bool Session::Impl::add(Glib::ustring const& name, bool const do_start, bool const do_prompt, bool const do_notify) bool Session::Impl::add(Glib::ustring const& name_in, bool const do_start, bool const do_prompt, bool const do_notify)
{ {
auto name = name_in;
// `gio::File` doesn't seem to know how to stringify magnet links correctly.
// Unfortunately there are some code paths that unavoidably use `gio::File`
// e.g. Gtk::Application::on_open() so we have to do this:
if (auto constexpr BrokenMagnetLinkPrefix = "magnet:///?"sv; tr_strv_starts_with(name.raw(), BrokenMagnetLinkPrefix))
{
name.replace(0, std::size(BrokenMagnetLinkPrefix), "magnet:?");
}
auto* const session = get_session(); auto* const session = get_session();
if (session == nullptr) if (session == nullptr)
{ {