Skip to content

Commit

Permalink
Resubscribe to signal when running with old xdg-desktop-portal
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed May 7, 2021
1 parent f1a9884 commit 95b4435
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,35 +408,37 @@ void XDPFileDialog::openPortal() {
+ uniqueName
+ '/'
+ handleToken;

const auto responseCallback = crl::guard(this, [=](
const Glib::RefPtr<Gio::DBus::Connection> &connection,
const Glib::ustring &sender_name,
const Glib::ustring &object_path,
const Glib::ustring &interface_name,
const Glib::ustring &signal_name,
const Glib::VariantContainerBase &parameters) {
try {
auto parametersCopy = parameters;

_requestSignalId = _dbusConnection->signal_subscribe(
crl::guard(this, [=](
const Glib::RefPtr<Gio::DBus::Connection> &connection,
const Glib::ustring &sender_name,
const Glib::ustring &object_path,
const Glib::ustring &interface_name,
const Glib::ustring &signal_name,
const Glib::VariantContainerBase &parameters) {
try {
auto parametersCopy = parameters;
const auto response = base::Platform::GlibVariantCast<uint>(
parametersCopy.get_child(0));

const auto response = base::Platform::GlibVariantCast<uint>(
parametersCopy.get_child(0));
const auto results = base::Platform::GlibVariantCast<
std::map<
Glib::ustring,
Glib::VariantBase
>>(parametersCopy.get_child(1));

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())));

gotResponse(response, results);
} catch (const std::exception &e) {
LOG(("XDP File Dialog Error: %1").arg(
QString::fromStdString(e.what())));
_reject.fire({});
}
});

_reject.fire({});
}
}),
_requestSignalId = _dbusConnection->signal_subscribe(
responseCallback,
{},
"org.freedesktop.portal.Request",
"Response",
Expand All @@ -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 = {
Expand Down

0 comments on commit 95b4435

Please sign in to comment.