mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-13 00:46:26 +00:00
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:
parent
7cd19cc0e0
commit
1bee396e03
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user