From 906ca7eb436dc9944d43f5b7f6ae7b44afc2a3e7 Mon Sep 17 00:00:00 2001 From: Keshav Bhatt Date: Sat, 20 May 2023 21:22:01 +0530 Subject: fix: fix unread message parsing - fixes #116 --- src/mainwindow.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1ba43f1..c4098f5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -978,25 +978,33 @@ void MainWindow::fullScreenRequested(QWebEngineFullScreenRequest request) { void MainWindow::handleWebViewTitleChanged(const QString &title) { setWindowTitle(QApplication::applicationName() + ": " + title); - QRegularExpressionMatch match = m_notificationsTitleRegExp.match(title); - if (match.hasMatch()) { - QString capturedTitle = match.captured(0); - m_unreadMessageCountRegExp.setPatternOptions( - QRegularExpression::DontCaptureOption); - QRegularExpressionMatch countMatch = + QRegularExpressionMatch notificationsTitleMatch = + m_notificationsTitleRegExp.match(title); + + if (notificationsTitleMatch.hasMatch()) { + + QString capturedTitle = notificationsTitleMatch.captured(0); + + QRegularExpressionMatch unreadMessageCountMatch = m_unreadMessageCountRegExp.match(capturedTitle); - if (countMatch.hasMatch()) { - QString unreadMessageCountStr = countMatch.captured(0); + + if (unreadMessageCountMatch.hasMatch()) { + + QString unreadMessageCountStr = unreadMessageCountMatch.captured(1); + int unreadMessageCount = unreadMessageCountStr.toInt(); m_restoreAction->setText( tr("Restore") + " | " + unreadMessageCountStr + " " + (unreadMessageCount > 1 ? tr("messages") : tr("message"))); + m_systemTrayIcon->setIcon(getTrayIcon(unreadMessageCount)); + setWindowIcon(getTrayIcon(unreadMessageCount)); } } else { m_systemTrayIcon->setIcon(m_trayIconNormal); + setWindowIcon(m_trayIconNormal); } } -- cgit v1.2.3