Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect default application for opening PDFs #814

Closed
apyrgio opened this issue May 23, 2024 · 1 comment · Fixed by #832
Closed

Detect default application for opening PDFs #814

apyrgio opened this issue May 23, 2024 · 1 comment · Fixed by #832
Assignees
Labels
bug Something isn't working
Milestone

Comments

@apyrgio
Copy link
Contributor

apyrgio commented May 23, 2024

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

def _find_pdf_viewers(self) -> Dict[str, str]:
pdf_viewers: Dict[str, str] = {}
if platform.system() == "Linux":
# Find all .desktop files
for search_path in [
"/usr/share/applications",
"/usr/local/share/applications",
os.path.expanduser("~/.local/share/applications"),
]:
try:
for filename in os.listdir(search_path):
full_filename = os.path.join(search_path, filename)
if os.path.splitext(filename)[1] == ".desktop":
# See which ones can open PDFs
desktop_entry = DesktopEntry(full_filename)
if (
"application/pdf" in desktop_entry.getMimeTypes()
and "dangerzone" not in desktop_entry.getName().lower()
):
pdf_viewers[desktop_entry.getName()] = (
desktop_entry.getExec()
)
except FileNotFoundError:
pass
return pdf_viewers

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 apyrgio added the bug Something isn't working label May 23, 2024
@apyrgio
Copy link
Contributor Author

apyrgio commented May 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants