mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-13 00:46:26 +00:00
Try to improve the queing of snore backend notifications.
This commit is contained in:
parent
dd4f01baf2
commit
f5fbb6a7ed
@ -116,6 +116,7 @@ void SnoreCore::broadcastNotification(Notification notification)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
if (d->m_activeNotifications.size() > d->maxNumberOfActiveNotifications()) {
|
||||
#pragma message "TODO: handle updates in queue"
|
||||
snoreDebug(SNORE_DEBUG) << "queue size:" << d->m_notificationQue.size() << "active size:" << d->m_activeNotifications.size();
|
||||
d->m_notificationQue.append(notification);
|
||||
return;
|
||||
|
@ -11,19 +11,18 @@ Window {
|
||||
color: notifyWidget.color
|
||||
|
||||
|
||||
|
||||
onVisibleChanged: {
|
||||
if(visible){
|
||||
x = 0
|
||||
animation.from = notifyWidget.animationFrom
|
||||
animation.start()
|
||||
animation.restart()
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
NumberAnimation{
|
||||
NumberAnimation on x{
|
||||
id: animation
|
||||
properties: "x"
|
||||
duration: 500
|
||||
target: window
|
||||
from: notifyWidget.animationFrom
|
||||
to: notifyWidget.animationTo
|
||||
}
|
||||
@ -51,9 +50,8 @@ Window {
|
||||
Drag.cancel()
|
||||
notifyWidget.dismissed()
|
||||
}
|
||||
} else {
|
||||
x = 0
|
||||
}
|
||||
x = 0
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
|
@ -27,8 +27,8 @@
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
||||
m_id(pos),
|
||||
NotifyWidget::NotifyWidget(int id, const SnoreNotifier *parent) :
|
||||
m_id(id),
|
||||
m_parent(parent),
|
||||
m_mem(QLatin1String("SnoreNotifyWidget_rev") + QString::number(SHARED_MEM_TYPE_REV()) + QLatin1String("_id") + QString::number(m_id)),
|
||||
m_ready(true),
|
||||
@ -52,6 +52,8 @@ NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
||||
engine->load(QUrl::fromEncoded("qrc:/notification.qml"));
|
||||
m_window = qobject_cast<QQuickWindow *>(engine->rootObjects().value(0));
|
||||
|
||||
// TODO: Qt::BypassWindowManagerHint is needed on linux to make it possible to animate the Window.
|
||||
// It looks like there is a Qt bug wich make some Windows with this flag invisible.
|
||||
m_window->setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus | Qt::BypassWindowManagerHint
|
||||
#ifdef Q_OS_MAC
|
||||
| Qt::SubWindow
|
||||
@ -86,7 +88,7 @@ NotifyWidget::~NotifyWidget()
|
||||
|
||||
void NotifyWidget::display(const Notification ¬ification)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << m_id << notification.id();
|
||||
snoreDebug(SNORE_DEBUG) << m_id << notification.id() << m_window->isVisible();
|
||||
m_notification = notification;
|
||||
QColor color;
|
||||
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
|
||||
@ -177,11 +179,6 @@ int NotifyWidget::id() const
|
||||
return m_id;
|
||||
}
|
||||
|
||||
bool NotifyWidget::isVisible() const
|
||||
{
|
||||
return m_window->isVisible();
|
||||
}
|
||||
|
||||
void NotifyWidget::syncSettings()
|
||||
{
|
||||
Qt::Corner c = static_cast<Qt::Corner>(m_parent->settingsValue(QLatin1String("Position")).toInt());
|
||||
|
@ -33,7 +33,7 @@ typedef struct {
|
||||
|
||||
} SHARED_MEM_TYPE;
|
||||
|
||||
inline int SHARED_MEM_TYPE_REV()
|
||||
Q_CONSTEXPR int SHARED_MEM_TYPE_REV()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
@ -41,6 +41,7 @@ inline int SHARED_MEM_TYPE_REV()
|
||||
class NotifyWidget : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int id READ id)
|
||||
Q_PROPERTY(bool isOrientatedLeft MEMBER m_isOrientatedLeft NOTIFY isOrientatedLeftChanged)
|
||||
Q_PROPERTY(int animationFrom MEMBER m_animationFrom NOTIFY animationFromChanged)
|
||||
Q_PROPERTY(int animationTo MEMBER m_animationTo NOTIFY animationtoChanged)
|
||||
@ -57,7 +58,7 @@ class NotifyWidget : public QObject
|
||||
Q_PROPERTY(QString fontFamily MEMBER m_fontFamily NOTIFY fontFamilyChanged)
|
||||
|
||||
public:
|
||||
explicit NotifyWidget(int pos, const SnoreNotifier *parent);
|
||||
explicit NotifyWidget(int id, const SnoreNotifier *parent);
|
||||
~NotifyWidget();
|
||||
|
||||
void display(const Snore::Notification ¬ification);
|
||||
@ -68,7 +69,6 @@ public:
|
||||
Snore::Notification ¬ification();
|
||||
|
||||
int id() const;
|
||||
bool isVisible() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void invoked();
|
||||
|
@ -27,7 +27,7 @@
|
||||
using namespace Snore;
|
||||
|
||||
SnoreNotifier::SnoreNotifier():
|
||||
m_widgets(3),
|
||||
m_widgets(1),
|
||||
m_timer(new QTimer(this))
|
||||
{
|
||||
for (int i = 0; i < m_widgets.size(); ++i) {
|
||||
@ -47,26 +47,8 @@ SnoreNotifier::SnoreNotifier():
|
||||
});
|
||||
}
|
||||
|
||||
m_timer->setInterval(500);
|
||||
connect(m_timer, &QTimer::timeout, [this]() {
|
||||
if (m_queue.isEmpty()) {
|
||||
snoreDebug(SNORE_DEBUG) << "queue is empty";
|
||||
m_timer->stop();
|
||||
} else {
|
||||
for (NotifyWidget *w : m_widgets) {
|
||||
if (w->acquire(m_queue.first().timeout())) {
|
||||
Notification notification = m_queue.takeFirst();
|
||||
w->display(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
slotNotificationDisplayed(notification);
|
||||
if (m_queue.isEmpty()) {
|
||||
m_timer->stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
m_timer->setInterval(1000);
|
||||
connect(m_timer, &QTimer::timeout, this, &SnoreNotifier::slotQueueTimeout);
|
||||
|
||||
}
|
||||
|
||||
@ -88,7 +70,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
||||
if (notification.isUpdate()) {
|
||||
if (notification.old().hints().privateValue(this, "id").isValid()) {
|
||||
NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()];
|
||||
if (w->isVisible() && w->notification().isValid() && w->notification().id() == notification.old().id()) {
|
||||
if (w->notification().isValid() && w->notification().id() == notification.old().id()) {
|
||||
snoreDebug(SNORE_DEBUG) << "replacing notification" << w->notification().id() << notification.id();
|
||||
display(w, notification);
|
||||
}
|
||||
@ -101,16 +83,19 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (m_queue.isEmpty()) {
|
||||
for (NotifyWidget *w : m_widgets) {
|
||||
if (w->acquire(notification.timeout())) {
|
||||
display(w, notification);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (m_queue.isEmpty()) {
|
||||
for (NotifyWidget *w : m_widgets) {
|
||||
if (w->acquire(notification.timeout())) {
|
||||
display(w, notification);
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_queue.append(notification);
|
||||
}
|
||||
m_queue.append(notification);
|
||||
snoreDebug(SNORE_WARNING) << "queing" << m_queue.size();
|
||||
if(!m_timer->isActive()){
|
||||
m_timer->start();
|
||||
}
|
||||
}
|
||||
@ -119,7 +104,26 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
|
||||
{
|
||||
NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()];
|
||||
w->release();
|
||||
//the timer will show the next
|
||||
slotQueueTimeout();
|
||||
}
|
||||
|
||||
void SnoreNotifier::slotQueueTimeout()
|
||||
{
|
||||
snoreDebug(SNORE_WARNING) << "queue" << m_queue.size();
|
||||
if (m_queue.isEmpty()) {
|
||||
// snoreDebug(SNORE_DEBUG) << "queue is empty";
|
||||
m_timer->stop();
|
||||
} else {
|
||||
for (NotifyWidget *w : m_widgets) {
|
||||
if (!m_queue.isEmpty() && w->acquire(m_queue.first().timeout())) {
|
||||
snoreDebug(SNORE_WARNING) << "aquired " << w->id();
|
||||
Notification notification = m_queue.takeFirst();
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
w->display(notification);
|
||||
slotNotificationDisplayed(notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SnoreNotifier::canCloseNotification() const
|
||||
|
@ -43,6 +43,9 @@ public Q_SLOTS:
|
||||
virtual void slotNotify(Snore::Notification notification) override;
|
||||
virtual void slotCloseNotification(Snore::Notification notification) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotQueueTimeout();
|
||||
|
||||
private:
|
||||
QList<Snore::Notification> m_queue;
|
||||
QVector<NotifyWidget *> m_widgets;
|
||||
|
Loading…
x
Reference in New Issue
Block a user