only allow a limited number of notifications to be active at a time and queue the rest.

More than 100 outstatnding notifications crashed the windows backend,
this shouldn't happen to often but a crash isn't wat we ant too.
This commit is contained in:
Patrick von Reth 2015-07-29 16:12:30 +02:00
parent 7cd19cc0e0
commit 1bee396e03
3 changed files with 27 additions and 1 deletions

View File

@ -109,6 +109,12 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
void SnoreCore::broadcastNotification(Notification notification)
{
Q_D(SnoreCore);
if(d->m_activeNotifications.size() > d->maxNumberOfActiveNotifications())
{
snoreDebug(SNORE_DEBUG) << "queue size:" << d->m_notificationQue.size() << "active size:" << d->m_activeNotifications.size();
d->m_notificationQue.append(notification);
return;
}
Q_ASSERT_X(!notification.data()->isBroadcasted(), Q_FUNC_INFO, "Notification was already broadcasted.");
snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout();
if (d->m_notificationBackend != nullptr) {
@ -117,7 +123,11 @@ void SnoreCore::broadcastNotification(Notification notification)
}
}
notification.data()->setBroadcasted();
d->startNotificationTimeoutTimer(notification);
notification.addActiveIn(this);
if(!d->m_notificationBackend)
{
d->startNotificationTimeoutTimer(notification);
}
emit d->notify(notification);
}

View File

@ -75,6 +75,7 @@ void SnoreCorePrivate::slotNotificationActionInvoked(Notification notification)
void SnoreCorePrivate::slotNotificationDisplayed(Notification notification)
{
emit notificationDisplayed(notification);
startNotificationTimeoutTimer(notification);
}
bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
@ -225,6 +226,15 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n)
{
Q_Q(SnoreCore);
emit q->notificationClosed(n);
if(!n.removeActiveIn(q))
{
snoreDebug(SNORE_WARNING) << n << "was already closed";
}
if(!m_notificationQue.isEmpty() && m_activeNotifications.size() < maxNumberOfActiveNotifications())
{
snoreDebug(SNORE_DEBUG) << "Broadcast from queue" << m_notificationQue.size();
q->broadcastNotification(m_notificationQue.takeFirst());
}
}
void SnoreCorePrivate::slotAboutToQuit()

View File

@ -42,6 +42,11 @@ public:
*/
static QString tempPath();
static constexpr int maxNumberOfActiveNotifications()
{
return 3;
}
public:
static SnoreCorePrivate *instance();
~SnoreCorePrivate();
@ -108,6 +113,7 @@ private:
QSettings *m_settings;
QList<Notification> m_notificationQue;
QHash<uint, Snore::Notification> m_activeNotifications;
friend class Snore::Notification;