Ensure notification manager is not null before first call to setManager in cross-platform code
This commit is contained in:
		
							parent
							
								
									6718d238af
								
							
						
					
					
						commit
						9b8dcec26e
					
				
					 3 changed files with 12 additions and 25 deletions
				
			
		|  | @ -745,18 +745,15 @@ void Create(Window::Notifications::System *system) { | |||
| 		using ManagerType = Window::Notifications::ManagerType; | ||||
| 		if ((Core::App().settings().nativeNotifications() || Enforced()) | ||||
| 			&& Supported()) { | ||||
| 			if (!system->managerType().has_value() | ||||
| 				|| *system->managerType() != ManagerType::Native) { | ||||
| 			if (system->managerType() != ManagerType::Native) { | ||||
| 				system->setManager(std::make_unique<Manager>(system)); | ||||
| 			} | ||||
| 		} else if (Enforced()) { | ||||
| 			if (!system->managerType().has_value() | ||||
| 				|| *system->managerType() != ManagerType::Dummy) { | ||||
| 			if (system->managerType() != ManagerType::Dummy) { | ||||
| 				using DummyManager = Window::Notifications::DummyManager; | ||||
| 				system->setManager(std::make_unique<DummyManager>(system)); | ||||
| 			} | ||||
| 		} else if (!system->managerType().has_value() | ||||
| 			|| *system->managerType() != ManagerType::Default) { | ||||
| 		} else if (system->managerType() != ManagerType::Default) { | ||||
| 			system->setManager(nullptr); | ||||
| 		} | ||||
| 	}; | ||||
|  | @ -768,7 +765,8 @@ void Create(Window::Notifications::System *system) { | |||
| 		} | ||||
| 	}; | ||||
| 
 | ||||
| 	const auto serviceActivated = [=] { | ||||
| 	// snap doesn't allow access when the daemon is not running :(
 | ||||
| 	StartServiceAsync([=] { | ||||
| 		ServiceRegistered = GetServiceRegistered(); | ||||
| 
 | ||||
| 		if (!ServiceRegistered) { | ||||
|  | @ -787,17 +785,7 @@ void Create(Window::Notifications::System *system) { | |||
| 			CurrentCapabilities = result; | ||||
| 			oneReady(); | ||||
| 		}); | ||||
| 	}; | ||||
| 
 | ||||
| 	// There are some asserts that manager is not nullptr,
 | ||||
| 	// avoid crashes until some real manager is created
 | ||||
| 	if (!system->managerType().has_value()) { | ||||
| 		using DummyManager = Window::Notifications::DummyManager; | ||||
| 		system->setManager(std::make_unique<DummyManager>(system)); | ||||
| 	} | ||||
| 
 | ||||
| 	// snap doesn't allow access when the daemon is not running :(
 | ||||
| 	StartServiceAsync(serviceActivated); | ||||
| 	}); | ||||
| } | ||||
| 
 | ||||
| class Manager::Private { | ||||
|  |  | |||
|  | @ -91,7 +91,8 @@ System::NotificationInHistoryKey::NotificationInHistoryKey( | |||
| 
 | ||||
| System::System() | ||||
| : _waitTimer([=] { showNext(); }) | ||||
| , _waitForAllGroupedTimer([=] { showGrouped(); }) { | ||||
| , _waitForAllGroupedTimer([=] { showGrouped(); }) | ||||
| , _manager(std::make_unique<DummyManager>(this)) { | ||||
| 	settingsChanged( | ||||
| 	) | rpl::start_with_next([=](ChangeType type) { | ||||
| 		if (type == ChangeType::DesktopEnabled) { | ||||
|  | @ -116,12 +117,10 @@ void System::setManager(std::unique_ptr<Manager> manager) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| std::optional<ManagerType> System::managerType() const { | ||||
| 	if (_manager) { | ||||
| ManagerType System::managerType() const { | ||||
| 	Expects(_manager != nullptr); | ||||
| 	return _manager->type(); | ||||
| } | ||||
| 	return std::nullopt; | ||||
| } | ||||
| 
 | ||||
| Main::Session *System::findSession(uint64 sessionId) const { | ||||
| 	for (const auto &[index, account] : Core::App().domain().accounts()) { | ||||
|  |  | |||
|  | @ -85,7 +85,7 @@ public: | |||
| 
 | ||||
| 	void createManager(); | ||||
| 	void setManager(std::unique_ptr<Manager> manager); | ||||
| 	[[nodiscard]] std::optional<ManagerType> managerType() const; | ||||
| 	[[nodiscard]] ManagerType managerType() const; | ||||
| 
 | ||||
| 	void checkDelayed(); | ||||
| 	void schedule(ItemNotification notification); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Ilya Fedin
						Ilya Fedin