chmln / handlr

A better xdg-utils
MIT License
616 stars 24 forks source link

Malformed entry in desktop file #9

Closed Kabouik closed 4 years ago

Kabouik commented 4 years ago

I recently stumbled upon handlr and I love it, thank you so much for it, it really healed a lot of headaches I was always having with xdg-open. However, I have a custom .desktop file that I would like to use as a default application and handlr says the desktop entry is malformed. I'm sure this is me doing something wrong in the .desktop file, but it used to work with other openers and handlr is not saying exactly what is wrong with it:

$ handlr set .mp3 cmus.desktop
error: Invalid value for '<handler>': malformed desktop entry at /home/kabouik/.local/share/applications/cmus.desktop

$ micro /home/kabouik/.local/share/applications/cmus.desktop 

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Display=true
Exec=bash -c "(! pgrep cmus && tilix -e cmus && tilix -a session-add-down -e cava); sleep 0.1 && cmus-remote -q %f"
Terminal=false
Name=cmus-remote
Comment=Music player cmus-remote control
NoDisplay=true
Icon=cmus

This is supposed to open a new Tilix window and run cmus in it, plus open an additional Tilix pane below it to run cava, if a cmus session is already opened, it will just add the file to play queue using cmus-remote. There is obviously something handlr doesn't like about it but I don't know how to troubleshoot. Any help would be greatly appreciated!

chmln commented 4 years ago

@Kabouik please try v0.4.4 and let me know if the issue is fixed! :)

Kabouik commented 4 years ago

It's working, thanks a lot!

Kabouik commented 4 years ago

There's another issue though, I'm not sure if it is related to that one but since I did not notice it before, maybe you'll know better:

I noticed that you updated the README to explain how to add extra handlers, so I wanted to test. I configured handlr.toml to my liking to use my rofi theme, set enable_selector = true, and then ran handlr add .mp3 sayonara.desktop. When I click on a .mp3, cmus is still being used by default and rofi doesn't show up. Yet, the .toml file is correct because if I handlr get .mp3, then rofi selector appears.

Another thing: if I handlr open /path/to/mp3, it opens Audacity. I have no idea where this comes from, since Audacity is not listed in handlr list. I guess it might be some leftovers in other mime/whatever files?

chmln commented 4 years ago

@Kabouik it is probably because handlr open detects an mp3 file as audio/mpeg, while .mp3 gets resolved as audio/mp3.

I've fixed this in v0.4.5 by resolving the extensions through the same database that's used to guess the mime from content.

Thanks for providing useful feedback!

Kabouik commented 4 years ago

Thanks for the quick fix! Just after updating handlr, I ran handlr get .mp3 and this time it returned audacity.desktop indeed. I now set again cmus.desktop as default and sayonara.desktop as extra.

Not sure if this is a real issue or if it's caused by my hacky desktop file:

chmln commented 4 years ago

@Kabouik it depends on how the file manager handles double-clicking. There's a few options

1) it uses something specific like gvfs-open or similar, which does not call handlr 2) it uses xdg-open. In this case you can install https://aur.archlinux.org/packages/xdg-utils-handlr or override it manually

If you want you can let me know what DE/file manager you use and I could look into it

Kabouik commented 4 years ago

Thanks. Since I don't use Arch, I just created two aliases in my ~/bashrc instead of creating a bash file in /usr/bin:

alias xdg-open='handlr open "$@"'
alias gvfs-open='handlr open "$@"'

And then confirmed from command line that both aliases now call handlr (.mp3 files invoked the rofi selector).

The issue with files containing a space in their path was due to missing quotes in my cmus.desktop's Exec line. Not sure why it was working correctly from file managers and not from command line, but anyway I fixed it with:

Exec=bash -c '(! pgrep cmus && tilix -e cmus && tilix -a session-add-down -e cava); sleep 0.1 && cmus-remote -q "%f"'

Nautilus still bypasses handlr though, I have to investigate and see what it is using by default and maybe make another alias. nnn does the same, although it should be using xdg-open, there must still be something I'm missing.

Kabouik commented 4 years ago

Turns out trying to be smart and making aliases instead of using a script placed in $PATH was a very bad idea, since aliases work only directly in a shell, not when called from other programs (this is what I learnt here). Works as expected with the simple script you linked in my user $PATH to replace xdg-open from the base $PATH.