diff --git a/Telegram/SourceFiles/_other/updater.cpp b/Telegram/SourceFiles/_other/updater.cpp index 7050e9bf30..f70e65ca87 100644 --- a/Telegram/SourceFiles/_other/updater.cpp +++ b/Telegram/SourceFiles/_other/updater.cpp @@ -456,7 +456,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara ShellExecute(0, 0, (updateTo + L"Telegram.exe").c_str(), (L"-noupdate" + targs).c_str(), 0, SW_SHOWNORMAL); } - writeLog(L"Executed Telegram.exe, closing log and quiting.."); + writeLog(L"Executed Telegram.exe, closing log and quitting.."); closeLog(); return 0; diff --git a/Telegram/SourceFiles/_other/updater_linux.cpp b/Telegram/SourceFiles/_other/updater_linux.cpp index 3a3b778105..7ae72c3709 100644 --- a/Telegram/SourceFiles/_other/updater_linux.cpp +++ b/Telegram/SourceFiles/_other/updater_linux.cpp @@ -430,7 +430,7 @@ int main(int argc, char *argv[]) { case 0: execv(path, args); return 1; } - writeLog("Executed Telegram, closing log and quiting.."); + writeLog("Executed Telegram, closing log and quitting.."); closeLog(); return 0; diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index d434bc26ea..85a4000aca 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -33,7 +33,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "numbers.h" namespace { - bool quiting = false; + App::LaunchState _launchState = App::Launched; UserData *self = 0; @@ -1791,7 +1791,7 @@ namespace App { } ::repliesTo.erase(j); } - if (App::main() && !App::quiting()) { + if (App::main() && !App::quitting()) { App::main()->itemRemoved(item); } } @@ -2155,21 +2155,22 @@ namespace App { } void quit() { - if (quiting()) return; + if (quitting()) return; + setLaunchState(QuitRequested); - setQuiting(); - if (wnd()) { - wnd()->quit(); - } Application::quit(); } - bool quiting() { - return ::quiting; + bool quitting() { + return _launchState != Launched; } - void setQuiting() { - ::quiting = true; + LaunchState launchState() { + return _launchState; + } + + void setLaunchState(LaunchState state) { + _launchState = state; } QImage readImage(QByteArray data, QByteArray *format, bool opaque, bool *animated) { diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index b206d462e4..20e51a806e 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -191,9 +191,15 @@ namespace App { bool isValidPhone(QString phone); + enum LaunchState { + Launched = 0, + QuitRequested = 1, + QuitProcessed = 2, + }; void quit(); - bool quiting(); - void setQuiting(); + bool quitting(); + LaunchState launchState(); + void setLaunchState(LaunchState state); QImage readImage(QByteArray data, QByteArray *format = 0, bool opaque = true, bool *animated = 0); QImage readImage(const QString &file, QByteArray *format = 0, bool opaque = true, bool *animated = 0, QByteArray *content = 0); diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 2d3bc56f1a..150e41b25d 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -166,16 +166,16 @@ void Application::socketReading() { if (QRegularExpression("RES:(\\d+);").match(_localSocketReadData).hasMatch()) { uint64 pid = _localSocketReadData.mid(4, _localSocketReadData.length() - 5).toULongLong(); psActivateProcess(pid); - LOG(("Show command response received, pid = %1, activating and quiting..").arg(pid)); + LOG(("Show command response received, pid = %1, activating and quitting..").arg(pid)); return App::quit(); } } void Application::socketError(QLocalSocket::LocalSocketError e) { - if (App::quiting()) return; + if (App::quitting()) return; if (_secondInstance) { - LOG(("Could not write show command, error %1, quiting..").arg(e)); + LOG(("Could not write show command, error %1, quitting..").arg(e)); return App::quit(); } @@ -235,7 +235,7 @@ void Application::singleInstanceChecked() { void Application::socketDisconnected() { if (_secondInstance) { - DEBUG_LOG(("Application Error: socket disconnected before command response received, quiting..")); + DEBUG_LOG(("Application Error: socket disconnected before command response received, quitting..")); return App::quit(); } } @@ -314,14 +314,15 @@ void Application::removeClients() { } void Application::startApplication() { - if (App::quiting()) { + if (App::quitting()) { quit(); } } void Application::closeApplication() { + if (App::launchState() != App::QuitProcessed); + App::setLaunchState(App::QuitProcessed); App::quit(); - delete AppObject; AppObject = 0; @@ -973,7 +974,7 @@ void AppClass::onSwitchTestMode() { } FileUploader *AppClass::uploader() { - if (!_uploader && !App::quiting()) _uploader = new FileUploader(); + if (!_uploader && !App::quitting()) _uploader = new FileUploader(); return _uploader; } diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index a32ba4bc87..37e5fdaf30 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -154,7 +154,7 @@ namespace Ui { } bool hideWindowNoQuit() { - if (!App::quiting()) { + if (!App::quitting()) { if (Window *w = App::wnd()) { if (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray) { return w->minimizeToTray(); diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 88db017feb..412bb0735a 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -2526,7 +2526,7 @@ void History::clear(bool leaveItems) { } overview[i].clear(); overviewIds[i].clear(); - if (App::wnd() && !App::quiting()) App::wnd()->mediaOverviewUpdated(peer, MediaOverviewType(i)); + if (App::wnd() && !App::quitting()) App::wnd()->mediaOverviewUpdated(peer, MediaOverviewType(i)); } } Blocks lst = blocks; diff --git a/Telegram/SourceFiles/window.cpp b/Telegram/SourceFiles/window.cpp index 3431edfd51..ba6f86229d 100644 --- a/Telegram/SourceFiles/window.cpp +++ b/Telegram/SourceFiles/window.cpp @@ -1105,7 +1105,7 @@ void Window::mouseReleaseEvent(QMouseEvent *e) { } bool Window::minimizeToTray() { - if (App::quiting() || !psHasTrayIcon()) return false; + if (App::quitting() || !psHasTrayIcon()) return false; hide(); if (cPlatform() == dbipWindows && trayIcon && !cSeenTrayTooltip()) { @@ -1372,16 +1372,8 @@ void Window::onClearFailed(int task, void *manager) { emit tempDirClearFailed(task); } -void Window::quit() { - delete _mediaView; - _mediaView = 0; - delete main; - main = 0; - notifyClearFast(); -} - void Window::notifySchedule(History *history, HistoryItem *item) { - if (App::quiting() || !history->currentNotification() || !main) return; + if (App::quitting() || !history->currentNotification() || !main) return; PeerData *notifyByFrom = (!history->peer->isUser() && item->mentionsMe()) ? item->from() : 0; @@ -1514,7 +1506,7 @@ void Window::notifySettingGot() { } void Window::notifyShowNext(NotifyWindow *remove) { - if (App::quiting()) return; + if (App::quitting()) return; int32 count = NotifyWindowsCount; if (remove) { diff --git a/Telegram/SourceFiles/window.h b/Telegram/SourceFiles/window.h index ab34c00d92..774a232960 100644 --- a/Telegram/SourceFiles/window.h +++ b/Telegram/SourceFiles/window.h @@ -206,8 +206,6 @@ public: TempDirState localStorageState(); void tempDirDelete(int task); - void quit(); - void notifySettingGot(); void notifySchedule(History *history, HistoryItem *item); void notifyClear(History *history = 0);