From 8e9d4d60f84c5cdb77dc0030a1345c85fd73b5f8 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Wed, 13 Nov 2024 09:36:22 +0100 Subject: [PATCH] Use xdg-mime to choose a default pdf viewer in the run configuration template --- CHANGELOG.md | 1 + .../run/linuxpdfviewer/InternalPdfViewer.kt | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee134589b..8cb7c52a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Added +* Use xdg-mime to choose a default pdf viewer in the run configuration template ### Fixed diff --git a/src/nl/hannahsten/texifyidea/run/linuxpdfviewer/InternalPdfViewer.kt b/src/nl/hannahsten/texifyidea/run/linuxpdfviewer/InternalPdfViewer.kt index 7943f9a74..f691d90f9 100644 --- a/src/nl/hannahsten/texifyidea/run/linuxpdfviewer/InternalPdfViewer.kt +++ b/src/nl/hannahsten/texifyidea/run/linuxpdfviewer/InternalPdfViewer.kt @@ -65,6 +65,17 @@ enum class InternalPdfViewer( // These properties may be used often when opening a project or during project use because of settings state initialization, so we cache them. val availableSubset: List by lazy { entries.filter { it.isAvailable() } } - val firstAvailable: InternalPdfViewer by lazy { availableSubset.first() } + val firstAvailable: InternalPdfViewer by lazy { + // Use system default if possible + if (SystemInfo.isLinux) { + // e.g. okularApplication_pdf.desktop or org.gnome.Evince.desktop + runCommand("xdg-mime", "query", "default", "application/pdf", timeout = 1)?.let { + availableSubset.firstOrNull { viewer -> viewer.name.lowercase() in it.lowercase() } + } ?: availableSubset.first() + } + else { + availableSubset.first() + } + } } }