mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Destroy NotificationData signal connections with rpl::lifetme
This commit is contained in:
parent
4df90cfb9e
commit
d5d1254393
1 changed files with 22 additions and 31 deletions
|
@ -156,8 +156,6 @@ public:
|
||||||
NotificationData(NotificationData &&other) = delete;
|
NotificationData(NotificationData &&other) = delete;
|
||||||
NotificationData &operator=(NotificationData &&other) = delete;
|
NotificationData &operator=(NotificationData &&other) = delete;
|
||||||
|
|
||||||
~NotificationData();
|
|
||||||
|
|
||||||
void show();
|
void show();
|
||||||
void close();
|
void close();
|
||||||
void setImage(QImage image);
|
void setImage(QImage image);
|
||||||
|
@ -181,10 +179,7 @@ private:
|
||||||
std::string _imageKey;
|
std::string _imageKey;
|
||||||
|
|
||||||
uint _notificationId = 0;
|
uint _notificationId = 0;
|
||||||
ulong _actionInvokedSignalId = 0;
|
rpl::lifetime _lifetime;
|
||||||
ulong _activationTokenSignalId = 0;
|
|
||||||
ulong _notificationRepliedSignalId = 0;
|
|
||||||
ulong _notificationClosedSignalId = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -315,7 +310,7 @@ bool NotificationData::init(const Info &info) {
|
||||||
_actions.push_back(
|
_actions.push_back(
|
||||||
tr::lng_notification_reply(tr::now).toStdString());
|
tr::lng_notification_reply(tr::now).toStdString());
|
||||||
|
|
||||||
_notificationRepliedSignalId
|
const auto notificationRepliedSignalId
|
||||||
= _interface.signal_notification_replied().connect([=](
|
= _interface.signal_notification_replied().connect([=](
|
||||||
XdgNotifications::Notifications,
|
XdgNotifications::Notifications,
|
||||||
uint id,
|
uint id,
|
||||||
|
@ -328,10 +323,14 @@ bool NotificationData::init(const Info &info) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_lifetime.add([=] {
|
||||||
|
_interface.disconnect(notificationRepliedSignalId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_actionInvokedSignalId = _interface.signal_action_invoked().connect(
|
const auto actionInvokedSignalId
|
||||||
[=](
|
= _interface.signal_action_invoked().connect([=](
|
||||||
XdgNotifications::Notifications,
|
XdgNotifications::Notifications,
|
||||||
uint id,
|
uint id,
|
||||||
std::string actionName) {
|
std::string actionName) {
|
||||||
|
@ -346,7 +345,11 @@ bool NotificationData::init(const Info &info) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
_activationTokenSignalId
|
_lifetime.add([=] {
|
||||||
|
_interface.disconnect(actionInvokedSignalId);
|
||||||
|
});
|
||||||
|
|
||||||
|
const auto activationTokenSignalId
|
||||||
= _interface.signal_activation_token().connect([=](
|
= _interface.signal_activation_token().connect([=](
|
||||||
XdgNotifications::Notifications,
|
XdgNotifications::Notifications,
|
||||||
uint id,
|
uint id,
|
||||||
|
@ -355,6 +358,10 @@ bool NotificationData::init(const Info &info) {
|
||||||
GLib::setenv("XDG_ACTIVATION_TOKEN", token, true);
|
GLib::setenv("XDG_ACTIVATION_TOKEN", token, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_lifetime.add([=] {
|
||||||
|
_interface.disconnect(activationTokenSignalId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasCapability("action-icons")) {
|
if (HasCapability("action-icons")) {
|
||||||
|
@ -392,7 +399,7 @@ bool NotificationData::init(const Info &info) {
|
||||||
_hints.insert_value("desktop-entry", GLib::Variant::new_string(
|
_hints.insert_value("desktop-entry", GLib::Variant::new_string(
|
||||||
QGuiApplication::desktopFileName().toStdString()));
|
QGuiApplication::desktopFileName().toStdString()));
|
||||||
|
|
||||||
_notificationClosedSignalId =
|
const auto notificationClosedSignalId =
|
||||||
_interface.signal_notification_closed().connect([=](
|
_interface.signal_notification_closed().connect([=](
|
||||||
XdgNotifications::Notifications,
|
XdgNotifications::Notifications,
|
||||||
uint id,
|
uint id,
|
||||||
|
@ -418,29 +425,13 @@ bool NotificationData::init(const Info &info) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_lifetime.add([=] {
|
||||||
|
_interface.disconnect(notificationClosedSignalId);
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationData::~NotificationData() {
|
|
||||||
if (_interface) {
|
|
||||||
if (_actionInvokedSignalId != 0) {
|
|
||||||
_interface.disconnect(_actionInvokedSignalId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_activationTokenSignalId != 0) {
|
|
||||||
_interface.disconnect(_activationTokenSignalId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_notificationRepliedSignalId != 0) {
|
|
||||||
_interface.disconnect(_notificationRepliedSignalId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_notificationClosedSignalId != 0) {
|
|
||||||
_interface.disconnect(_notificationClosedSignalId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationData::show() {
|
void NotificationData::show() {
|
||||||
if (_application && _notification) {
|
if (_application && _notification) {
|
||||||
_application.send_notification(_guid, _notification);
|
_application.send_notification(_guid, _notification);
|
||||||
|
|
Loading…
Add table
Reference in a new issue