diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 136af3c7c6..58f6c99d0f 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1193,8 +1193,6 @@ PRIVATE window/themes/window_themes_generate_name.h apiwrap.cpp apiwrap.h - app.cpp - app.h config.h facades.cpp facades.h diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 0b9ea0883b..bee3d0f7cd 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3087,4 +3087,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_mac_touchbar_favorite_stickers" = "Favorite stickers"; +"lng_mac_hold_to_quit" = "Hold {text} to Quit"; + // Keys finished diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 17e0b1e0bd..4f138a510d 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -46,7 +46,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/confirm_box.h" #include "apiwrap.h" #include "ui/text/format_values.h" // Ui::FormatPhone -#include "app.h" // App::quitting namespace Api { namespace { @@ -912,7 +911,7 @@ void Updates::updateOnline(crl::time lastNonIdleTime, bool gotOtherOffline) { _lastWasOnline = isOnline; _lastSetOnline = ms; - if (!App::quitting()) { + if (!Core::Quitting()) { _onlineRequest = api().request(MTPaccount_UpdateStatus( MTP_bool(!isOnline) )).send(); diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 737faa7b7a..b9f47daf3a 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -87,7 +87,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_media_prepare.h" #include "storage/storage_account.h" #include "facades.h" -#include "app.h" // App::quitting namespace { @@ -2127,7 +2126,7 @@ bool ApiWrap::isQuitPrevent() { void ApiWrap::checkQuitPreventFinished() { if (_draftsSaveRequestIds.empty()) { - if (App::quitting()) { + if (Core::Quitting()) { LOG(("ApiWrap doesn't prevent quit any more.")); } Core::App().quitPreventFinished(); diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp deleted file mode 100644 index e5bf010584..0000000000 --- a/Telegram/SourceFiles/app.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "app.h" - -#include "history/view/history_view_element.h" -#include "core/update_checker.h" -#include "core/sandbox.h" -#include "core/application.h" -#include "mainwindow.h" - -#include -#include - -namespace { - -App::LaunchState _launchState = App::Launched; - -HistoryView::Element *hoveredItem = nullptr, - *pressedItem = nullptr, - *hoveredLinkItem = nullptr, - *pressedLinkItem = nullptr, - *mousedItem = nullptr; - -} // namespace - -namespace App { - - void hoveredItem(HistoryView::Element *item) { - ::hoveredItem = item; - } - - HistoryView::Element *hoveredItem() { - return ::hoveredItem; - } - - void pressedItem(HistoryView::Element *item) { - ::pressedItem = item; - } - - HistoryView::Element *pressedItem() { - return ::pressedItem; - } - - void hoveredLinkItem(HistoryView::Element *item) { - ::hoveredLinkItem = item; - } - - HistoryView::Element *hoveredLinkItem() { - return ::hoveredLinkItem; - } - - void pressedLinkItem(HistoryView::Element *item) { - ::pressedLinkItem = item; - } - - HistoryView::Element *pressedLinkItem() { - return ::pressedLinkItem; - } - - void mousedItem(HistoryView::Element *item) { - ::mousedItem = item; - } - - HistoryView::Element *mousedItem() { - return ::mousedItem; - } - - void clearMousedItems() { - hoveredItem(nullptr); - pressedItem(nullptr); - hoveredLinkItem(nullptr); - pressedLinkItem(nullptr); - mousedItem(nullptr); - } - - void quit() { - if (quitting()) { - return; - } else if (Core::IsAppLaunched() - && Core::App().preventsQuit()) { - return; - } - setLaunchState(QuitRequested); - - if (auto window = App::wnd()) { - if (!Core::Sandbox::Instance().isSavingSession()) { - window->hide(); - } - } - Core::Application::QuitAttempt(); - } - - bool quitting() { - return _launchState != Launched; - } - - LaunchState launchState() { - return _launchState; - } - - void setLaunchState(LaunchState state) { - _launchState = state; - } - - void restart() { - using namespace Core; - const auto updateReady = !UpdaterDisabled() - && (UpdateChecker().state() == UpdateChecker::State::Ready); - if (updateReady) { - cSetRestartingUpdate(true); - } else { - cSetRestarting(true); - cSetRestartingToSettings(true); - } - App::quit(); - } - -} diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h deleted file mode 100644 index 65b111b6a2..0000000000 --- a/Telegram/SourceFiles/app.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -namespace HistoryView { -class Element; -} // namespace HistoryView - -namespace App { - void hoveredItem(HistoryView::Element *item); - HistoryView::Element *hoveredItem(); - void pressedItem(HistoryView::Element *item); - HistoryView::Element *pressedItem(); - void hoveredLinkItem(HistoryView::Element *item); - HistoryView::Element *hoveredLinkItem(); - void pressedLinkItem(HistoryView::Element *item); - HistoryView::Element *pressedLinkItem(); - void mousedItem(HistoryView::Element *item); - HistoryView::Element *mousedItem(); - void clearMousedItems(); - - enum LaunchState { - Launched = 0, - QuitRequested = 1, - QuitProcessed = 2, - }; - void quit(); - bool quitting(); - LaunchState launchState(); - void setLaunchState(LaunchState state); - void restart(); - -}; diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index d5ed48eb99..a2d38d9d02 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toast/toast.h" #include "base/unixtime.h" #include "mtproto/mtproto_config.h" -#include "app.h" // App::quitting #include #include @@ -247,7 +246,7 @@ void Instance::destroyCall(not_null call) { _currentCallChanges.fire(nullptr); taken.reset(); - if (App::quitting()) { + if (Core::Quitting()) { LOG(("Calls::Instance doesn't prevent quit any more.")); } Core::App().quitPreventFinished(); @@ -285,7 +284,7 @@ void Instance::destroyGroupCall(not_null call) { _currentGroupCallChanges.fire(nullptr); taken.reset(); - if (App::quitting()) { + if (Core::Quitting()) { LOG(("Calls::Instance doesn't prevent quit any more.")); } Core::App().quitPreventFinished(); diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 848753e6ae..1d66fb63d8 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -83,7 +83,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/connection_box.h" #include "ui/boxes/confirm_box.h" #include "boxes/share_box.h" -#include "app.h" #include #include @@ -96,6 +95,8 @@ constexpr auto kQuitPreventTimeoutMs = crl::time(1500); constexpr auto kAutoLockTimeoutLateMs = crl::time(3000); constexpr auto kClearEmojiImageSourceTimeout = 10 * crl::time(1000); +LaunchState GlobalLaunchState/* = LaunchState::Running*/; + void SetCrashAnnotationsGL() { #ifdef Q_OS_WIN CrashReports::SetAnnotation("OpenGL ANGLE", [] { @@ -235,7 +236,7 @@ void Application::run() { if (cLaunchMode() == LaunchModeAutoStart && Platform::AutostartSkip()) { Platform::AutostartToggle(false); - App::quit(); + Quit(); return; } @@ -340,7 +341,7 @@ void Application::showOpenGLCrashNotification() { Ui::GL::CrashCheckFinish(); Core::App().settings().setDisableOpenGL(false); Local::writeSettings(); - App::restart(); + Restart(); }; const auto keepDisabled = [=] { Ui::GL::ForceDisable(true); @@ -721,7 +722,7 @@ void Application::switchDebugMode() { if (Logs::DebugEnabled()) { Logs::SetDebugEnabled(false); _launcher->writeDebugModeSetting(); - App::restart(); + Restart(); } else { Logs::SetDebugEnabled(true); _launcher->writeDebugModeSetting(); @@ -742,7 +743,7 @@ void Application::switchFreeType() { } cSetUseFreeType(true); } - App::restart(); + Restart(); } void Application::writeInstallBetaVersionsSetting() { @@ -760,7 +761,7 @@ Main::Session *Application::maybeActiveSession() const { bool Application::exportPreventsQuit() { if (_exportManager->inProgress()) { _exportManager->stopWithConfirmation([] { - App::quit(); + Quit(); }); return true; } @@ -782,7 +783,7 @@ bool Application::uploadPreventsQuit() { account->session().uploadsStop(); } } - App::quit(); + Quit(); }); return true; } @@ -790,8 +791,15 @@ bool Application::uploadPreventsQuit() { return false; } -bool Application::preventsQuit() { - return exportPreventsQuit() || uploadPreventsQuit(); +bool Application::preventsQuit(QuitReason reason) { + if (exportPreventsQuit() || uploadPreventsQuit()) { + return true; + } else if (const auto window = activeWindow()) { + if (window->widget()->isActive()) { + return window->widget()->preventsQuit(reason); + } + } + return false; } int Application::unreadBadge() const { @@ -999,7 +1007,7 @@ void Application::localPasscodeChanged() { } bool Application::hasActiveWindow(not_null session) const { - if (App::quitting() || !_primaryWindow) { + if (Quitting() || !_primaryWindow) { return false; } else if (_calls->hasActivePanel(session)) { return true; @@ -1173,9 +1181,10 @@ void Application::refreshGlobalProxy() { Sandbox::Instance().refreshGlobalProxy(); } -void Application::QuitAttempt() { +void QuitAttempt() { + const auto savingSession = Sandbox::Instance().isSavingSession(); if (!IsAppLaunched() - || Sandbox::Instance().isSavingSession() + || savingSession || App().readyToQuit()) { Sandbox::QuitWhenStarted(); } @@ -1206,12 +1215,18 @@ bool Application::readyToQuit() { } void Application::quitPreventFinished() { - if (App::quitting()) { + if (Quitting()) { QuitAttempt(); } } void Application::quitDelayed() { + if (_primaryWindow) { + _primaryWindow->widget()->hide(); + } + for (const auto &[history, window] : _secondaryWindows) { + window->widget()->hide(); + } if (!_private->quitTimer.isActive()) { _private->quitTimer.setCallback([] { Sandbox::QuitWhenStarted(); }); _private->quitTimer.callOnce(kQuitPreventTimeoutMs); @@ -1234,7 +1249,7 @@ void Application::startShortcuts() { ) | rpl::start_with_next([=](not_null request) { using Command = Shortcuts::Command; request->check(Command::Quit) && request->handle([] { - App::quit(); + Quit(); return true; }); request->check(Command::Lock) && request->handle([=] { @@ -1276,4 +1291,39 @@ Application &App() { return *Application::Instance; } +void Quit(QuitReason reason) { + if (Quitting()) { + return; + } else if (IsAppLaunched() && App().preventsQuit(reason)) { + return; + } + SetLaunchState(LaunchState::QuitRequested); + + QuitAttempt(); +} + +bool Quitting() { + return GlobalLaunchState != LaunchState::Running; +} + +LaunchState CurrentLaunchState() { + return GlobalLaunchState; +} + +void SetLaunchState(LaunchState state) { + GlobalLaunchState = state; +} + +void Restart() { + const auto updateReady = !UpdaterDisabled() + && (UpdateChecker().state() == UpdateChecker::State::Ready); + if (updateReady) { + cSetRestartingUpdate(true); + } else { + cSetRestarting(true); + cSetRestartingToSettings(true); + } + Quit(); +} + } // namespace Core diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index bdca073b44..c11b3150a2 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -39,10 +39,6 @@ namespace ChatHelpers { class EmojiKeywords; } // namespace ChatHelpers -namespace App { -void quit(); -} // namespace App - namespace Main { class Domain; class Account; @@ -107,6 +103,17 @@ namespace Core { class Launcher; struct LocalUrlHandler; +enum class LaunchState { + Running, + QuitRequested, + QuitProcessed, +}; + +enum class QuitReason { + Default, + QtQuitEvent, +}; + class Application final : public QObject { public: struct ProxyChange { @@ -255,7 +262,7 @@ public: void checkAutoLockIn(crl::time time); void localPasscodeChanged(); - [[nodiscard]] bool preventsQuit(); + [[nodiscard]] bool preventsQuit(QuitReason reason); [[nodiscard]] crl::time lastNonIdleTime() const; void updateNonIdle(); @@ -305,8 +312,7 @@ private: void startEmojiImageLoader(); void startSystemDarkModeViewer(); - friend void App::quit(); - static void QuitAttempt(); + friend void QuitAttempt(); void quitDelayed(); [[nodiscard]] bool readyToQuit(); @@ -391,4 +397,12 @@ private: [[nodiscard]] bool IsAppLaunched(); [[nodiscard]] Application &App(); +[[nodiscard]] LaunchState CurrentLaunchState(); +void SetLaunchState(LaunchState state); + +void Quit(QuitReason reason = QuitReason::Default); +[[nodiscard]] bool Quitting(); + +void Restart(); + } // namespace Core diff --git a/Telegram/SourceFiles/core/crash_report_window.cpp b/Telegram/SourceFiles/core/crash_report_window.cpp index d72d81afa7..be3e9973aa 100644 --- a/Telegram/SourceFiles/core/crash_report_window.cpp +++ b/Telegram/SourceFiles/core/crash_report_window.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_report_window.h" #include "core/crash_reports.h" +#include "core/application.h" #include "core/launcher.h" #include "core/sandbox.h" #include "core/update_checker.h" @@ -15,7 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/main_window.h" #include "platform/platform_specific.h" #include "base/zlib_help.h" -#include "app.h" #include #include @@ -208,7 +208,7 @@ void NotStartedWindow::updateControls() { void NotStartedWindow::closeEvent(QCloseEvent *e) { deleteLater(); - App::quit(); + Core::Quit(); } void NotStartedWindow::resizeEvent(QResizeEvent *e) { @@ -906,7 +906,7 @@ void LastCrashedWindow::setUpdatingState(UpdatingState state, bool force) { case UpdatingReady: if (Core::checkReadyUpdate()) { cSetRestartingUpdate(true); - App::quit(); + Core::Quit(); return; } else { setUpdatingState(UpdatingFail); diff --git a/Telegram/SourceFiles/core/sandbox.cpp b/Telegram/SourceFiles/core/sandbox.cpp index 403d9c6f82..1641a58fc9 100644 --- a/Telegram/SourceFiles/core/sandbox.cpp +++ b/Telegram/SourceFiles/core/sandbox.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qt/qt_common_adapters.h" #include "ui/ui_utility.h" #include "ui/effects/animations.h" -#include "app.h" #include #include @@ -196,7 +195,7 @@ void Sandbox::QuitWhenStarted() { void Sandbox::launchApplication() { InvokeQueued(this, [=] { - if (App::quitting()) { + if (Quitting()) { quit(); } else if (_application) { return; @@ -261,12 +260,12 @@ void Sandbox::setupScreenScale() { Sandbox::~Sandbox() = default; bool Sandbox::event(QEvent *e) { - if (e->type() == QEvent::Quit && !App::quitting()) { - App::quit(); + if (e->type() == QEvent::Quit && !Quitting()) { + Quit(QuitReason::QtQuitEvent); e->ignore(); return false; } else if (e->type() == QEvent::Close) { - App::quit(); + Quit(); } return QApplication::event(e); } @@ -318,16 +317,16 @@ void Sandbox::socketReading() { psActivateProcess(pid); } LOG(("Show command response received, pid = %1, activating and quitting...").arg(pid)); - return App::quit(); + return Quit(); } } void Sandbox::socketError(QLocalSocket::LocalSocketError e) { - if (App::quitting()) return; + if (Quitting()) return; if (_secondInstance) { LOG(("Could not write show command, error %1, quitting...").arg(e)); - return App::quit(); + return Quit(); } if (e == QLocalSocket::ServerNotFoundError) { @@ -343,7 +342,7 @@ void Sandbox::socketError(QLocalSocket::LocalSocketError e) { if (!_localServer.listen(_localServerName)) { LOG(("Failed to start listening to %1 server: %2").arg(_localServerName, _localServer.errorString())); - return App::quit(); + return Quit(); } #endif // !Q_OS_WINRT @@ -352,11 +351,11 @@ void Sandbox::socketError(QLocalSocket::LocalSocketError e) { && Core::checkReadyUpdate()) { cSetRestartingUpdate(true); DEBUG_LOG(("Sandbox Info: installing update instead of starting app...")); - return App::quit(); + return Quit(); } if (cQuit()) { - return App::quit(); + return Quit(); } singleInstanceChecked(); @@ -407,7 +406,7 @@ void Sandbox::singleInstanceChecked() { void Sandbox::socketDisconnected() { if (_secondInstance) { DEBUG_LOG(("Sandbox Error: socket disconnected before command response received, quitting...")); - return App::quit(); + return Quit(); } } @@ -499,7 +498,7 @@ void Sandbox::removeClients() { } void Sandbox::checkForQuit() { - if (App::quitting()) { + if (Quitting()) { quit(); } } @@ -633,10 +632,10 @@ MTP::ProxyData Sandbox::sandboxProxy() const { } void Sandbox::closeApplication() { - if (App::launchState() == App::QuitProcessed) { + if (CurrentLaunchState() == LaunchState::QuitProcessed) { return; } - App::setLaunchState(App::QuitProcessed); + SetLaunchState(LaunchState::QuitProcessed); _application = nullptr; @@ -660,7 +659,7 @@ void Sandbox::execExternal(const QString &cmd) { PreLaunchWindow::instance()->activate(); } } else if (cmd == "quit") { - App::quit(); + Quit(); } } diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index f03d46a136..2cec99a73d 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "settings/settings_intro.h" #include "ui/layers/box_content.h" -#include "app.h" #include #include @@ -1175,7 +1174,7 @@ void Updater::check() { void Updater::handleReady() { stop(); _action = Action::Ready; - if (!App::quitting()) { + if (!Quitting()) { cSetLastUpdateCheck(base::unixtime::now()); Local::writeSettings(); } @@ -1203,7 +1202,7 @@ void Updater::handleProgress() { void Updater::scheduleNext() { stop(); - if (!App::quitting()) { + if (!Quitting()) { cSetLastUpdateCheck(base::unixtime::now()); Local::writeSettings(); start(true); diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 39c09b48d6..02d0bc3854 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -51,9 +51,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_file_origin.h" #include "main/main_session.h" #include "main/main_session_settings.h" +#include "core/application.h" #include "lang/lang_keys.h" #include "storage/file_upload.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_dialogs.h" @@ -464,7 +464,7 @@ MediaPhoto::MediaPhoto( } MediaPhoto::~MediaPhoto() { - if (uploading() && !App::quitting()) { + if (uploading() && !Core::Quitting()) { parent()->history()->session().uploader().cancel(parent()->fullId()); } parent()->history()->owner().unregisterPhotoItem(_photo, parent()); @@ -649,7 +649,7 @@ MediaFile::MediaFile( } MediaFile::~MediaFile() { - if (uploading() && !App::quitting()) { + if (uploading() && !Core::Quitting()) { parent()->history()->session().uploader().cancel(parent()->fullId()); } parent()->history()->owner().unregisterDocumentItem( diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index abb0e8471c..9cae7df26f 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -64,7 +64,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/call_delayed.h" #include "base/random.h" #include "facades.h" // Notify::switchInlineBotButtonReceived -#include "app.h" #include "styles/style_boxes.h" // st::backgroundSize namespace Data { @@ -291,7 +290,7 @@ void Session::clear() { _sentMessagesData.clear(); cSetRecentInlineBots(RecentInlineBots()); cSetRecentStickers(RecentStickerPack()); - App::clearMousedItems(); + HistoryView::Element::ClearGlobal(); _histories->clearAll(); _webpages.clear(); _locations.clear(); @@ -3674,20 +3673,22 @@ void Session::unregisterItemView(not_null view) { _views.erase(i); } } - if (App::hoveredItem() == view) { - App::hoveredItem(nullptr); + + using namespace HistoryView; + if (Element::Hovered() == view) { + Element::Hovered(nullptr); } - if (App::pressedItem() == view) { - App::pressedItem(nullptr); + if (Element::Pressed() == view) { + Element::Pressed(nullptr); } - if (App::hoveredLinkItem() == view) { - App::hoveredLinkItem(nullptr); + if (Element::HoveredLink() == view) { + Element::HoveredLink(nullptr); } - if (App::pressedLinkItem() == view) { - App::pressedLinkItem(nullptr); + if (Element::PressedLink() == view) { + Element::PressedLink(nullptr); } - if (App::mousedItem() == view) { - App::mousedItem(nullptr); + if (Element::Moused() == view) { + Element::Moused(nullptr); } } diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 00c77f2af7..4718c0e210 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -47,7 +47,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_histories.h" #include "data/data_changes.h" #include "facades.h" -#include "app.h" #include "styles/style_dialogs.h" #include "styles/style_chat.h" #include "styles/style_info.h" @@ -607,7 +606,7 @@ void Widget::checkUpdateStatus() { _updateTelegram->show(); _updateTelegram->setClickedCallback([] { Core::checkReadyUpdate(); - App::restart(); + Core::Restart(); }); if (_connecting) { _connecting->raise(); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index dab33ac744..e375eb62bc 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -56,7 +56,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_user.h" #include "facades.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_menu_icons.h" @@ -529,7 +528,7 @@ void InnerWidget::updateEmptyText() { QString InnerWidget::tooltipText() const { if (_mouseCursorState == CursorState::Date && _mouseAction == MouseAction::None) { - if (const auto view = App::hoveredItem()) { + if (const auto view = Element::Hovered()) { const auto format = QLocale::system().dateTimeFormat( QLocale::LongFormat); auto dateText = HistoryView::DateTooltipText(view); @@ -545,7 +544,7 @@ QString InnerWidget::tooltipText() const { } } else if (_mouseCursorState == CursorState::Forwarded && _mouseAction == MouseAction::None) { - if (const auto view = App::hoveredItem()) { + if (const auto view = Element::Hovered()) { if (const auto forwarded = view->data()->Get()) { return forwarded->text.toString(); } @@ -582,7 +581,7 @@ std::unique_ptr InnerWidget::elementCreate( bool InnerWidget::elementUnderCursor( not_null view) { - return (App::hoveredItem() == view); + return (Element::Hovered() == view); } crl::time InnerWidget::elementHighlightTime( @@ -1145,13 +1144,13 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { auto selFrom = _selectedText.from; auto selTo = _selectedText.to; hasSelected = (selTo > selFrom) ? 1 : 0; - if (App::mousedItem() && App::mousedItem() == App::hoveredItem()) { + if (Element::Moused() && Element::Moused() == Element::Hovered()) { auto mousePos = mapPointToItem( mapFromGlobal(_mousePosition), - App::mousedItem()); + Element::Moused()); StateRequest request; request.flags |= Ui::Text::StateRequest::Flag::LookupSymbol; - auto dragState = App::mousedItem()->textState(mousePos, request); + auto dragState = Element::Moused()->textState(mousePos, request); if (dragState.cursor == CursorState::Text && base::in_range(dragState.symbol, selFrom, selTo)) { isUponSelected = 1; @@ -1167,9 +1166,9 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { st::popupMenuWithIcons); const auto link = ClickHandler::getActive(); - auto view = App::hoveredItem() - ? App::hoveredItem() - : App::hoveredLinkItem(); + auto view = Element::Hovered() + ? Element::Hovered() + : Element::HoveredLink(); const auto lnkPhoto = link ? reinterpret_cast( link->property(kPhotoLinkMediaProperty).toULongLong()) @@ -1526,9 +1525,9 @@ void InnerWidget::enterEventHook(QEnterEvent *e) { } void InnerWidget::leaveEventHook(QEvent *e) { - if (const auto view = App::hoveredItem()) { + if (const auto view = Element::Hovered()) { repaintItem(view); - App::hoveredItem(nullptr); + Element::Hovered(nullptr); } ClickHandler::clearActive(); Ui::Tooltip::Hide(); @@ -1544,14 +1543,14 @@ void InnerWidget::mouseActionStart(const QPoint &screenPos, Qt::MouseButton butt if (button != Qt::LeftButton) return; ClickHandler::pressed(); - if (App::pressedItem() != App::hoveredItem()) { - repaintItem(App::pressedItem()); - App::pressedItem(App::hoveredItem()); - repaintItem(App::pressedItem()); + if (Element::Pressed() != Element::Hovered()) { + repaintItem(Element::Pressed()); + Element::Pressed(Element::Hovered()); + repaintItem(Element::Pressed()); } _mouseAction = MouseAction::None; - _mouseActionItem = App::mousedItem(); + _mouseActionItem = Element::Moused(); _dragStartPosition = mapPointToItem( mapFromGlobal(screenPos), _mouseActionItem); @@ -1579,13 +1578,13 @@ void InnerWidget::mouseActionStart(const QPoint &screenPos, Qt::MouseButton butt mouseActionUpdate(_mousePosition); _trippleClickTimer.callOnce(QApplication::doubleClickInterval()); } - } else if (App::pressedItem()) { + } else if (Element::Pressed()) { StateRequest request; request.flags = Ui::Text::StateRequest::Flag::LookupSymbol; dragState = _mouseActionItem->textState(_dragStartPosition, request); } if (_mouseSelectType != TextSelectType::Paragraphs) { - if (App::pressedItem()) { + if (Element::Pressed()) { _mouseTextSymbol = dragState.symbol; auto uponSelected = (dragState.cursor == CursorState::Text); if (uponSelected) { @@ -1636,9 +1635,9 @@ void InnerWidget::mouseActionFinish(const QPoint &screenPos, Qt::MouseButton but if (_mouseAction == MouseAction::Dragging) { activated = nullptr; } - if (const auto view = App::pressedItem()) { + if (const auto view = Element::Pressed()) { repaintItem(view); - App::pressedItem(nullptr); + Element::Pressed(nullptr); } _wasSelectedText = false; @@ -1698,17 +1697,17 @@ void InnerWidget::updateSelected() { const auto view = (from != end) ? from->get() : nullptr; const auto item = view ? view->data().get() : nullptr; if (item) { - App::mousedItem(view); + Element::Moused(view); itemPoint = mapPointToItem(point, view); if (view->pointState(itemPoint) != PointState::Outside) { - if (App::hoveredItem() != view) { - repaintItem(App::hoveredItem()); - App::hoveredItem(view); + if (Element::Hovered() != view) { + repaintItem(Element::Hovered()); + Element::Hovered(view); repaintItem(view); } - } else if (const auto view = App::hoveredItem()) { + } else if (const auto view = Element::Hovered()) { repaintItem(view); - App::hoveredItem(nullptr); + Element::Hovered(nullptr); } } @@ -1716,7 +1715,7 @@ void InnerWidget::updateSelected() { ClickHandlerHost *lnkhost = nullptr; auto selectingText = _selectedItem && (view == _mouseActionItem) - && (view == App::hoveredItem()); + && (view == Element::Hovered()); if (view) { if (view != _mouseActionItem || (itemPoint - _dragStartPosition).manhattanLength() >= QApplication::startDragDistance()) { if (_mouseAction == MouseAction::PrepareDrag) { @@ -1807,7 +1806,7 @@ void InnerWidget::updateSelected() { } // Voice message seek support. - if (const auto pressedView = App::pressedLinkItem()) { + if (const auto pressedView = Element::PressedLink()) { const auto adjustedPoint = mapPointToItem(point, pressedView); pressedView->updatePressed(adjustedPoint); } @@ -1883,7 +1882,7 @@ void InnerWidget::performDrag() { //} else { // auto forwardMimeType = QString(); // auto pressedMedia = static_cast(nullptr); - // if (auto pressedItem = App::pressedItem()) { + // if (auto pressedItem = Element::Pressed()) { // pressedMedia = pressedItem->media(); // if (_mouseCursorState == CursorState::Date // || (pressedMedia && pressedMedia->dragItem())) { @@ -1892,7 +1891,7 @@ void InnerWidget::performDrag() { // session().data().itemOrItsGroup(pressedItem->data())); // } // } - // if (auto pressedLnkItem = App::pressedLinkItem()) { + // if (auto pressedLnkItem = Element::PressedLink()) { // if ((pressedMedia = pressedLnkItem->media())) { // if (forwardMimeType.isEmpty() // && pressedMedia->dragItemByHandler(pressedHandler)) { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 980b0b43a3..a3299cef08 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -82,7 +82,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/stickers/data_stickers.h" #include "data/data_sponsored_messages.h" #include "facades.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_window.h" // st::windowMinWidth #include "styles/style_menu_icons.h" @@ -153,7 +152,7 @@ public: } bool elementUnderCursor( not_null view) override { - return (App::mousedItem() == view); + return (Element::Moused() == view); } crl::time elementHighlightTime( not_null item) override { @@ -1400,13 +1399,13 @@ void HistoryInner::mouseActionStart(const QPoint &screenPos, Qt::MouseButton but if (button != Qt::LeftButton) return; ClickHandler::pressed(); - if (App::pressedItem() != App::hoveredItem()) { - repaintItem(App::pressedItem()); - App::pressedItem(App::hoveredItem()); - repaintItem(App::pressedItem()); + if (Element::Pressed() != Element::Hovered()) { + repaintItem(Element::Pressed()); + Element::Pressed(Element::Hovered()); + repaintItem(Element::Pressed()); } - const auto mouseActionView = App::mousedItem(); + const auto mouseActionView = Element::Moused(); _mouseAction = MouseAction::None; _mouseActionItem = mouseActionView ? mouseActionView->data().get() @@ -1422,7 +1421,7 @@ void HistoryInner::mouseActionStart(const QPoint &screenPos, Qt::MouseButton but } else if (inSelectionMode()) { if (_dragStateItem && _selected.find(_dragStateItem) != _selected.cend() - && App::hoveredItem()) { + && Element::Hovered()) { _mouseAction = MouseAction::PrepareDrag; // start items drag } else if (!_pressWasInactive) { _mouseAction = MouseAction::PrepareSelect; // start items select @@ -1450,13 +1449,13 @@ void HistoryInner::mouseActionStart(const QPoint &screenPos, Qt::MouseButton but QApplication::doubleClickInterval()); } } - } else if (App::pressedItem()) { + } else if (Element::Pressed()) { StateRequest request; request.flags = Ui::Text::StateRequest::Flag::LookupSymbol; dragState = mouseActionView->textState(_dragStartPosition, request); } if (_mouseSelectType != TextSelectType::Paragraphs) { - if (App::pressedItem()) { + if (Element::Pressed()) { _mouseTextSymbol = dragState.symbol; bool uponSelected = (dragState.cursor == CursorState::Text); if (uponSelected) { @@ -1474,7 +1473,7 @@ void HistoryInner::mouseActionStart(const QPoint &screenPos, Qt::MouseButton but if (uponSelected) { _mouseAction = MouseAction::PrepareDrag; // start text drag } else if (!_pressWasInactive) { - const auto media = App::pressedItem()->media(); + const auto media = Element::Pressed()->media(); if ((media && media->dragItem()) || _mouseCursorState == CursorState::Date) { _mouseAction = MouseAction::PrepareDrag; // start sticker drag or by-date drag @@ -1694,10 +1693,10 @@ void HistoryInner::mouseActionFinish( } } } - const auto pressedItemView = App::pressedItem(); + const auto pressedItemView = Element::Pressed(); if (pressedItemView) { repaintItem(pressedItemView); - App::pressedItem(nullptr); + Element::Pressed(nullptr); } _wasSelectedText = false; @@ -1874,15 +1873,15 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } else { isUponSelected = -2; } - } else if (App::mousedItem() - && App::mousedItem() == App::hoveredItem() - && _selected.cbegin()->first == App::mousedItem()->data()) { + } else if (Element::Moused() + && Element::Moused() == Element::Hovered() + && _selected.cbegin()->first == Element::Moused()->data()) { uint16 selFrom = _selected.cbegin()->second.from, selTo = _selected.cbegin()->second.to; hasSelected = (selTo > selFrom) ? 1 : 0; - auto mousePos = mapPointToItem(mapFromGlobal(_mousePosition), App::mousedItem()); + auto mousePos = mapPointToItem(mapFromGlobal(_mousePosition), Element::Moused()); StateRequest request; request.flags |= Ui::Text::StateRequest::Flag::LookupSymbol; - auto dragState = App::mousedItem()->textState(mousePos, request); + auto dragState = Element::Moused()->textState(mousePos, request); if (dragState.cursor == CursorState::Text && dragState.symbol >= selFrom && dragState.symbol < selTo) { @@ -2146,10 +2145,10 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } else { // maybe cursor on some text history item? const auto albumPartItem = _dragStateItem; const auto item = [&] { - const auto result = App::hoveredItem() - ? App::hoveredItem()->data().get() - : App::hoveredLinkItem() - ? App::hoveredLinkItem()->data().get() + const auto result = Element::Hovered() + ? Element::Hovered()->data().get() + : Element::HoveredLink() + ? Element::HoveredLink()->data().get() : nullptr; return result ? groupLeaderOrSelf(result) : nullptr; }(); @@ -2288,8 +2287,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { blockSenderAsGroup(itemId); }, &st::menuIconBlock); } - } else if (App::mousedItem()) { - addSelectMessageAction(App::mousedItem()->data()); + } else if (Element::Moused()) { + addSelectMessageAction(Element::Moused()->data()); } } @@ -2898,9 +2897,9 @@ void HistoryInner::enterEventHook(QEnterEvent *e) { void HistoryInner::leaveEventHook(QEvent *e) { _reactionsManager->updateButton({ .cursorLeft = true }); - if (auto item = App::hoveredItem()) { + if (auto item = Element::Hovered()) { repaintItem(item); - App::hoveredItem(nullptr); + Element::Hovered(nullptr); } ClickHandler::clearActive(); Ui::Tooltip::Hide(); @@ -3230,11 +3229,11 @@ void HistoryInner::mouseActionUpdate() { : nullptr; const auto item = view ? view->data().get() : nullptr; if (view) { - const auto changed = (App::mousedItem() != view); + const auto changed = (Element::Moused() != view); if (changed) { - repaintItem(App::mousedItem()); - App::mousedItem(view); - repaintItem(App::mousedItem()); + repaintItem(Element::Moused()); + Element::Moused(view); + repaintItem(Element::Moused()); } m = mapPointToItem(point, view); _reactionsManager->updateButton(reactionButtonParameters( @@ -3245,19 +3244,19 @@ void HistoryInner::mouseActionUpdate() { _reactionsManager->updateUniqueLimit(item); } if (view->pointState(m) != PointState::Outside) { - if (App::hoveredItem() != view) { - repaintItem(App::hoveredItem()); - App::hoveredItem(view); - repaintItem(App::hoveredItem()); + if (Element::Hovered() != view) { + repaintItem(Element::Hovered()); + Element::Hovered(view); + repaintItem(Element::Hovered()); } - } else if (App::hoveredItem()) { - repaintItem(App::hoveredItem()); - App::hoveredItem(nullptr); + } else if (Element::Hovered()) { + repaintItem(Element::Hovered()); + Element::Hovered(nullptr); } } else { - if (App::mousedItem()) { - repaintItem(App::mousedItem()); - App::mousedItem(nullptr); + if (Element::Moused()) { + repaintItem(Element::Moused()); + Element::Moused(nullptr); } _reactionsManager->updateButton({}); } @@ -3268,7 +3267,7 @@ void HistoryInner::mouseActionUpdate() { TextState dragState; ClickHandlerHost *lnkhost = nullptr; auto selectingText = (item == _mouseActionItem) - && (view == App::hoveredItem()) + && (view == Element::Hovered()) && !_selected.empty() && (_selected.cbegin()->second != FullSelection); const auto overReaction = reactionView && reactionState.link; @@ -3921,19 +3920,19 @@ void HistoryInner::applyDragSelection( QString HistoryInner::tooltipText() const { if (_mouseCursorState == CursorState::Date && _mouseAction == MouseAction::None) { - if (const auto view = App::hoveredItem()) { + if (const auto view = Element::Hovered()) { return HistoryView::DateTooltipText(view); } } else if (_mouseCursorState == CursorState::Forwarded && _mouseAction == MouseAction::None) { - if (const auto view = App::mousedItem()) { + if (const auto view = Element::Moused()) { if (const auto forwarded = view->data()->Get()) { return forwarded->text.toString(); } } } else if (const auto lnk = ClickHandler::getActive()) { return lnk->tooltip(); - } else if (const auto view = App::mousedItem()) { + } else if (const auto view = Element::Moused()) { StateRequest request; const auto local = mapFromGlobal(_mousePosition); const auto point = _widget->clampMousePosition(local); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 566f34ac52..10d4fdb69e 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -142,7 +142,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_key.h" #include "calls/calls_instance.h" #include "facades.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_dialogs.h" #include "styles/style_window.h" @@ -2040,7 +2039,7 @@ void HistoryWidget::showHistory( Assert(_list == nullptr); } - App::clearMousedItems(); + HistoryView::Element::ClearGlobal(); _saveEditMsgRequestId = 0; _replyEditMsg = nullptr; @@ -3978,8 +3977,8 @@ bool HistoryWidget::insertBotCommand(const QString &cmd) { if (!toInsert.isEmpty() && !insertingInlineBot) { auto bot = _peer->isUser() ? _peer - : (App::hoveredLinkItem() - ? App::hoveredLinkItem()->data()->fromOriginal().get() + : (HistoryView::Element::HoveredLink() + ? HistoryView::Element::HoveredLink()->data()->fromOriginal().get() : nullptr); if (bot && (!bot->isUser() || !bot->asUser()->isBot())) { bot = nullptr; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index a6dc65bf0e..62e5278c9e 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -37,7 +37,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_media_types.h" #include "data/data_sponsored_messages.h" #include "lang/lang_keys.h" -#include "app.h" #include "styles/style_chat.h" namespace HistoryView { @@ -46,6 +45,12 @@ namespace { // A new message from the same sender is attached to previous within 15 minutes. constexpr int kAttachMessageToPreviousSecondsDelta = 900; +Element *HoveredElement/* = nullptr*/; +Element *PressedElement/* = nullptr*/; +Element *HoveredLinkElement/* = nullptr*/; +Element *PressedLinkElement/* = nullptr*/; +Element *MousedElement/* = nullptr*/; + [[nodiscard]] bool IsAttachedToPreviousInSavedMessages( not_null previous, HistoryMessageForwarded *prevForwarded, @@ -1032,7 +1037,7 @@ void Element::clickHandlerActiveChanged( keyboard->clickHandlerActiveChanged(handler, active); } } - App::hoveredLinkItem(active ? this : nullptr); + HoveredLink(active ? this : nullptr); repaint(); if (const auto media = this->media()) { media->clickHandlerActiveChanged(handler, active); @@ -1047,7 +1052,7 @@ void Element::clickHandlerPressedChanged( keyboard->clickHandlerPressedChanged(handler, pressed); } } - App::pressedLinkItem(pressed ? this : nullptr); + PressedLink(pressed ? this : nullptr); repaint(); if (const auto media = this->media()) { media->clickHandlerPressedChanged(handler, pressed); @@ -1074,4 +1079,52 @@ Element::~Element() { history()->owner().unregisterItemView(this); } +void Element::Hovered(Element *view) { + HoveredElement = view; +} + +Element *Element::Hovered() { + return HoveredElement; +} + +void Element::Pressed(Element *view) { + PressedElement = view; +} + +Element *Element::Pressed() { + return PressedElement; +} + +void Element::HoveredLink(Element *view) { + HoveredLinkElement = view; +} + +Element *Element::HoveredLink() { + return HoveredLinkElement; +} + +void Element::PressedLink(Element *view) { + PressedLinkElement = view; +} + +Element *Element::PressedLink() { + return PressedLinkElement; +} + +void Element::Moused(Element *view) { + MousedElement = view; +} + +Element *Element::Moused() { + return MousedElement; +} + +void Element::ClearGlobal() { + HoveredElement = nullptr; + PressedElement = nullptr; + HoveredLinkElement = nullptr; + PressedLinkElement = nullptr; + MousedElement = nullptr; +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index d6e4b35c63..1ccb3bcafb 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -427,6 +427,18 @@ public: virtual ~Element(); + static void Hovered(Element *view); + [[nodiscard]] static Element *Hovered(); + static void Pressed(Element *view); + [[nodiscard]] static Element *Pressed(); + static void HoveredLink(Element *view); + [[nodiscard]] static Element *HoveredLink(); + static void PressedLink(Element *view); + [[nodiscard]] static Element *PressedLink(); + static void Moused(Element *view); + [[nodiscard]] static Element *Moused(); + static void ClearGlobal(); + protected: void repaint() const; diff --git a/Telegram/SourceFiles/info/info_layer_widget.cpp b/Telegram/SourceFiles/info/info_layer_widget.cpp index 4c2178a2ae..75a67085d8 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.cpp +++ b/Telegram/SourceFiles/info/info_layer_widget.cpp @@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "boxes/abstract_box.h" #include "core/application.h" -#include "app.h" // App::quitting. #include "styles/style_info.h" #include "styles/style_window.h" #include "styles/style_layers.h" @@ -297,7 +296,7 @@ void LayerWidget::closeHook() { } LayerWidget::~LayerWidget() { - if (!App::quitting()) { + if (!Core::Quitting()) { restoreFloatPlayerDelegate(); } } diff --git a/Telegram/SourceFiles/intro/intro_widget.cpp b/Telegram/SourceFiles/intro/intro_widget.cpp index 9aed9aa4bc..ca6ff3b287 100644 --- a/Telegram/SourceFiles/intro/intro_widget.cpp +++ b/Telegram/SourceFiles/intro/intro_widget.cpp @@ -41,7 +41,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/section_widget.h" #include "base/platform/base_platform_info.h" #include "api/api_text_entities.h" -#include "app.h" #include "styles/style_layers.h" #include "styles/style_intro.h" #include "base/qt/qt_common_adapters.h" @@ -304,7 +303,7 @@ void Widget::checkUpdateStatus() { _update->toggle(!stepHasCover, anim::type::instant); _update->entity()->setClickedCallback([] { Core::checkReadyUpdate(); - App::restart(); + Core::Restart(); }); } else { if (!_update) return; diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index 3719af18ce..41d352d2c5 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -21,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "core/file_utilities.h" #include "core/click_handler_types.h" -#include "app.h" #include "styles/style_layers.h" namespace Lang { @@ -548,7 +547,7 @@ void CloudManager::performSwitchToCustom() { + getValue(tr::lng_sure_save_language.base); const auto change = [=] { _langpack.switchToCustomFile(filePath); - App::restart(); + Core::Restart(); }; Ui::show( Box( @@ -595,7 +594,7 @@ void CloudManager::restartAfterSwitch() { if (_langPackRequestId || _langPackBaseRequestId) { _restartAfterSwitch = true; } else { - App::restart(); + Core::Restart(); } } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index e32acb5948..8ff7a0e874 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -798,7 +798,7 @@ void MainWindow::toggleDisplayNotifyFromTray() { void MainWindow::closeEvent(QCloseEvent *e) { if (Core::Sandbox::Instance().isSavingSession()) { e->accept(); - App::quit(); + Core::Quit(); } else { e->ignore(); const auto hasAuth = [&] { @@ -813,7 +813,7 @@ void MainWindow::closeEvent(QCloseEvent *e) { return false; }(); if (!hasAuth || !hideNoQuit()) { - App::quit(); + Core::Quit(); } } } diff --git a/Telegram/SourceFiles/media/audio/media_audio.cpp b/Telegram/SourceFiles/media/audio/media_audio.cpp index 6a7205be6f..df1371f6a7 100644 --- a/Telegram/SourceFiles/media/audio/media_audio.cpp +++ b/Telegram/SourceFiles/media/audio/media_audio.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_audio.h" #include "core/application.h" #include "main/main_session.h" -#include "app.h" #include #include @@ -244,7 +243,7 @@ bool AttachToDevice() { } crl::on_main([] { - if (!App::quitting()) { + if (!Core::Quitting()) { Current().reattachTracks(); } }); @@ -253,7 +252,7 @@ bool AttachToDevice() { void ScheduleDetachFromDeviceSafe() { crl::on_main([] { - if (!App::quitting()) { + if (!Core::Quitting()) { Current().scheduleDetachFromDevice(); } }); @@ -261,7 +260,7 @@ void ScheduleDetachFromDeviceSafe() { void ScheduleDetachIfNotUsedSafe() { crl::on_main([] { - if (!App::quitting()) { + if (!Core::Quitting()) { Current().scheduleDetachIfNotUsed(); } }); @@ -269,7 +268,7 @@ void ScheduleDetachIfNotUsedSafe() { void StopDetachIfNotUsedSafe() { crl::on_main([] { - if (!App::quitting()) { + if (!Core::Quitting()) { Current().stopDetachIfNotUsed(); } }); diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index ed57eccd17..741bce7db7 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.h +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.h @@ -35,6 +35,8 @@ public: void psShowTrayMenu(); + bool preventsQuit(Core::QuitReason reason) override; + class Private; public Q_SLOTS: diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index e9092ca4e4..4c538e84d4 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "platform/platform_notifications_manager.h" #include "base/platform/base_platform_info.h" +#include "base/platform/mac/base_confirm_quit.h" #include "boxes/peer_list_controllers.h" #include "boxes/about_box.h" #include "lang/lang_keys.h" @@ -284,6 +285,15 @@ void MainWindow::hideAndDeactivate() { void MainWindow::psShowTrayMenu() { } +bool MainWindow::preventsQuit(Core::QuitReason reason) { + // Thanks Chromium, see + // chromium.org/developers/design-documents/confirm-to-quit-experiment + return (reason == Core::QuitReason::QtQuitEvent) + && ([[NSApp currentEvent] type] == NSKeyDown) + && !Platform::ConfirmQuit::RunModal( + tr::lng_mac_hold_to_quit(tr::now, lt_text, "{key}")); +} + void MainWindow::psTrayMenuUpdated() { } diff --git a/Telegram/SourceFiles/platform/win/integration_win.cpp b/Telegram/SourceFiles/platform/win/integration_win.cpp index 0b0da418d2..b3d22620aa 100644 --- a/Telegram/SourceFiles/platform/win/integration_win.cpp +++ b/Telegram/SourceFiles/platform/win/integration_win.cpp @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "core/application.h" #include "core/sandbox.h" -#include "app.h" #include #include @@ -66,7 +65,7 @@ bool WindowsIntegration::processEvent( LRESULT *result) { switch (msg) { case WM_ENDSESSION: - App::quit(); + Core::Quit(); break; case WM_TIMECHANGE: diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index ccd3413339..68d2da2e42 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -282,7 +282,7 @@ void MainWindow::psShowTrayMenu() { } void MainWindow::destroyedFromSystem() { - App::quit(); + Core::Quit(); } int32 MainWindow::screenNameChecksum(const QString &name) const { diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index b0b89c2d8a..fd148b985a 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -36,7 +36,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_domain.h" #include "main/main_session.h" #include "mtproto/facade.h" -#include "app.h" #include "styles/style_settings.h" #ifndef TDESKTOP_DISABLE_SPELLCHECK @@ -243,7 +242,7 @@ void SetupUpdate(not_null container) { if (!Core::UpdaterDisabled()) { Core::checkReadyUpdate(); } - App::restart(); + Core::Restart(); }); } @@ -599,7 +598,7 @@ void SetupANGLE( Core::App().settings().setDisableOpenGL(nowDisabled); Local::writeSettings(); } - App::restart(); + Core::Restart(); }); controller->show(Box( tr::lng_settings_need_restart(tr::now), @@ -638,7 +637,7 @@ void SetupOpenGL( const auto confirmed = crl::guard(button, [=] { Core::App().settings().setDisableOpenGL(!enabled); Local::writeSettings(); - App::restart(); + Core::Restart(); }); const auto cancelled = crl::guard(button, [=] { toggles->fire(!enabled); diff --git a/Telegram/SourceFiles/settings/settings_calls.cpp b/Telegram/SourceFiles/settings/settings_calls.cpp index fb0ec060dd..11d53edcbb 100644 --- a/Telegram/SourceFiles/settings/settings_calls.cpp +++ b/Telegram/SourceFiles/settings/settings_calls.cpp @@ -35,7 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "webrtc/webrtc_create_adm.h" // Webrtc::Backend. #include "tgcalls/VideoCaptureInterface.h" #include "facades.h" -#include "app.h" // App::restart(). #include "styles/style_layers.h" namespace Settings { @@ -453,7 +452,7 @@ object_ptr ChooseAudioInputBox( // Core::App().settings().setCallAudioBackend( // static_cast(option)); // Core::App().saveSettings(); -// App::restart(); +// Core::Restart(); // }; // return Box([=](not_null box) { // SingleChoiceBox(box, { diff --git a/Telegram/SourceFiles/settings/settings_folders.cpp b/Telegram/SourceFiles/settings/settings_folders.cpp index bbd22050f3..5e709c7b33 100644 --- a/Telegram/SourceFiles/settings/settings_folders.cpp +++ b/Telegram/SourceFiles/settings/settings_folders.cpp @@ -25,9 +25,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/painter.h" #include "ui/filter_icons.h" #include "settings/settings_common.h" +#include "core/application.h" #include "lang/lang_keys.h" #include "apiwrap.h" -#include "app.h" #include "styles/style_settings.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -575,7 +575,7 @@ Folders::Folders( } Folders::~Folders() { - if (!App::quitting()) { + if (!Core::Quitting()) { _save(); } } diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 43bf1e9ecb..9d8b2d6ba8 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -37,9 +37,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_controller.h" #include "window/window_session_controller.h" #include "core/click_handler_types.h" +#include "core/application.h" #include "base/call_delayed.h" #include "facades.h" -#include "app.h" #include "styles/style_settings.h" #include "base/platform/base_platform_info.h" @@ -230,7 +230,7 @@ void SetupInterfaceScale( const auto confirmed = crl::guard(button, [=] { cSetConfigScale(scale); Local::writeSettings(); - App::restart(); + Core::Restart(); }); const auto cancelled = crl::guard(button, [=] { base::call_delayed( diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 9f67302b20..c981ba19c7 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "mainwidget.h" // session->content()->windowShown(). #include "facades.h" -#include "app.h" #include "styles/style_widgets.h" #include "styles/style_window.h" @@ -362,7 +361,7 @@ Window::SessionController *MainWindow::sessionController() const { } bool MainWindow::hideNoQuit() { - if (App::quitting()) { + if (Core::Quitting()) { return false; } const auto workMode = Core::App().settings().workMode(); @@ -516,7 +515,7 @@ void MainWindow::showFromTray() { } void MainWindow::quitFromTray() { - App::quit(); + Core::Quit(); } void MainWindow::activate() { @@ -804,7 +803,7 @@ void MainWindow::updateControlsGeometry() { } void MainWindow::updateUnreadCounter() { - if (App::quitting()) { + if (Core::Quitting()) { return; } @@ -894,7 +893,9 @@ void MainWindow::savePosition(Qt::WindowState state) { } bool MainWindow::minimizeToTray() { - if (App::quitting() || !hasTrayIcon()) return false; + if (Core::Quitting() || !hasTrayIcon()) { + return false; + } closeWithoutDestroy(); controller().updateIsActiveBlur(); diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index a319a15f9e..70a886ddd5 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -27,6 +27,7 @@ class PlainShadow; namespace Core { struct WindowPosition; +enum class QuitReason; } // namespace Core namespace Window { @@ -137,6 +138,10 @@ public: updateGlobalMenuHook(); } + [[nodiscard]] virtual bool preventsQuit(Core::QuitReason reason) { + return false; + } + protected: void leaveEventHook(QEvent *e) override; diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index f2fcbb5d27..e985be5341 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_domain.h" #include "ui/text/text_utilities.h" #include "facades.h" -#include "app.h" #include @@ -174,7 +173,7 @@ System::SkipState System::computeSkipState( bool showForMuted) const { const auto history = item->history(); const auto notifyBy = item->specialNotificationPeer(); - if (App::quitting()) { + if (Core::Quitting()) { return { SkipState::Skip }; } else if (!Core::App().settings().notifyFromAll() && &history->session().account() != &Core::App().domain().active()) { @@ -432,7 +431,7 @@ void System::showGrouped() { void System::showNext() { Expects(_manager != nullptr); - if (App::quitting()) { + if (Core::Quitting()) { return; } diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 7e306f06c2..f30802fb31 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -52,7 +52,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_changes.h" #include "mainwidget.h" -#include "app.h" #include "styles/style_window.h" #include "styles/style_widgets.h" #include "styles/style_dialogs.h" @@ -1214,7 +1213,7 @@ void MainMenu::initResetScaleButton() { _resetScaleButton->addClickHandler([] { cSetConfigScale(style::kScaleDefault); Local::writeSettings(); - App::restart(); + Core::Restart(); }); _resetScaleButton->show(); updateControlsGeometry(); diff --git a/Telegram/lib_base b/Telegram/lib_base index 136d2eb5bc..fdd2714a2a 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit 136d2eb5bc0e26774bcf2611e0a4ac46dfb73388 +Subproject commit fdd2714a2ae0a42ff1ee06c4ae6815a3fd575a2e