Skip to content

Detect default application for opening PDFs #814

@apyrgio

Description

@apyrgio

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions