Move native notifications option check logic to cross platform code

This commit is contained in:
Ilya Fedin 2025-01-24 23:35:03 +04:00 committed by John Preston
parent df377cd5bb
commit e1f71baed6
5 changed files with 34 additions and 32 deletions

View file

@ -640,22 +640,11 @@ void Create(Window::Notifications::System *system) {
const auto managerSetter = [=]( const auto managerSetter = [=](
XdgNotifications::NotificationsProxy proxy) { XdgNotifications::NotificationsProxy proxy) {
using ManagerType = Window::Notifications::ManagerType; system->setManager([=] {
if ((Core::App().settings().nativeNotifications() || Enforced()) auto manager = std::make_unique<Manager>(system);
&& Supported()) { manager->_private->init(proxy);
if (system->manager().type() != ManagerType::Native) { return manager;
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);
}
}; };
const auto counter = std::make_shared<int>(2); const auto counter = std::make_shared<int>(2);

View file

@ -197,11 +197,7 @@ bool ByDefault() {
} }
void Create(Window::Notifications::System *system) { void Create(Window::Notifications::System *system) {
if (Supported()) { system->setManager([=] { return std::make_unique<Manager>(system); });
system->setManager(std::make_unique<Manager>(system));
} else {
system->setManager(nullptr);
}
} }
class Manager::Private : public QObject { class Manager::Private : public QObject {

View file

@ -416,14 +416,10 @@ bool ByDefault() {
} }
void Create(Window::Notifications::System *system) { void Create(Window::Notifications::System *system) {
if (Core::App().settings().nativeNotifications() && Supported()) { system->setManager([=] {
auto result = std::make_unique<Manager>(system); auto result = std::make_unique<Manager>(system);
if (result->init()) { return result->init() ? std::move(result) : nullptr;
system->setManager(std::move(result)); });
return;
}
}
system->setManager(nullptr);
} }
class Manager::Private { class Manager::Private {

View file

@ -184,9 +184,30 @@ void System::createManager() {
Platform::Notifications::Create(this); Platform::Notifications::Create(this);
} }
void System::setManager(std::unique_ptr<Manager> manager) { void System::setManager(Fn<std::unique_ptr<Manager>()> create) {
_manager = std::move(manager); Expects(_manager != nullptr);
if (!_manager) { 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); _manager = std::make_unique<Default::Manager>(this);
} }
} }

View file

@ -99,7 +99,7 @@ public:
[[nodiscard]] Main::Session *findSession(uint64 sessionId) const; [[nodiscard]] Main::Session *findSession(uint64 sessionId) const;
void createManager(); void createManager();
void setManager(std::unique_ptr<Manager> manager); void setManager(Fn<std::unique_ptr<Manager>()> create);
[[nodiscard]] Manager &manager() const; [[nodiscard]] Manager &manager() const;
void checkDelayed(); void checkDelayed();