From 67bf796f1e79cdf2ed00ec0ff24e1bc07a4b6b71 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 16 Nov 2025 00:38:47 +0000 Subject: [PATCH] Split scheme check code in Linux launch maps implementation --- .../platform/linux/specific_linux.cpp | 109 ++++++++++-------- 1 file changed, 64 insertions(+), 45 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index b8844e380d..cc9e032979 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -528,6 +528,55 @@ void InstallLauncher() { return base64.mid(0, kHashForSocketPathLength); } +void AppInfoCheckScheme( + const std::string &scheme, + Fn)> callback, + Fn fail) { + // TODO: use get_default_for_uri_scheme_async once we can use GLib 2.74 + if (auto appInfo = Gio::AppInfo::get_default_for_uri_scheme(scheme)) { + callback(appInfo, fail); + return; + } + fail(); +} + +void PortalCheckScheme( + const std::string &scheme, + Fn)> callback, + Fn fail) { + XdpOpenURI::OpenURIProxy::new_for_bus( + Gio::BusType::SESSION_, + Gio::DBusProxyFlags::NONE_, + base::Platform::XDP::kService, + base::Platform::XDP::kObjectPath, + [=](GObject::Object, Gio::AsyncResult res) { + auto interface = XdpOpenURI::OpenURI( + XdpOpenURI::OpenURIProxy::new_for_bus_finish(res, nullptr)); + + if (!interface) { + fail(); + return; + } + + interface.call_scheme_supported( + scheme, + GLib::Variant::new_array( + GLib::VariantType::new_("{sv}"), + {}), + [=](GObject::Object, Gio::AsyncResult res) mutable { + const auto result + = interface.call_scheme_supported_finish(res); + + if (!result || !std::get<1>(*result)) { + fail(); + return; + } + + callback(fail); + }); + }); +} + } // namespace namespace Platform { @@ -785,56 +834,26 @@ QString ApplicationIconName() { } void LaunchMaps(const Data::LocationPoint &point, Fn fail) { - if (auto appInfo = Gio::AppInfo::get_default_for_uri_scheme("geo")) { - if (appInfo.launch_uris( - { - std::format( - "geo:{},{}", - point.latAsString().toStdString(), - point.lonAsString().toStdString()), - }, + const auto url = QUrl( + u"geo:%1,%2"_q.arg(point.latAsString(), point.lonAsString())); + + AppInfoCheckScheme(url.scheme().toStdString(), [=]( + Gio::AppInfo appInfo, + Fn fail) { + // TODO: use launch_uris_async once we can use GLib 2.60 + if (!appInfo.launch_uris( + { url.toString().toStdString() }, base::Platform::AppLaunchContext(), nullptr)) { - return; + fail(); } - } - - XdpOpenURI::OpenURIProxy::new_for_bus( - Gio::BusType::SESSION_, - Gio::DBusProxyFlags::NONE_, - base::Platform::XDP::kService, - base::Platform::XDP::kObjectPath, - [=](GObject::Object, Gio::AsyncResult res) { - auto interface = XdpOpenURI::OpenURI( - XdpOpenURI::OpenURIProxy::new_for_bus_finish(res, nullptr)); - - if (!interface) { + }, [=] { + PortalCheckScheme(url.scheme().toStdString(), [=](Fn fail) { + if (!QDesktopServices::openUrl(url)) { fail(); - return; } - - interface.call_scheme_supported( - "geo", - GLib::Variant::new_array( - GLib::VariantType::new_("{sv}"), - {}), - [=](GObject::Object, Gio::AsyncResult res) mutable { - const auto result - = interface.call_scheme_supported_finish(res); - - if (!result || !std::get<1>(*result)) { - fail(); - return; - } - - if (!QDesktopServices::openUrl( - u"geo:%1,%2"_q.arg( - point.latAsString(), - point.lonAsString()))) { - fail(); - } - }); - }); + }, fail); + }); } namespace ThirdParty {