From 50d2d313e7127802ae25965b6144515cb5d243c2 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 11 Sep 2021 01:49:10 +0400 Subject: [PATCH] Don't link glib with DESKTOP_APP_DISABLE_DBUS_INTEGRATION --- CMakeLists.txt | 13 ++++++++----- .../linux/base_file_utilities_linux.cpp | 18 +++++++++++------- .../linux/base_network_reachability_linux.cpp | 6 ++++++ base/platform/linux/base_url_scheme_linux.cpp | 18 ++++++++++++++---- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c0c200b..6b488994 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,7 @@ if (DESKTOP_APP_DISABLE_DBUS_INTEGRATION) remove_target_sources(lib_base ${src_loc} base/platform/linux/base_linux_dbus_utilities.cpp base/platform/linux/base_linux_dbus_utilities.h + base/platform/linux/base_linux_glibmm_helper.h base/platform/linux/base_linux_xdp_utilities.cpp base/platform/linux/base_linux_xdp_utilities.h base/platform/linux/base_system_media_controls_linux.cpp @@ -224,11 +225,13 @@ PUBLIC if (WIN32) nuget_add_winrt(lib_base) elseif (LINUX) - target_link_libraries(lib_base - PUBLIC - desktop-app::external_glibmm - desktop-app::external_glib - ) + if (NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) + target_link_libraries(lib_base + PUBLIC + desktop-app::external_glibmm + desktop-app::external_glib + ) + endif() if (NOT DESKTOP_APP_DISABLE_X11_INTEGRATION) target_link_libraries(lib_base diff --git a/base/platform/linux/base_file_utilities_linux.cpp b/base/platform/linux/base_file_utilities_linux.cpp index 6bb82ec9..d843163f 100644 --- a/base/platform/linux/base_file_utilities_linux.cpp +++ b/base/platform/linux/base_file_utilities_linux.cpp @@ -15,8 +15,10 @@ #include #include +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #include #include +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #include #include @@ -92,7 +94,6 @@ bool DBusShowInFolder(const QString &filepath) { return false; } -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION bool ProcessShowInFolder(const QString &filepath) { const auto fileManager = [] { @@ -137,6 +138,7 @@ bool ProcessShowInFolder(const QString &filepath) { return false; } +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } // namespace @@ -149,27 +151,29 @@ bool ShowInFolder(const QString &filepath) { if (PortalShowInFolder(filepath)) { return true; } -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION if (ProcessShowInFolder(filepath)) { return true; } - const auto folder = QFileInfo(filepath).absolutePath(); try { if (Gio::AppInfo::launch_default_for_uri( - Glib::filename_to_uri(folder.toStdString()))) { + Glib::filename_to_uri( + Glib::path_get_dirname(filepath.toStdString())))) { return true; } } catch (...) { } +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION + + const auto folder = QUrl::fromLocalFile( + QFileInfo(filepath).absolutePath()); - const auto qUrlFolder = QUrl::fromLocalFile(folder); - if (QDesktopServices::openUrl(qUrlFolder)) { + if (QDesktopServices::openUrl(folder)) { return true; } - if (QProcess::startDetached("xdg-open", { qUrlFolder.toEncoded() })) { + if (QProcess::startDetached("xdg-open", { folder.toEncoded() })) { return true; } diff --git a/base/platform/linux/base_network_reachability_linux.cpp b/base/platform/linux/base_network_reachability_linux.cpp index b5e322b5..3d7c785f 100644 --- a/base/platform/linux/base_network_reachability_linux.cpp +++ b/base/platform/linux/base_network_reachability_linux.cpp @@ -6,12 +6,15 @@ // #include "base/platform/linux/base_network_reachability_linux.h" +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #include +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION namespace base::Platform { // glib is better on linux due to portal support std::optional NetworkAvailable() { +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION // crashes on 2.46.0...2.60.0, but not on >=2.56.3, >=2.58.1 (fix backported) if ((!glib_check_version(2, 56, 0) && glib_check_version(2, 56, 3)) || (!glib_check_version(2, 58, 0) && glib_check_version(2, 58, 1)) @@ -33,6 +36,9 @@ std::optional NetworkAvailable() { return g_network_monitor_get_network_available( g_network_monitor_get_default()); +#else // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION + return std::nullopt; +#endif // DESKTOP_APP_DISABLE_DBUS_INTEGRATION } } // namespace base::Platform diff --git a/base/platform/linux/base_url_scheme_linux.cpp b/base/platform/linux/base_url_scheme_linux.cpp index 4c3971ae..20aed5ea 100644 --- a/base/platform/linux/base_url_scheme_linux.cpp +++ b/base/platform/linux/base_url_scheme_linux.cpp @@ -6,22 +6,29 @@ // #include "base/platform/linux/base_url_scheme_linux.h" -#include "base/platform/linux/base_linux_glibmm_helper.h" #include "base/const_string.h" #include "base/debug_log.h" +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION +#include "base/platform/linux/base_linux_glibmm_helper.h" +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION + #include #include #include #include + +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #include #include #include +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION namespace base::Platform { namespace { +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION constexpr auto kSnapcraftSettingsService = "io.snapcraft.Settings"_cs; constexpr auto kSnapcraftSettingsObjectPath = "/io/snapcraft/Settings"_cs; constexpr auto kSnapcraftSettingsInterface = kSnapcraftSettingsService; @@ -52,7 +59,6 @@ constexpr auto kSnapcraftSettingsInterface = kSnapcraftSettingsService; return result; } -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION void SnapDefaultHandler(const QString &protocol) { try { const auto connection = Gio::DBus::Connection::get_sync( @@ -118,6 +124,7 @@ void SnapDefaultHandler(const QString &protocol) { } // namespace bool CheckUrlScheme(const UrlSchemeDescriptor &descriptor) { +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION try { const auto handlerType = QString("x-scheme-handler/%1") .arg(descriptor.protocol); @@ -144,18 +151,18 @@ bool CheckUrlScheme(const UrlSchemeDescriptor &descriptor) { } } catch (...) { } +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION return false; } void RegisterUrlScheme(const UrlSchemeDescriptor &descriptor) { - try { #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION + try { if (qEnvironmentVariableIsSet("SNAP")) { SnapDefaultHandler(descriptor.protocol); return; } -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION if (CheckUrlScheme(descriptor)) { return; @@ -186,9 +193,11 @@ void RegisterUrlScheme(const UrlSchemeDescriptor &descriptor) { } catch (const Glib::Error &e) { LOG(("Register Url Scheme Error: %1").arg(QString::fromStdString(e.what()))); } +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } void UnregisterUrlScheme(const UrlSchemeDescriptor &descriptor) { +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION const auto handlerType = QString("x-scheme-handler/%1") .arg(descriptor.protocol); @@ -224,6 +233,7 @@ void UnregisterUrlScheme(const UrlSchemeDescriptor &descriptor) { if (registeredAppInfoList) { g_list_free_full(registeredAppInfoList, g_object_unref); } +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } } // namespace base::Platform