2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Remove app module. Support delayed quit by Cmd+Q on macOS.

This commit is contained in:
John Preston
2022-01-27 15:48:51 +03:00
parent b8f1cebeb6
commit 28f2c213f7
38 changed files with 319 additions and 350 deletions

View File

@@ -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 <QtCore/QMimeDatabase>
#include <QtGui/QGuiApplication>
@@ -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<Main::Session*> 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<Shortcuts::Request*> 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