From dde6e024d097bf3fa36a08d2baa59c69f0bc0571 Mon Sep 17 00:00:00 2001 From: Keshav Bhatt Date: Fri, 1 Nov 2024 23:34:31 +0530 Subject: [PATCH] fix: prevent crashes due to custom notification --- src/mainwindow.cpp | 24 ++++++++++++++---------- src/mainwindow.h | 3 ++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 94dc414..ac9741d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -932,17 +932,16 @@ void MainWindow::createWebPage(bool offTheRecord) { } void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) { - auto *op = m_webEngine->findChild("engineNotifier"); - if (op != nullptr) { - op->close(); - op->deleteLater(); + + if (m_webengine_notifier_popup != nullptr) { + m_webengine_notifier_popup->close(); + m_webengine_notifier_popup->deleteLater(); } - auto popup = new NotificationPopup(m_webEngine); - popup->setObjectName("engineNotifier"); + m_webengine_notifier_popup = new NotificationPopup(m_webEngine); - connect(popup, &NotificationPopup::notification_clicked, this, - [this]() { notificationClicked(); }); + connect(m_webengine_notifier_popup, &NotificationPopup::notification_clicked, + this, [this]() { notificationClicked(); }); profile->setNotificationPresenter( [&](std::unique_ptr notification) { @@ -988,7 +987,12 @@ void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) { return; } - popup->setMinimumWidth(300); + if (!m_webengine_notifier_popup) { + qWarning() << "Popup is not available!"; + return; + } + + m_webengine_notifier_popup->setMinimumWidth(300); QScreen *screen = QGuiApplication::primaryScreen(); if (!screen) { const auto screens = QGuiApplication::screens(); @@ -999,7 +1003,7 @@ void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) { return; } } - popup->present(screen, notification); + m_webengine_notifier_popup->present(screen, notification); }); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 7be6372..64ce92c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -119,9 +119,10 @@ protected slots: AutoLockEventFilter *m_autoLockEventFilter = nullptr; Qt::WindowStates windowStateBeforeFullScreen; - QString userDesktopEnvironment = Utils::detectDesktopEnvironment(); + QString userDesktopEnvironment = Utils::detectDesktopEnvironment(); void notificationClicked(); + NotificationPopup *m_webengine_notifier_popup = nullptr; private slots: void iconActivated(QSystemTrayIcon::ActivationReason reason); void toggleMute(const bool &checked);