mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Don't use crl::on_main unnecessarily in Linux native notifications code
All those dbus methods call callbacks on the same thread
This commit is contained in:
parent
55fb3405e5
commit
bf255c0e00
1 changed files with 127 additions and 128 deletions
|
@ -91,15 +91,12 @@ std::unique_ptr<base::Platform::DBus::ServiceWatcher> CreateServiceWatcher() {
|
||||||
const Glib::ustring &service,
|
const Glib::ustring &service,
|
||||||
const Glib::ustring &oldOwner,
|
const Glib::ustring &oldOwner,
|
||||||
const Glib::ustring &newOwner) {
|
const Glib::ustring &newOwner) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
if (activatable && newOwner.empty()) {
|
if (activatable && newOwner.empty()) {
|
||||||
crl::on_main([] {
|
|
||||||
Core::App().notifications().clearAll();
|
Core::App().notifications().clearAll();
|
||||||
});
|
} else {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
crl::on_main([] {
|
|
||||||
Core::App().notifications().createManager();
|
Core::App().notifications().createManager();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
@ -117,6 +114,7 @@ void StartServiceAsync(Fn<void()> callback) {
|
||||||
connection,
|
connection,
|
||||||
kService,
|
kService,
|
||||||
[=](Fn<base::Platform::DBus::StartReply()> result) {
|
[=](Fn<base::Platform::DBus::StartReply()> result) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
Noexcept([&] {
|
Noexcept([&] {
|
||||||
try {
|
try {
|
||||||
result(); // get the error if any
|
result(); // get the error if any
|
||||||
|
@ -136,14 +134,15 @@ void StartServiceAsync(Fn<void()> callback) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
crl::on_main(callback);
|
callback();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
crl::on_main(callback);
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetServiceRegistered() {
|
bool GetServiceRegistered() {
|
||||||
|
@ -191,6 +190,7 @@ void GetServerInformation(
|
||||||
"GetServerInformation",
|
"GetServerInformation",
|
||||||
{},
|
{},
|
||||||
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
|
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
Noexcept([&] {
|
Noexcept([&] {
|
||||||
const auto reply = connection->call_finish(result);
|
const auto reply = connection->call_finish(result);
|
||||||
|
|
||||||
|
@ -210,7 +210,6 @@ void GetServerInformation(
|
||||||
3
|
3
|
||||||
).get_dynamic<Glib::ustring>();
|
).get_dynamic<Glib::ustring>();
|
||||||
|
|
||||||
crl::on_main([=] {
|
|
||||||
callback(ServerInformation{
|
callback(ServerInformation{
|
||||||
QString::fromStdString(name),
|
QString::fromStdString(name),
|
||||||
QString::fromStdString(vendor),
|
QString::fromStdString(vendor),
|
||||||
|
@ -219,14 +218,14 @@ void GetServerInformation(
|
||||||
QVersionNumber::fromString(
|
QVersionNumber::fromString(
|
||||||
QString::fromStdString(specVersion)),
|
QString::fromStdString(specVersion)),
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}, [&] {
|
}, [&] {
|
||||||
crl::on_main([=] { callback(std::nullopt); });
|
callback(std::nullopt);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
kService);
|
kService);
|
||||||
}, [&] {
|
}, [&] {
|
||||||
crl::on_main([=] { callback(std::nullopt); });
|
callback(std::nullopt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +240,7 @@ void GetCapabilities(Fn<void(const QStringList &)> callback) {
|
||||||
"GetCapabilities",
|
"GetCapabilities",
|
||||||
{},
|
{},
|
||||||
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
|
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
Noexcept([&] {
|
Noexcept([&] {
|
||||||
QStringList value;
|
QStringList value;
|
||||||
ranges::transform(
|
ranges::transform(
|
||||||
|
@ -252,14 +252,15 @@ void GetCapabilities(Fn<void(const QStringList &)> callback) {
|
||||||
ranges::back_inserter(value),
|
ranges::back_inserter(value),
|
||||||
QString::fromStdString);
|
QString::fromStdString);
|
||||||
|
|
||||||
crl::on_main([=] { callback(value); });
|
callback(value);
|
||||||
}, [&] {
|
}, [&] {
|
||||||
crl::on_main([=] { callback({}); });
|
callback({});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
kService);
|
kService);
|
||||||
}, [&] {
|
}, [&] {
|
||||||
crl::on_main([=] { callback({}); });
|
callback({});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,6 +278,7 @@ void GetInhibited(Fn<void(bool)> callback) {
|
||||||
Glib::ustring("Inhibited"),
|
Glib::ustring("Inhibited"),
|
||||||
}),
|
}),
|
||||||
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
|
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
Noexcept([&] {
|
Noexcept([&] {
|
||||||
const auto value = connection->call_finish(
|
const auto value = connection->call_finish(
|
||||||
result
|
result
|
||||||
|
@ -285,14 +287,15 @@ void GetInhibited(Fn<void(bool)> callback) {
|
||||||
).get_dynamic<Glib::Variant<bool>>(
|
).get_dynamic<Glib::Variant<bool>>(
|
||||||
).get();
|
).get();
|
||||||
|
|
||||||
crl::on_main([=] { callback(value); });
|
callback(value);
|
||||||
}, [&] {
|
}, [&] {
|
||||||
crl::on_main([=] { callback(false); });
|
callback(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
kService);
|
kService);
|
||||||
}, [&] {
|
}, [&] {
|
||||||
crl::on_main([=] { callback(false); });
|
callback(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,13 +468,14 @@ bool NotificationData::init(
|
||||||
const auto weak = base::make_weak(this);
|
const auto weak = base::make_weak(this);
|
||||||
const auto capabilities = CurrentCapabilities;
|
const auto capabilities = CurrentCapabilities;
|
||||||
|
|
||||||
const auto signalEmitted = [=](
|
const auto signalEmitted = crl::guard(weak, [=](
|
||||||
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||||
const Glib::ustring &sender_name,
|
const Glib::ustring &sender_name,
|
||||||
const Glib::ustring &object_path,
|
const Glib::ustring &object_path,
|
||||||
const Glib::ustring &interface_name,
|
const Glib::ustring &interface_name,
|
||||||
const Glib::ustring &signal_name,
|
const Glib::ustring &signal_name,
|
||||||
const Glib::VariantContainerBase ¶meters) {
|
const Glib::VariantContainerBase ¶meters) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
Noexcept([&] {
|
Noexcept([&] {
|
||||||
if (signal_name == "ActionInvoked") {
|
if (signal_name == "ActionInvoked") {
|
||||||
const auto id = parameters.get_child(0).get_dynamic<uint>();
|
const auto id = parameters.get_child(0).get_dynamic<uint>();
|
||||||
|
@ -480,7 +484,7 @@ bool NotificationData::init(
|
||||||
1
|
1
|
||||||
).get_dynamic<Glib::ustring>();
|
).get_dynamic<Glib::ustring>();
|
||||||
|
|
||||||
crl::on_main(weak, [=] { actionInvoked(id, actionName); });
|
actionInvoked(id, actionName);
|
||||||
} else if (signal_name == "ActivationToken") {
|
} else if (signal_name == "ActivationToken") {
|
||||||
const auto id = parameters.get_child(0).get_dynamic<uint>();
|
const auto id = parameters.get_child(0).get_dynamic<uint>();
|
||||||
|
|
||||||
|
@ -488,7 +492,7 @@ bool NotificationData::init(
|
||||||
1
|
1
|
||||||
).get_dynamic<Glib::ustring>();
|
).get_dynamic<Glib::ustring>();
|
||||||
|
|
||||||
crl::on_main(weak, [=] { activationToken(id, token); });
|
activationToken(id, token);
|
||||||
} else if (signal_name == "NotificationReplied") {
|
} else if (signal_name == "NotificationReplied") {
|
||||||
const auto id = parameters.get_child(0).get_dynamic<uint>();
|
const auto id = parameters.get_child(0).get_dynamic<uint>();
|
||||||
|
|
||||||
|
@ -496,7 +500,7 @@ bool NotificationData::init(
|
||||||
1
|
1
|
||||||
).get_dynamic<Glib::ustring>();
|
).get_dynamic<Glib::ustring>();
|
||||||
|
|
||||||
crl::on_main(weak, [=] { notificationReplied(id, text); });
|
notificationReplied(id, text);
|
||||||
} else if (signal_name == "NotificationClosed") {
|
} else if (signal_name == "NotificationClosed") {
|
||||||
const auto id = parameters.get_child(0).get_dynamic<uint>();
|
const auto id = parameters.get_child(0).get_dynamic<uint>();
|
||||||
|
|
||||||
|
@ -504,10 +508,11 @@ bool NotificationData::init(
|
||||||
1
|
1
|
||||||
).get_dynamic<uint>();
|
).get_dynamic<uint>();
|
||||||
|
|
||||||
crl::on_main(weak, [=] { notificationClosed(id, reason); });
|
notificationClosed(id, reason);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
});
|
||||||
|
|
||||||
_imageKey = GetImageKey(CurrentServerInformationValue().specVersion);
|
_imageKey = GetImageKey(CurrentServerInformationValue().specVersion);
|
||||||
|
|
||||||
|
@ -652,23 +657,19 @@ void NotificationData::show() {
|
||||||
_hints,
|
_hints,
|
||||||
-1,
|
-1,
|
||||||
}),
|
}),
|
||||||
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
|
crl::guard(weak, [=](const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
Noexcept([&] {
|
Noexcept([&] {
|
||||||
const auto notificationId = connection->call_finish(
|
_notificationId = connection->call_finish(
|
||||||
result
|
result
|
||||||
).get_child(
|
).get_child(
|
||||||
0
|
0
|
||||||
).get_dynamic<uint>();
|
).get_dynamic<uint>();
|
||||||
|
|
||||||
crl::on_main(weak, [=] {
|
|
||||||
_notificationId = notificationId;
|
|
||||||
});
|
|
||||||
}, [&] {
|
}, [&] {
|
||||||
crl::on_main(weak, [=] {
|
|
||||||
_manager->clearNotification(_id);
|
_manager->clearNotification(_id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
kService);
|
kService);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -966,13 +967,14 @@ Manager::Private::Private(not_null<Manager*> manager)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
_inhibitedSignalId = _dbusConnection->signal_subscribe(
|
_inhibitedSignalId = _dbusConnection->signal_subscribe(
|
||||||
[=](
|
crl::guard(weak, [=](
|
||||||
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||||
const Glib::ustring &sender_name,
|
const Glib::ustring &sender_name,
|
||||||
const Glib::ustring &object_path,
|
const Glib::ustring &object_path,
|
||||||
const Glib::ustring &interface_name,
|
const Glib::ustring &interface_name,
|
||||||
const Glib::ustring &signal_name,
|
const Glib::ustring &signal_name,
|
||||||
const Glib::VariantContainerBase ¶meters) {
|
const Glib::VariantContainerBase ¶meters) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
Noexcept([&] {
|
Noexcept([&] {
|
||||||
const auto interface = parameters.get_child(
|
const auto interface = parameters.get_child(
|
||||||
0
|
0
|
||||||
|
@ -982,18 +984,15 @@ Manager::Private::Private(not_null<Manager*> manager)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto inhibited = parameters.get_child(
|
_inhibited = parameters.get_child(
|
||||||
1
|
1
|
||||||
).get_dynamic<std::map<Glib::ustring, Glib::VariantBase>>(
|
).get_dynamic<std::map<Glib::ustring, Glib::VariantBase>>(
|
||||||
).at(
|
).at(
|
||||||
"Inhibited"
|
"Inhibited"
|
||||||
).get_dynamic<bool>();
|
).get_dynamic<bool>();
|
||||||
|
|
||||||
crl::on_main(weak, [=] {
|
|
||||||
_inhibited = inhibited;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
kService,
|
kService,
|
||||||
kPropertiesInterface,
|
kPropertiesInterface,
|
||||||
"PropertiesChanged",
|
"PropertiesChanged",
|
||||||
|
|
Loading…
Add table
Reference in a new issue