You are not logged in.

#1 2017-05-01 14:57:36

x1Bape
Member
Registered: 2017-05-01
Posts: 1

Thoughts on my process to get magnet links to work (chrome/xdg-open)

Hi,

First of all I'm a tad new, so I hope this is the correct place to post this since I feel like this is a basic problem.
I'm trying to get chrome (not chromium) to open magnet links with deluge. I have it working now but am quite unsure about my approach and whether there is something else I can do that's a bit cleaner.

The mime type default is set correctly according to:

$ xdg-mime query default x-scheme-handler/magnet
deluge.desktop

The desktop entry is also available at

$ ls /usr/share/applications/deluge.desktop 
/usr/share/applications/deluge.desktop

I remember a chrome popup asking if I wanted to open links with xdg-open, so I tried to execute a magnet link with the command. This resulted in the same behaviour as clicking the magnet link in chrome, which opened up a new browser tab.

So at deads end, I opened up xdg-open and examined the code. What the script basically does is determine the desktop environment, and handle the request accordingly.
Now I am on OpenBox, which means that I ended up in the generic execution bracket, namely function open_generic().

The function roughly looks like this:

open_generic()
{
    if is_file_url_or_path "$1"; then
       #handle opening file
    fi

    if [ -n "$BROWSER" ];  then
        open_envvar "$1"
    fi

    if [ -n "$DISPLAY" ]; then
        open_generic_xdg_x_scheme_handler "$1"
    fi

    # if BROWSER variable is not set, check some well known browsers instead
    if [ x"$BROWSER" = x"" ]; then
       # some fallback
    fi

    open_envvar "$1"

    exit_failure_operation_impossible "no method available for opening '$1'"
}

To me this looks like that if the environment variable $BROWSER is set (which is in my case as per default installation), it will always resolve to open any protocol with the browser?
When I changed

    if [ -n "$BROWSER" ];  then

to

    if [ -n "$BROWSER" ] && ! (echo "$1" | grep -q '^magnet:') ;  then

xdg-open works correctly since it actually tries to find the scheme handler. Any thoughts?

Offline

Board footer

Powered by FluxBB