Fix starting with a passcode.

This commit is contained in:
John Preston 2020-06-16 14:09:16 +04:00
parent bc144377c0
commit ba103fdd40
2 changed files with 38 additions and 36 deletions

View file

@ -489,8 +489,8 @@ void Application::checkLocalTime() {
base::ConcurrentTimerEnvironment::Adjust(); base::ConcurrentTimerEnvironment::Adjust();
base::unixtime::http_invalidate(); base::unixtime::http_invalidate();
} }
if (activeAccount().sessionExists()) { if (const auto session = maybeActiveSession()) {
activeAccount().session().updates().checkLastUpdate(adjusted); session->updates().checkLastUpdate(adjusted);
} }
} }
@ -575,27 +575,36 @@ Main::Account &Application::activeAccount() const {
return _accounts->active(); return _accounts->active();
} }
Main::Session *Application::maybeActiveSession() const {
return (_accounts->started() && activeAccount().sessionExists())
? &activeAccount().session()
: nullptr;
}
bool Application::exportPreventsQuit() { bool Application::exportPreventsQuit() {
if (!activeAccount().sessionExists() if (const auto session = maybeActiveSession()) {
|| !activeAccount().session().data().exportInProgress()) { if (session->data().exportInProgress()) {
return false; session->data().stopExportWithConfirmation([] {
}
activeAccount().session().data().stopExportWithConfirmation([] {
App::quit(); App::quit();
}); });
return true; return true;
}
}
return false;
} }
int Application::unreadBadge() const { int Application::unreadBadge() const {
return (accounts().started() && activeAccount().sessionExists()) if (const auto session = maybeActiveSession()) {
? activeAccount().session().data().unreadBadge() return session->data().unreadBadge();
: 0; }
return 0;
} }
bool Application::unreadBadgeMuted() const { bool Application::unreadBadgeMuted() const {
return (accounts().started() && activeAccount().sessionExists()) if (const auto session = maybeActiveSession()) {
? activeAccount().session().data().unreadBadgeMuted() return session->data().unreadBadgeMuted();
: false; }
return false;
} }
bool Application::offerLegacyLangPackSwitch() const { bool Application::offerLegacyLangPackSwitch() const {
@ -678,9 +687,8 @@ bool Application::openCustomUrl(
return false; return false;
} }
const auto command = urlTrimmed.midRef(protocol.size(), 8192); const auto command = urlTrimmed.midRef(protocol.size(), 8192);
const auto session = activeAccount().sessionExists() const auto session = maybeActiveSession();
? &activeAccount().session()
: nullptr;
using namespace qthelp; using namespace qthelp;
const auto options = RegExOption::CaseInsensitive; const auto options = RegExOption::CaseInsensitive;
for (const auto &[expression, handler] : handlers) { for (const auto &[expression, handler] : handlers) {
@ -716,8 +724,8 @@ bool Application::passcodeLocked() const {
void Application::updateNonIdle() { void Application::updateNonIdle() {
_lastNonIdleTime = crl::now(); _lastNonIdleTime = crl::now();
if (activeAccount().sessionExists()) { if (const auto session = maybeActiveSession()) {
activeAccount().session().updates().checkIdleFinish(); session->updates().checkIdleFinish();
} }
} }
@ -945,24 +953,17 @@ void Application::refreshGlobalProxy() {
void Application::QuitAttempt() { void Application::QuitAttempt() {
auto prevents = false; auto prevents = false;
if (IsAppLaunched() if (IsAppLaunched() && !Sandbox::Instance().isSavingSession()) {
&& App().activeAccount().sessionExists() if (const auto session = App().maybeActiveSession()) {
&& !Sandbox::Instance().isSavingSession()) { if (session->updates().isQuitPrevent()
if (App().activeAccount().session().updates().isQuitPrevent()) { || session->api().isQuitPrevent()
prevents = true; || session->calls().isQuitPrevent()) {
}
if (App().activeAccount().session().api().isQuitPrevent()) {
prevents = true;
}
if (App().activeAccount().session().calls().isQuitPrevent()) {
prevents = true;
}
}
if (prevents) {
App().quitDelayed(); App().quitDelayed();
} else { return;
QApplication::quit();
} }
}
}
QApplication::quit();
} }
void Application::quitPreventFinished() { void Application::quitPreventFinished() {

View file

@ -160,6 +160,7 @@ public:
[[nodiscard]] bool exportPreventsQuit(); [[nodiscard]] bool exportPreventsQuit();
// Main::Session component. // Main::Session component.
Main::Session *maybeActiveSession() const;
[[nodiscard]] int unreadBadge() const; [[nodiscard]] int unreadBadge() const;
[[nodiscard]] bool unreadBadgeMuted() const; [[nodiscard]] bool unreadBadgeMuted() const;