2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

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

@@ -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);
}
}