mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Port NotificationId conversion to cppgir
This commit is contained in:
parent
f2a54e3cbb
commit
59e53c1edf
3 changed files with 80 additions and 62 deletions
|
@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtCore/QAbstractEventDispatcher>
|
#include <QtCore/QAbstractEventDispatcher>
|
||||||
#include <qpa/qwindowsysteminterface.h>
|
#include <qpa/qwindowsysteminterface.h>
|
||||||
|
|
||||||
#include <glibmm.h>
|
|
||||||
#include <gio/gio.hpp>
|
#include <gio/gio.hpp>
|
||||||
#include <xdpinhibit/xdpinhibit.hpp>
|
#include <xdpinhibit/xdpinhibit.hpp>
|
||||||
|
|
||||||
|
@ -28,6 +27,32 @@ namespace {
|
||||||
|
|
||||||
using namespace gi::repository;
|
using namespace gi::repository;
|
||||||
|
|
||||||
|
std::vector<std::any> AnyVectorFromVariant(GLib::Variant value) {
|
||||||
|
std::vector<std::any> result;
|
||||||
|
|
||||||
|
auto iter = gi::wrap(
|
||||||
|
g_variant_iter_new(value.gobj_()),
|
||||||
|
gi::transfer_full);
|
||||||
|
|
||||||
|
const auto uint64Type = GLib::VariantType::new_("t");
|
||||||
|
const auto int64Type = GLib::VariantType::new_("x");
|
||||||
|
|
||||||
|
while (auto value = iter.next_value()) {
|
||||||
|
value = value.get_variant();
|
||||||
|
if (value.is_of_type(uint64Type)) {
|
||||||
|
result.push_back(std::make_any<uint64>(value.get_uint64()));
|
||||||
|
} else if (value.is_of_type(int64Type)) {
|
||||||
|
result.push_back(std::make_any<int64>(value.get_int64()));
|
||||||
|
} else if (value.is_container()) {
|
||||||
|
result.push_back(
|
||||||
|
std::make_any<std::vector<std::any>>(
|
||||||
|
AnyVectorFromVariant(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
class Application : public Gio::impl::ApplicationImpl {
|
class Application : public Gio::impl::ApplicationImpl {
|
||||||
public:
|
public:
|
||||||
Application();
|
Application();
|
||||||
|
@ -102,23 +127,8 @@ Application::Application()
|
||||||
|
|
||||||
using Window::Notifications::Manager;
|
using Window::Notifications::Manager;
|
||||||
using NotificationId = Manager::NotificationId;
|
using NotificationId = Manager::NotificationId;
|
||||||
using NotificationIdTuple = std::invoke_result_t<
|
|
||||||
decltype(&NotificationId::toTuple),
|
|
||||||
NotificationId*
|
|
||||||
>;
|
|
||||||
|
|
||||||
const auto notificationIdVariantType = [] {
|
const auto notificationIdVariantType = GLib::VariantType::new_("av");
|
||||||
try {
|
|
||||||
return gi::wrap(
|
|
||||||
Glib::create_variant(
|
|
||||||
NotificationId().toTuple()
|
|
||||||
).get_type().gobj_copy(),
|
|
||||||
gi::transfer_full
|
|
||||||
);
|
|
||||||
} catch (...) {
|
|
||||||
return GLib::VariantType();
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
|
|
||||||
auto notificationActivateAction = Gio::SimpleAction::new_(
|
auto notificationActivateAction = Gio::SimpleAction::new_(
|
||||||
"notification-activate",
|
"notification-activate",
|
||||||
|
@ -128,17 +138,9 @@ Application::Application()
|
||||||
Gio::SimpleAction,
|
Gio::SimpleAction,
|
||||||
GLib::Variant parameter) {
|
GLib::Variant parameter) {
|
||||||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
try {
|
Core::App().notifications().manager().notificationActivated(
|
||||||
const auto &app = Core::App();
|
NotificationId::FromAnyVector(
|
||||||
app.notifications().manager().notificationActivated(
|
AnyVectorFromVariant(parameter)));
|
||||||
NotificationId::FromTuple(
|
|
||||||
Glib::wrap(
|
|
||||||
parameter.gobj_copy_()
|
|
||||||
).get_dynamic<NotificationIdTuple>()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -152,18 +154,10 @@ Application::Application()
|
||||||
Gio::SimpleAction,
|
Gio::SimpleAction,
|
||||||
GLib::Variant parameter) {
|
GLib::Variant parameter) {
|
||||||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
try {
|
Core::App().notifications().manager().notificationReplied(
|
||||||
const auto &app = Core::App();
|
NotificationId::FromAnyVector(
|
||||||
app.notifications().manager().notificationReplied(
|
AnyVectorFromVariant(parameter)),
|
||||||
NotificationId::FromTuple(
|
{});
|
||||||
Glib::wrap(
|
|
||||||
parameter.gobj_copy_()
|
|
||||||
).get_dynamic<NotificationIdTuple>()
|
|
||||||
),
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtCore/QVersionNumber>
|
#include <QtCore/QVersionNumber>
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
|
|
||||||
#include <glibmm.h>
|
|
||||||
#include <xdgnotifications/xdgnotifications.hpp>
|
#include <xdgnotifications/xdgnotifications.hpp>
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
@ -139,6 +138,32 @@ bool UseGNotification() {
|
||||||
return KSandbox::isFlatpak() && !ServiceRegistered;
|
return KSandbox::isFlatpak() && !ServiceRegistered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLib::Variant AnyVectorToVariant(const std::vector<std::any> &value) {
|
||||||
|
return GLib::Variant::new_array(
|
||||||
|
value | ranges::views::transform([](const std::any &value) {
|
||||||
|
try {
|
||||||
|
return GLib::Variant::new_variant(
|
||||||
|
GLib::Variant::new_uint64(std::any_cast<uint64>(value)));
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return GLib::Variant::new_variant(
|
||||||
|
GLib::Variant::new_int64(std::any_cast<int64>(value)));
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return GLib::Variant::new_variant(
|
||||||
|
AnyVectorToVariant(
|
||||||
|
std::any_cast<std::vector<std::any>>(value)));
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return GLib::Variant(nullptr);
|
||||||
|
}) | ranges::to_vector);
|
||||||
|
}
|
||||||
|
|
||||||
class NotificationData final : public base::has_weak_ptr {
|
class NotificationData final : public base::has_weak_ptr {
|
||||||
public:
|
public:
|
||||||
using NotificationId = Window::Notifications::Manager::NotificationId;
|
using NotificationId = Window::Notifications::Manager::NotificationId;
|
||||||
|
@ -239,9 +264,7 @@ bool NotificationData::init(
|
||||||
set_category(_notification.gobj_(), "im.received");
|
set_category(_notification.gobj_(), "im.received");
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto idVariant = gi::wrap(
|
const auto idVariant = AnyVectorToVariant(_id.toAnyVector());
|
||||||
Glib::create_variant(_id.toTuple()).gobj_copy(),
|
|
||||||
gi::transfer_full);
|
|
||||||
|
|
||||||
_notification.set_default_action_and_target(
|
_notification.set_default_action_and_target(
|
||||||
"app.notification-activate",
|
"app.notification-activate",
|
||||||
|
|
|
@ -233,19 +233,19 @@ public:
|
||||||
const ContextId&,
|
const ContextId&,
|
||||||
const ContextId&) = default;
|
const ContextId&) = default;
|
||||||
|
|
||||||
[[nodiscard]] auto toTuple() const {
|
[[nodiscard]] auto toAnyVector() const {
|
||||||
return std::make_tuple(
|
return std::vector<std::any>{
|
||||||
sessionId,
|
std::make_any<uint64>(sessionId),
|
||||||
peerId.value,
|
std::make_any<uint64>(peerId.value),
|
||||||
topicRootId.bare);
|
std::make_any<int64>(topicRootId.bare),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
[[nodiscard]] static auto FromAnyVector(const auto &vector) {
|
||||||
[[nodiscard]] static auto FromTuple(const T &tuple) {
|
|
||||||
return ContextId{
|
return ContextId{
|
||||||
std::get<0>(tuple),
|
std::any_cast<uint64>(vector[0]),
|
||||||
PeerIdHelper(std::get<1>(tuple)),
|
PeerIdHelper(std::any_cast<uint64>(vector[1])),
|
||||||
std::get<2>(tuple),
|
std::any_cast<int64>(vector[2]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -257,17 +257,18 @@ public:
|
||||||
const NotificationId&,
|
const NotificationId&,
|
||||||
const NotificationId&) = default;
|
const NotificationId&) = default;
|
||||||
|
|
||||||
[[nodiscard]] auto toTuple() const {
|
[[nodiscard]] auto toAnyVector() const {
|
||||||
return std::make_tuple(
|
return std::vector<std::any>{
|
||||||
contextId.toTuple(),
|
std::make_any<std::vector<std::any>>(contextId.toAnyVector()),
|
||||||
msgId.bare);
|
std::make_any<int64>(msgId.bare),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
[[nodiscard]] static auto FromAnyVector(const auto &vector) {
|
||||||
[[nodiscard]] static auto FromTuple(const T &tuple) {
|
|
||||||
return NotificationId{
|
return NotificationId{
|
||||||
ContextId::FromTuple(std::get<0>(tuple)),
|
ContextId::FromAnyVector(
|
||||||
std::get<1>(tuple),
|
std::any_cast<std::vector<std::any>>(vector[0])),
|
||||||
|
std::any_cast<int64>(vector[1]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue