From 23bbc95f964c808db28c13ae9c31d8c8df6139d5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 25 Nov 2023 13:01:51 +0530 Subject: [PATCH] Linux: Fix external applications not being launched under Wayland --- src/calibre/gui2/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index cce168e597..c3f0c7f242 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1462,7 +1462,13 @@ def open_url(qurl): # Qt 5 requires QApplication to be constructed before trying to use # QDesktopServices::openUrl() ensure_app() - ok = QDesktopServices.openUrl(qurl) + cmd = ['xdg-open', qurl.toLocalFile() if qurl.isLocalFile() else qurl.toString(QUrl.ComponentFormattingOption.FullyEncoded)] + if isfrozen and QApplication.instance().platformName() == "wayland": + # See https://bugreports.qt.io/browse/QTBUG-119438 + subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + ok = True + else: + ok = QDesktopServices.openUrl(qurl) if not ok: # this happens a lot with Qt 6.5.3. On Wayland, Qt requires # BOTH a QApplication AND a top level window so it can use the @@ -1470,7 +1476,6 @@ def open_url(qurl): print('QDesktopServices::openUrl() failed for url:', qurl, file=sys.stderr) if islinux: import subprocess - cmd = ['xdg-open', qurl.toLocalFile() if qurl.isLocalFile() else qurl.toString(QUrl.ComponentFormattingOption.FullyEncoded)] if DEBUG: print('Running opener:', cmd) subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)