From 7cfb122dea86fde1c76f8e40ce0c34e1bf3ab878 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 12 Apr 2019 17:21:01 +0400 Subject: [PATCH] Fix crash with event loop nesting tracking. --- Telegram/SourceFiles/mainwindow.cpp | 8 ++++++-- Telegram/SourceFiles/mainwindow.h | 4 +++- .../SourceFiles/platform/linux/main_window_linux.cpp | 5 +---- Telegram/SourceFiles/platform/mac/main_window_mac.mm | 4 +--- .../SourceFiles/platform/win/main_window_win.cpp | 4 +--- Telegram/SourceFiles/window/main_window.cpp | 12 ++++++++++++ Telegram/SourceFiles/window/main_window.h | 3 +++ 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index a6daee23c..12d33ade8 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -675,9 +675,13 @@ void MainWindow::showFromTray(QSystemTrayIcon::ActivationReason reason) { } } -void MainWindow::toggleTray(QSystemTrayIcon::ActivationReason reason) { +void MainWindow::handleTrayIconActication( + QSystemTrayIcon::ActivationReason reason) { updateIsActive(0); - if ((cPlatform() == dbipMac || cPlatform() == dbipMacOld) && isActive()) return; + if ((cPlatform() == dbipMac || cPlatform() == dbipMacOld) + && isActive()) { + return; + } if (reason == QSystemTrayIcon::Context) { updateTrayMenu(true); QTimer::singleShot(1, this, SLOT(psShowTrayMenu())); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 5acabdc6f..89aa6b98f 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -132,7 +132,6 @@ public slots: void quitFromTray(); void showFromTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown); - void toggleTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown); void toggleDisplayNotifyFromTray(); void onClearFinished(int task, void *manager); @@ -150,6 +149,9 @@ signals: private: [[nodiscard]] bool skipTrayClick() const; + void handleTrayIconActication( + QSystemTrayIcon::ActivationReason reason) override; + void hideMediaPreview(); void ensureLayerCreated(); void destroyLayer(); diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index cdc310284..98fbafaec 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -268,9 +268,6 @@ void MainWindow::psSetupTrayIcon() { } trayIcon->setIcon(icon); - trayIcon->setToolTip(str_const_toString(AppName)); - connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); - // This is very important for native notifications via libnotify! // Some notification servers compose several notifications with a "Reply" // action into one and after that a click on "Reply" button does not call @@ -278,7 +275,7 @@ void MainWindow::psSetupTrayIcon() { // just ignores ibus messages, but Qt tray icon at least emits this signal. connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray())); - App::wnd()->updateTrayMenu(); + attachToTrayIcon(trayIcon); } updateIconCounters(); diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index dbb330d9e..47a5f1d29 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -450,9 +450,7 @@ void MainWindow::psSetupTrayIcon() { icon.addPixmap(QPixmap::fromImage(psTrayIcon(true), Qt::ColorOnly), QIcon::Selected); trayIcon->setIcon(icon); - trayIcon->setToolTip(str_const_toString(AppName)); - connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); - App::wnd()->updateTrayMenu(); + attachToTrayIcon(trayIcon); } updateIconCounters(); diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index ffdd13635..3f1f6b372 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -667,10 +667,8 @@ void MainWindow::psSetupTrayIcon() { auto icon = QIcon(App::pixmapFromImageInPlace(Core::App().logoNoMargin())); trayIcon->setIcon(icon); - trayIcon->setToolTip(str_const_toString(AppName)); - connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray())); - App::wnd()->updateTrayMenu(); + attachToTrayIcon(trayIcon); } updateIconCounters(); diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index ee552f085..8234dbaa2 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "core/click_handler_types.h" #include "core/application.h" +#include "core/sandbox.h" #include "lang/lang_keys.h" #include "data/data_session.h" #include "auth_session.h" @@ -406,6 +407,17 @@ void MainWindow::setPositionInited() { _positionInited = true; } +void MainWindow::attachToTrayIcon(not_null icon) { + icon->setToolTip(str_const_toString(AppName)); + connect(icon, &QSystemTrayIcon::activated, this, [=]( + QSystemTrayIcon::ActivationReason reason) { + Core::Sandbox::Instance().customEnterFromEventLoop([&] { + handleTrayIconActication(reason); + }); + }); + App::wnd()->updateTrayMenu(); +} + void MainWindow::resizeEvent(QResizeEvent *e) { updateControlsGeometry(); } diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index 76526c0f2..2d1aa0208 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -143,6 +143,9 @@ protected: virtual int32 screenNameChecksum(const QString &name) const; void setPositionInited(); + void attachToTrayIcon(not_null icon); + virtual void handleTrayIconActication( + QSystemTrayIcon::ActivationReason reason) = 0; private: void checkAuthSession();