Skip to content

Commit

Permalink
fix: prevent crashes due to custom notification
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavbhatt committed Nov 1, 2024
1 parent ece2c55 commit dde6e02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,17 +932,16 @@ void MainWindow::createWebPage(bool offTheRecord) {
}

void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) {
auto *op = m_webEngine->findChild<NotificationPopup *>("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<QWebEngineNotification> notification) {
Expand Down Expand Up @@ -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();
Expand All @@ -999,7 +1003,7 @@ void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) {
return;
}
}
popup->present(screen, notification);
m_webengine_notifier_popup->present(screen, notification);
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dde6e02

Please sign in to comment.