2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 22:46:10 +00:00

Add upload cancel confirmation on Quit and Log Out.

This commit is contained in:
John Preston
2022-01-26 12:41:27 +03:00
parent 8c349c0515
commit 6a3ad52aef
13 changed files with 195 additions and 48 deletions

View File

@@ -639,6 +639,24 @@ void Application::logout(Main::Account *account) {
}
}
void Application::logoutWithChecks(Main::Account *account) {
const auto weak = base::make_weak(account);
const auto retry = [=] {
if (const auto account = weak.get()) {
logoutWithChecks(account);
}
};
if (!account || !account->sessionExists()) {
logout(account);
} else if (_exportManager->inProgress(&account->session())) {
_exportManager->stopWithConfirmation(retry);
} else if (account->session().uploadsInProgress()) {
account->session().uploadsStopWithConfirmation(retry);
} else {
logout(account);
}
}
void Application::forceLogOut(
not_null<Main::Account*> account,
const TextWithEntities &explanation) {
@@ -749,6 +767,33 @@ bool Application::exportPreventsQuit() {
return false;
}
bool Application::uploadPreventsQuit() {
if (!_domain->started()) {
return false;
}
for (const auto &[index, account] : _domain->accounts()) {
if (!account->sessionExists()) {
continue;
}
if (account->session().uploadsInProgress()) {
account->session().uploadsStopWithConfirmation([=] {
for (const auto &[index, account] : _domain->accounts()) {
if (account->sessionExists()) {
account->session().uploadsStop();
}
}
App::quit();
});
return true;
}
}
return false;
}
bool Application::preventsQuit() {
return exportPreventsQuit() || uploadPreventsQuit();
}
int Application::unreadBadge() const {
return _domain->unreadBadge();
}