diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index b777cd25f..f5c58d105 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -1079,7 +1079,7 @@ void Application::QuitAttempt() { if (!IsAppLaunched() || Sandbox::Instance().isSavingSession() || App().readyToQuit()) { - QApplication::quit(); + Sandbox::QuitWhenStarted(); } } @@ -1115,7 +1115,7 @@ void Application::quitPreventFinished() { void Application::quitDelayed() { if (!_private->quitTimer.isActive()) { - _private->quitTimer.setCallback([] { QApplication::quit(); }); + _private->quitTimer.setCallback([] { Sandbox::QuitWhenStarted(); }); _private->quitTimer.callOnce(kQuitPreventTimeoutMs); } } diff --git a/Telegram/SourceFiles/core/sandbox.cpp b/Telegram/SourceFiles/core/sandbox.cpp index 440ff3547..a113e88aa 100644 --- a/Telegram/SourceFiles/core/sandbox.cpp +++ b/Telegram/SourceFiles/core/sandbox.cpp @@ -78,6 +78,8 @@ QString _escapeFrom7bit(const QString &str) { } // namespace +bool Sandbox::QuitOnStartRequested = false; + Sandbox::Sandbox( not_null launcher, int &argc, @@ -155,9 +157,22 @@ int Sandbox::start() { _localSocket.connectToServer(_localServerName); } + if (QuitOnStartRequested) { + closeApplication(); + return 0; + } + _started = true; return exec(); } +void Sandbox::QuitWhenStarted() { + if (!QApplication::instance() || !Instance()._started) { + QuitOnStartRequested = true; + } else { + quit(); + } +} + void Sandbox::launchApplication() { InvokeQueued(this, [=] { if (App::quitting()) { diff --git a/Telegram/SourceFiles/core/sandbox.h b/Telegram/SourceFiles/core/sandbox.h index 58b17d187..7362f5554 100644 --- a/Telegram/SourceFiles/core/sandbox.h +++ b/Telegram/SourceFiles/core/sandbox.h @@ -60,6 +60,7 @@ public: return *static_cast(QCoreApplication::instance()); } + static void QuitWhenStarted(); ~Sandbox(); @@ -119,6 +120,8 @@ private: QLocalSocket _localSocket; LocalClients _localClients; bool _secondInstance = false; + bool _started = false; + static bool QuitOnStartRequested; std::unique_ptr _updateChecker;