From 95b4435396c560e9bcfba8e56e167bb60913015b Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 6 May 2021 22:12:03 +0400 Subject: [PATCH] Resubscribe to signal when running with old xdg-desktop-portal --- .../platform/linux/linux_xdp_file_dialog.cpp | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp b/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp index dc65476e83..c9476a0c50 100644 --- a/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp @@ -408,35 +408,37 @@ void XDPFileDialog::openPortal() { + uniqueName + '/' + handleToken; + + const auto responseCallback = crl::guard(this, [=]( + const Glib::RefPtr &connection, + const Glib::ustring &sender_name, + const Glib::ustring &object_path, + const Glib::ustring &interface_name, + const Glib::ustring &signal_name, + const Glib::VariantContainerBase ¶meters) { + try { + auto parametersCopy = parameters; + + const auto response = base::Platform::GlibVariantCast( + parametersCopy.get_child(0)); + + const auto results = base::Platform::GlibVariantCast< + std::map< + Glib::ustring, + Glib::VariantBase + >>(parametersCopy.get_child(1)); + + gotResponse(response, results); + } catch (const std::exception &e) { + LOG(("XDP File Dialog Error: %1").arg( + QString::fromStdString(e.what()))); + + _reject.fire({}); + } + }); _requestSignalId = _dbusConnection->signal_subscribe( - crl::guard(this, [=]( - const Glib::RefPtr &connection, - const Glib::ustring &sender_name, - const Glib::ustring &object_path, - const Glib::ustring &interface_name, - const Glib::ustring &signal_name, - const Glib::VariantContainerBase ¶meters) { - try { - auto parametersCopy = parameters; - - const auto response = base::Platform::GlibVariantCast( - parametersCopy.get_child(0)); - - const auto results = base::Platform::GlibVariantCast< - std::map< - Glib::ustring, - Glib::VariantBase - >>(parametersCopy.get_child(1)); - - gotResponse(response, results); - } catch (const std::exception &e) { - LOG(("XDP File Dialog Error: %1").arg( - QString::fromStdString(e.what()))); - - _reject.fire({}); - } - }), + responseCallback, {}, "org.freedesktop.portal.Request", "Response", @@ -461,10 +463,15 @@ void XDPFileDialog::openPortal() { Glib::ustring>(reply.get_child(0)); if (handle != requestPath) { - crl::on_main([=] { - _failedToOpen = true; - _reject.fire({}); - }); + _dbusConnection->signal_unsubscribe( + _requestSignalId); + + _requestSignalId = _dbusConnection->signal_subscribe( + responseCallback, + {}, + "org.freedesktop.portal.Request", + "Response", + handle); } } catch (const Glib::Error &e) { static const auto NotSupportedErrors = {