freedomofpress / dangerzone

Take potentially dangerous PDFs, office documents, or images and convert them to safe PDFs
https://dangerzone.rocks/
GNU Affero General Public License v3.0
3.35k stars 152 forks source link

Detect default application for opening PDFs #814

Closed apyrgio closed 2 weeks ago

apyrgio commented 1 month ago

Dangerzone has some logic for detecting which application (*.desktop file) can open a PDF:

https://github.com/freedomofpress/dangerzone/blob/65776d8c0506535c20f74f4375193287e1e8a78b/dangerzone/gui/logic.py#L97-L123

The result on Tails 6.2 is the following application list:

image

However, what's missing here is to present to the user the default application for opening PDFs. Instead, the first choice is picked up at random. Here, it's GIMP, whereas it should be Document Viewer.

apyrgio commented 1 month ago

On almost all Linux distros, we can use xdg-mime to find the default application for a mime type. On Tails, it returns the correct application:

$ xdg-mime query default application/pdf
org.gnome.Evince.desktop

We can improve this list by putting at the top the desktop file that xdg-mime returns. If xdg-mime is not present, or returns no results, we can keep the list order as is.