From 0bdd0689c09784bc91ca17ec3ba06f5869d4724c Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 6 Feb 2023 13:16:37 +0400 Subject: [PATCH] Create tray / mediaview queued on macOS. This removes some strange redundant entries like "Item-0" from the Dock menu. --- Telegram/SourceFiles/core/application.cpp | 35 +++++++++++++++++++++-- Telegram/SourceFiles/core/application.h | 2 ++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 5a33ab1d0..a53162549 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -347,9 +347,7 @@ void Application::run() { _lastActivePrimaryWindow->widget()->show(); - const auto current = _lastActivePrimaryWindow->widget()->geometry(); - _mediaView = std::make_unique(); - _lastActivePrimaryWindow->widget()->Ui::RpWidget::setGeometry(current); + startMediaView(); DEBUG_LOG(("Application Info: showing.")); _lastActivePrimaryWindow->finishFirstShow(); @@ -492,7 +490,38 @@ void Application::processCreatedWindow( ) | rpl::start_to_stream(_openInMediaViewRequests, window->lifetime()); } +void Application::startMediaView() { +#ifdef Q_OS_MAC + // On macOS we create some windows async, otherwise they're + // added to the Dock Menu as a visible window and are removed + // only after first show and then hide. + InvokeQueued(this, [=] { + _mediaView = std::make_unique(); + }); +#else // Q_OS_MAC + // On Windows we needed such hack for the main window, otherwise + // somewhere inside the media viewer creating code its geometry + // was broken / lost to some invalid values. + const auto current = _lastActivePrimaryWindow->widget()->geometry(); + _mediaView = std::make_unique(); + _lastActivePrimaryWindow->widget()->Ui::RpWidget::setGeometry(current); +#endif // Q_OS_MAC +} + void Application::startTray() { +#ifdef Q_OS_MAC + // On macOS we create some windows async, otherwise they're + // added to the Dock Menu as a visible window and are removed + // only after first show and then hide, tray icon being "Item-0". + InvokeQueued(this, [=] { + createTray(); + }); +#else // Q_OS_MAC + createTray(); +#endif // Q_OS_MAC +} + +void Application::createTray() { using WindowRaw = not_null; _tray->create(); _tray->aboutToShowRequests( diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 8671b89d7..cc6bcc143 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -333,8 +333,10 @@ private: void startDomain(); void startEmojiImageLoader(); void startSystemDarkModeViewer(); + void startMediaView(); void startTray(); + void createTray(); void updateWindowTitles(); void setLastActiveWindow(Window::Controller *window); void showAccount(not_null account);