diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ba66fcd..3f2912c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -931,17 +931,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) { @@ -987,7 +986,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(); @@ -998,7 +1002,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 0603890..b748d72 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -118,9 +118,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);