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

Optimize out most of LastUserInputTime() calls.

Fixes #16118.
This commit is contained in:
John Preston
2021-06-18 19:22:36 +04:00
parent 8897f9e46a
commit e1120d1cb5
12 changed files with 53 additions and 32 deletions

View File

@@ -849,7 +849,7 @@ bool Application::passcodeLocked() const {
void Application::updateNonIdle() {
_lastNonIdleTime = crl::now();
if (const auto session = maybeActiveSession()) {
session->updates().checkIdleFinish();
session->updates().checkIdleFinish(_lastNonIdleTime);
}
}
@@ -876,19 +876,21 @@ bool Application::someSessionExists() const {
return false;
}
void Application::checkAutoLock() {
void Application::checkAutoLock(crl::time lastNonIdleTime) {
if (!_domain->local().hasLocalPasscode()
|| passcodeLocked()
|| !someSessionExists()) {
_shouldLockAt = 0;
_autoLockTimer.cancel();
return;
} else if (!lastNonIdleTime) {
lastNonIdleTime = this->lastNonIdleTime();
}
checkLocalTime();
const auto now = crl::now();
const auto shouldLockInMs = _settings.autoLock() * 1000LL;
const auto checkTimeMs = now - lastNonIdleTime();
const auto checkTimeMs = now - lastNonIdleTime;
if (checkTimeMs >= shouldLockInMs || (_shouldLockAt > 0 && now > _shouldLockAt + kAutoLockTimeoutLateMs)) {
_shouldLockAt = 0;
_autoLockTimer.cancel();
@@ -910,7 +912,7 @@ void Application::checkAutoLockIn(crl::time time) {
void Application::localPasscodeChanged() {
_shouldLockAt = 0;
_autoLockTimer.cancel();
checkAutoLock();
checkAutoLock(crl::now());
}
bool Application::hasActiveWindow(not_null<Main::Session*> session) const {