From a7117df837db39e8d2e4590dd6b0434415f79264 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 2 Aug 2022 19:18:41 +0400 Subject: [PATCH] Use glib to open URLs on Linux Just like in lib_base&tdesktop --- ui/basic_click_handlers.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ui/basic_click_handlers.cpp b/ui/basic_click_handlers.cpp index 71d3da7..33624ea 100644 --- a/ui/basic_click_handlers.cpp +++ b/ui/basic_click_handlers.cpp @@ -12,11 +12,19 @@ #include "base/qthelp_url.h" #include "base/qt/qt_string_view.h" +#if defined Q_OS_UNIX && !defined Q_OS_MAC && !defined DESKTOP_APP_DISABLE_DBUS_INTEGRATION +#include "base/platform/linux/base_linux_app_launch_context.h" +#endif // Q_OS_UNIX && !Q_OS_MAC && !DESKTOP_APP_DISABLE_DBUS_INTEGRATION + #include #include #include #include +#if defined Q_OS_UNIX && !defined Q_OS_MAC && !defined DESKTOP_APP_DISABLE_DBUS_INTEGRATION +#include +#endif // Q_OS_UNIX && !Q_OS_MAC && !DESKTOP_APP_DISABLE_DBUS_INTEGRATION + QString TextClickHandler::readable() const { const auto result = url(); return !result.startsWith(qstr("internal:")) @@ -80,6 +88,25 @@ void UrlClickHandler::Open(QString url, QVariant context) { if (IsEmail(url)) { url = "mailto: " + url; } +#if defined Q_OS_UNIX && !defined Q_OS_MAC && !defined DESKTOP_APP_DISABLE_DBUS_INTEGRATION + // Desktop entry spec implementation, + // prefer it over QDesktopServices::openUrl since it just calls + // the xdg-open shell script that is known to be bugged: + // various shell-specific bugs with spaces in paths, + // logic bugs violating the spec and etc, etc. + // Not to mention xdg-open can and will use DE-specific executables + // that allows various ill people to develop extensions + // to the standard and differ the behavior across apps. + // https://specifications.freedesktop.org/desktop-entry-spec/latest/ + try { + if (Gio::AppInfo::launch_default_for_uri( + url.toStdString(), + base::Platform::AppLaunchContext())) { + return; + } + } catch (...) { + } +#endif // Q_OS_UNIX && !Q_OS_MAC && !DESKTOP_APP_DISABLE_DBUS_INTEGRATION QDesktopServices::openUrl(url); } }