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:
@@ -25,6 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "lang.h"
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
#include "messenger.h"
|
||||
#include "mainwidget.h"
|
||||
#include "historywidget.h"
|
||||
#include "storage/localstorage.h"
|
||||
@@ -46,8 +47,7 @@ constexpr auto kSmallDelayMs = 5;
|
||||
ApiWrap::ApiWrap()
|
||||
: _messageDataResolveDelayed([this] { resolveMessageDatas(); })
|
||||
, _webPagesTimer([this] { resolveWebPages(); })
|
||||
, _draftsSaveTimer([this] { saveDraftsToCloud(); })
|
||||
, _quitSavingDraftsTimer([] { App::allDraftsSaved(); }) {
|
||||
, _draftsSaveTimer([this] { saveDraftsToCloud(); }) {
|
||||
Window::Theme::Background()->start();
|
||||
}
|
||||
|
||||
@@ -985,10 +985,6 @@ void ApiWrap::saveDraftToCloudDelayed(History *history) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ApiWrap::hasUnsavedDrafts() const {
|
||||
return !_draftsSaveRequestIds.isEmpty();
|
||||
}
|
||||
|
||||
void ApiWrap::savePrivacy(const MTPInputPrivacyKey &key, QVector<MTPInputPrivacyRule> &&rules) {
|
||||
auto keyTypeId = key.type();
|
||||
auto it = _privacySaveRequests.find(keyTypeId);
|
||||
@@ -1144,9 +1140,7 @@ void ApiWrap::saveDraftsToCloud() {
|
||||
auto i = _draftsSaveRequestIds.find(history);
|
||||
if (i != _draftsSaveRequestIds.cend() && i.value() == requestId) {
|
||||
_draftsSaveRequestIds.remove(history);
|
||||
if (_draftsSaveRequestIds.isEmpty()) {
|
||||
App::allDraftsSaved(); // can quit the application
|
||||
}
|
||||
checkQuitPreventFinished();
|
||||
}
|
||||
}).fail([this, history](const RPCError &error, mtpRequestId requestId) {
|
||||
if (auto cloudDraft = history->cloudDraft()) {
|
||||
@@ -1157,18 +1151,29 @@ void ApiWrap::saveDraftsToCloud() {
|
||||
auto i = _draftsSaveRequestIds.find(history);
|
||||
if (i != _draftsSaveRequestIds.cend() && i.value() == requestId) {
|
||||
_draftsSaveRequestIds.remove(history);
|
||||
if (_draftsSaveRequestIds.isEmpty()) {
|
||||
App::allDraftsSaved(); // can quit the application
|
||||
}
|
||||
checkQuitPreventFinished();
|
||||
}
|
||||
}).send();
|
||||
|
||||
i.value() = cloudDraft->saveRequestId;
|
||||
}
|
||||
}
|
||||
|
||||
bool ApiWrap::isQuitPrevent() {
|
||||
if (_draftsSaveRequestIds.isEmpty()) {
|
||||
App::allDraftsSaved(); // can quit the application
|
||||
} else if (App::quitting() && !_quitSavingDraftsTimer.isActive()) {
|
||||
_quitSavingDraftsTimer.callOnce(kSaveDraftBeforeQuitTimeout);
|
||||
return false;
|
||||
}
|
||||
LOG(("ApiWrap prevents quit, saving drafts..."));
|
||||
saveDraftsToCloud();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ApiWrap::checkQuitPreventFinished() {
|
||||
if (_draftsSaveRequestIds.isEmpty()) {
|
||||
if (App::quitting()) {
|
||||
LOG(("ApiWrap doesn't prevent quit any more."));
|
||||
}
|
||||
Messenger::Instance().quitPreventFinished();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user