2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Try to hangup current call when quitting the app.

This commit is contained in:
John Preston
2017-04-29 23:06:32 +03:00
parent 29fc69ebaa
commit e050e270fc
8 changed files with 92 additions and 32 deletions

View File

@@ -20,12 +20,15 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#include "messenger.h"
#include "base/timer.h"
#include "storage/localstorage.h"
#include "platform/platform_specific.h"
#include "mainwindow.h"
#include "application.h"
#include "shortcuts.h"
#include "auth_session.h"
#include "apiwrap.h"
#include "calls/calls_instance.h"
#include "langloaderplain.h"
#include "observer_peer.h"
#include "storage/file_upload.h"
@@ -42,6 +45,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace {
constexpr auto kQuitPreventTimeoutMs = 1500;
Messenger *SingleInstance = nullptr;
} // namespace
@@ -55,6 +60,7 @@ struct Messenger::Private {
std::unique_ptr<Local::StoredAuthSession> storedAuthSession;
MTP::Instance::Config mtpConfig;
MTP::AuthKeysList mtpKeysToDestroy;
base::Timer quitTimer;
};
Messenger::Messenger() : QObject()
@@ -791,3 +797,33 @@ QPoint Messenger::getPointForCallPanelCenter() const {
}
return _window->windowHandle()->screen()->geometry().center();
}
void Messenger::QuitAttempt() {
auto prevents = false;
if (!Sandbox::isSavingSession() && AuthSession::Exists()) {
if (AuthSession::Current().api().isQuitPrevent()) {
prevents = true;
}
if (AuthSession::Current().calls().isQuitPrevent()) {
prevents = true;
}
}
if (prevents) {
Instance().quitDelayed();
} else {
QCoreApplication::quit();
}
}
void Messenger::quitPreventFinished() {
if (App::quitting()) {
QuitAttempt();
}
}
void Messenger::quitDelayed() {
if (!_private->quitTimer.isActive()) {
_private->quitTimer.setCallback([] { QCoreApplication::quit(); });
_private->quitTimer.callOnce(kQuitPreventTimeoutMs);
}
}