mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +02:00
Move native notifications option check logic to cross platform code
This commit is contained in:
parent
df377cd5bb
commit
e1f71baed6
5 changed files with 34 additions and 32 deletions
|
@ -640,22 +640,11 @@ void Create(Window::Notifications::System *system) {
|
|||
|
||||
const auto managerSetter = [=](
|
||||
XdgNotifications::NotificationsProxy proxy) {
|
||||
using ManagerType = Window::Notifications::ManagerType;
|
||||
if ((Core::App().settings().nativeNotifications() || Enforced())
|
||||
&& Supported()) {
|
||||
if (system->manager().type() != ManagerType::Native) {
|
||||
auto manager = std::make_unique<Manager>(system);
|
||||
manager->_private->init(proxy);
|
||||
system->setManager(std::move(manager));
|
||||
}
|
||||
} else if (Enforced()) {
|
||||
if (system->manager().type() != ManagerType::Dummy) {
|
||||
using DummyManager = Window::Notifications::DummyManager;
|
||||
system->setManager(std::make_unique<DummyManager>(system));
|
||||
}
|
||||
} else if (system->manager().type() != ManagerType::Default) {
|
||||
system->setManager(nullptr);
|
||||
}
|
||||
system->setManager([=] {
|
||||
auto manager = std::make_unique<Manager>(system);
|
||||
manager->_private->init(proxy);
|
||||
return manager;
|
||||
});
|
||||
};
|
||||
|
||||
const auto counter = std::make_shared<int>(2);
|
||||
|
|
|
@ -197,11 +197,7 @@ bool ByDefault() {
|
|||
}
|
||||
|
||||
void Create(Window::Notifications::System *system) {
|
||||
if (Supported()) {
|
||||
system->setManager(std::make_unique<Manager>(system));
|
||||
} else {
|
||||
system->setManager(nullptr);
|
||||
}
|
||||
system->setManager([=] { return std::make_unique<Manager>(system); });
|
||||
}
|
||||
|
||||
class Manager::Private : public QObject {
|
||||
|
|
|
@ -416,14 +416,10 @@ bool ByDefault() {
|
|||
}
|
||||
|
||||
void Create(Window::Notifications::System *system) {
|
||||
if (Core::App().settings().nativeNotifications() && Supported()) {
|
||||
system->setManager([=] {
|
||||
auto result = std::make_unique<Manager>(system);
|
||||
if (result->init()) {
|
||||
system->setManager(std::move(result));
|
||||
return;
|
||||
}
|
||||
}
|
||||
system->setManager(nullptr);
|
||||
return result->init() ? std::move(result) : nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
class Manager::Private {
|
||||
|
|
|
@ -184,9 +184,30 @@ void System::createManager() {
|
|||
Platform::Notifications::Create(this);
|
||||
}
|
||||
|
||||
void System::setManager(std::unique_ptr<Manager> manager) {
|
||||
_manager = std::move(manager);
|
||||
if (!_manager) {
|
||||
void System::setManager(Fn<std::unique_ptr<Manager>()> create) {
|
||||
Expects(_manager != nullptr);
|
||||
const auto guard = gsl::finally([&] {
|
||||
Ensures(_manager != nullptr);
|
||||
});
|
||||
|
||||
if ((Core::App().settings().nativeNotifications()
|
||||
|| Platform::Notifications::Enforced())
|
||||
&& Platform::Notifications::Supported()) {
|
||||
if (_manager->type() == ManagerType::Native) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto manager = create()) {
|
||||
_manager = std::move(manager);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Platform::Notifications::Enforced()) {
|
||||
if (_manager->type() != ManagerType::Dummy) {
|
||||
_manager = std::make_unique<DummyManager>(this);
|
||||
}
|
||||
} else if (_manager->type() != ManagerType::Default) {
|
||||
_manager = std::make_unique<Default::Manager>(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public:
|
|||
[[nodiscard]] Main::Session *findSession(uint64 sessionId) const;
|
||||
|
||||
void createManager();
|
||||
void setManager(std::unique_ptr<Manager> manager);
|
||||
void setManager(Fn<std::unique_ptr<Manager>()> create);
|
||||
[[nodiscard]] Manager &manager() const;
|
||||
|
||||
void checkDelayed();
|
||||
|
|
Loading…
Add table
Reference in a new issue