From 4a7c5dbd5a348925141add54c8957fe8e8edafb8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 25 Nov 2023 07:31:45 +0530 Subject: [PATCH] Linux: When Qt fails to open a file with the system default application fallback to xdg-open explicitly Who knows what Qt does these days. Portals and desktop heauristics and platform plugins. Sigh. Linux is such a clusterfuck. --- src/calibre/gui2/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 86d52eee3d..a8623ae4e1 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1462,7 +1462,18 @@ def open_url(qurl): # Qt 5 requires QApplication to be constructed before trying to use # QDesktopServices::openUrl() ensure_app() - QDesktopServices.openUrl(qurl) + ok = QDesktopServices.openUrl(qurl) + if not ok: + # this happens a lot with Qt 6.5.3 on some Linux distros + print('QDesktopServices.openUrl() failed for url:', qurl, file=sys.stderr) + if islinux: + if qurl.isLocalFile(): + cmd = ['xdg-open', qurl.toLocalFile()] + else: + cmd = ['xdg-open', qurl.toString()] + if DEBUG: + print('Running opener:', cmd) + subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) def safe_open_url(qurl):