How to configure Chrome to open magnet URI's with Deluge?

For 12.04 up to 16.04

In 12.04 and 13.04, deluge does include x-scheme-handler/magnet=deluge.desktop; in the desktop file. In my case, transmission was still opening magnet links. I had to tell gvfs-open preferring deluge with:

gvfs-mime --set x-scheme-handler/magnet deluge.desktop

For 18.04

gvfs-mime was deprecated and 'gio mime' used instead:

gio mime x-scheme-handler/magnet deluge.desktop

The answer is in fact a bug in deluge packaging (or, perhaps deluge is the same & everything else changed around it... depends on your perspective, I guess.) See the forum topic here for the details.

Basically, setting up xdg-open's config via gconf-editor didn't do anything to resolve the issue, since as of Natty the file-open functionality is handled by gvfs-open, which doesn't use gconf settings. Rather, gvfs-open looks at the ".desktop" files bundled with each application to determine what file types can be handled (if not installed, run sudo apt-get install gvfs-bin).

From the forum posting, the /usr/share/applications/deluge.desktop file has a couple issues; it should say Exec=deluge-gtk %U (rather than just "Exec=deluge-gtk") so that the argument is passed to the application. Second, rather than just MimeType=application/x-bittorrent; it should say MimeType=application/x-bittorrent;x-scheme-handler/magnet;.

The update should be coming through soon... Here is the link to the updated desktop file should you want to make the change yourself; just run sudo update-desktop-database and everything just starts working (don't even have to restart chrome/chromium).


Ubuntu

Recently it is also needed to add the following line to ~/.local/share/applications/mimeapps.list under [Added Associations]

x-scheme-handler/magnet=deluge.desktop;

Kubuntu

On Kubuntu however, you have to create the following file in ~/.kde/share/kde4/services/magnet.protocol

[Protocol]
exec=deluge "%u"
protocol=magnet
input=none
output=none
helper=true
listing=false
reading=false
writing=false
makedir=false
deleting=false

Note: Don't forget to relog after these changes.