mirror of https://github.com/procxx/kepka.git
Refactored counting idle time.
- psIdleTime() was replaced with Platform::LastUserInputTime(). - _lastTimeVideoPlayedAt was moved to Application as _lastNonIdleTime. - Call of updateNonIdle() was added while voice is recording. - Fixed #5695. - Thanks Preston. =)
This commit is contained in:
parent
9dc9e019f6
commit
78d00bcf22
|
@ -483,11 +483,9 @@ void AuthSession::checkAutoLock() {
|
|||
}
|
||||
|
||||
Core::App().checkLocalTime();
|
||||
auto now = crl::now();
|
||||
auto shouldLockInMs = Global::AutoLock() * 1000LL;
|
||||
auto idleForMs = psIdleTime();
|
||||
auto notPlayingVideoForMs = now - settings().lastTimeVideoPlayedAt();
|
||||
auto checkTimeMs = qMin(idleForMs, notPlayingVideoForMs);
|
||||
const auto now = crl::now();
|
||||
const auto shouldLockInMs = Global::AutoLock() * 1000LL;
|
||||
const auto checkTimeMs = now - Core::App().lastNonIdleTime();
|
||||
if (checkTimeMs >= shouldLockInMs || (_shouldLockAt > 0 && now > _shouldLockAt + kAutoLockTimeoutLateMs)) {
|
||||
Core::App().lockByPasscode();
|
||||
} else {
|
||||
|
|
|
@ -139,12 +139,6 @@ public:
|
|||
bool smallDialogsList() const {
|
||||
return _variables.smallDialogsList;
|
||||
}
|
||||
void setLastTimeVideoPlayedAt(crl::time time) {
|
||||
_lastTimeVideoPlayedAt = time;
|
||||
}
|
||||
crl::time lastTimeVideoPlayedAt() const {
|
||||
return _lastTimeVideoPlayedAt;
|
||||
}
|
||||
void setSoundOverride(const QString &key, const QString &path) {
|
||||
_variables.soundOverrides.insert(key, path);
|
||||
}
|
||||
|
@ -263,7 +257,6 @@ private:
|
|||
rpl::event_stream<bool> _tabbedReplacedWithInfoValue;
|
||||
|
||||
Variables _variables;
|
||||
crl::time _lastTimeVideoPlayedAt = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -841,6 +841,14 @@ bool Application::passcodeLocked() const {
|
|||
return _passcodeLock.current();
|
||||
}
|
||||
|
||||
void Application::updateNonIdle() {
|
||||
_lastNonIdleTime = crl::now();
|
||||
}
|
||||
|
||||
crl::time Application::lastNonIdleTime() const {
|
||||
return std::max(Platform::LastUserInputTime(), _lastNonIdleTime);
|
||||
}
|
||||
|
||||
rpl::producer<bool> Application::passcodeLockChanges() const {
|
||||
return _passcodeLock.changes();
|
||||
}
|
||||
|
|
|
@ -184,6 +184,9 @@ public:
|
|||
rpl::producer<bool> lockChanges() const;
|
||||
rpl::producer<bool> lockValue() const;
|
||||
|
||||
[[nodiscard]] crl::time lastNonIdleTime() const;
|
||||
void updateNonIdle();
|
||||
|
||||
void registerLeaveSubscription(QWidget *widget);
|
||||
void unregisterLeaveSubscription(QWidget *widget);
|
||||
|
||||
|
@ -282,6 +285,8 @@ private:
|
|||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
crl::time _lastNonIdleTime = 0;
|
||||
|
||||
};
|
||||
|
||||
Application &App();
|
||||
|
|
|
@ -1241,6 +1241,7 @@ void HistoryWidget::onRecordUpdate(quint16 level, qint32 samples) {
|
|||
if (samples < 0 || samples >= Media::Player::kDefaultFrequency * AudioVoiceMsgMaxLength) {
|
||||
stopRecording(_peer && samples > 0 && _inField);
|
||||
}
|
||||
Core::App().updateNonIdle();
|
||||
updateField();
|
||||
if (_history) {
|
||||
updateSendAction(_history, SendAction::Type::RecordVoice);
|
||||
|
|
|
@ -3767,7 +3767,7 @@ void MainWidget::updateOnline(bool gotOtherOffline) {
|
|||
bool isOnline = !App::quitting() && App::wnd()->isActive();
|
||||
int updateIn = Global::OnlineUpdatePeriod();
|
||||
if (isOnline) {
|
||||
auto idle = psIdleTime();
|
||||
const auto idle = crl::now() - Platform::LastUserInputTime();
|
||||
if (idle >= Global::OfflineIdleTimeout()) {
|
||||
isOnline = false;
|
||||
if (!_isIdle) {
|
||||
|
@ -3883,7 +3883,7 @@ void MainWidget::writeDrafts(History *history) {
|
|||
}
|
||||
|
||||
void MainWidget::checkIdleFinish() {
|
||||
if (psIdleTime() < Global::OfflineIdleTimeout()) {
|
||||
if (crl::now() - Platform::LastUserInputTime() < Global::OfflineIdleTimeout()) {
|
||||
_idleFinishTimer.cancel();
|
||||
_isIdle = false;
|
||||
updateOnline();
|
||||
|
|
|
@ -2041,7 +2041,7 @@ void OverlayWidget::onVideoPlayProgress(const AudioMsgId &audioId) {
|
|||
if (state.length) {
|
||||
updateVideoPlaybackState(state);
|
||||
}
|
||||
Auth().settings().setLastTimeVideoPlayedAt(crl::now());
|
||||
Core::App().updateNonIdle();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -207,10 +207,6 @@ bool psIdleSupported() {
|
|||
return false;
|
||||
}
|
||||
|
||||
crl::time psIdleTime() {
|
||||
return crl::now() - _lastUserAction;
|
||||
}
|
||||
|
||||
void psActivateProcess(uint64 pid) {
|
||||
// objc_activateProgram();
|
||||
}
|
||||
|
@ -449,6 +445,10 @@ bool OpenSystemSettings(SystemSettingsType type) {
|
|||
return true;
|
||||
}
|
||||
|
||||
crl::time LastUserInputTime() {
|
||||
return _lastUserAction;
|
||||
}
|
||||
|
||||
namespace ThirdParty {
|
||||
|
||||
void start() {
|
||||
|
|
|
@ -33,6 +33,8 @@ inline void ReInitOnTopPanel(QWidget *panel) {
|
|||
|
||||
QString CurrentExecutablePath(int argc, char *argv[]);
|
||||
|
||||
crl::time LastUserInputTime();
|
||||
|
||||
} // namespace Platform
|
||||
|
||||
inline QString psServerPrefix() {
|
||||
|
@ -51,7 +53,6 @@ void psDeleteDir(const QString &dir);
|
|||
|
||||
void psUserActionDone();
|
||||
bool psIdleSupported();
|
||||
crl::time psIdleTime();
|
||||
|
||||
QStringList psInitLogs();
|
||||
void psClearInitLogs();
|
||||
|
|
|
@ -19,6 +19,8 @@ inline bool TranslucentWindowsSupported(QPoint globalPosition) {
|
|||
|
||||
QString CurrentExecutablePath(int argc, char *argv[]);
|
||||
|
||||
crl::time LastUserInputTime();
|
||||
|
||||
void RemoveQuarantine(const QString &path);
|
||||
|
||||
namespace ThirdParty {
|
||||
|
@ -52,7 +54,6 @@ void psDeleteDir(const QString &dir);
|
|||
|
||||
void psUserActionDone();
|
||||
bool psIdleSupported();
|
||||
crl::time psIdleTime();
|
||||
|
||||
QStringList psInitLogs();
|
||||
void psClearInitLogs();
|
||||
|
|
|
@ -104,11 +104,6 @@ bool psIdleSupported() {
|
|||
return objc_idleSupported();
|
||||
}
|
||||
|
||||
crl::time psIdleTime() {
|
||||
auto idleTime = 0LL;
|
||||
return objc_idleTime(idleTime) ? idleTime : (crl::now() - _lastUserAction);
|
||||
}
|
||||
|
||||
QStringList psInitLogs() {
|
||||
return _initLogs;
|
||||
}
|
||||
|
@ -270,6 +265,11 @@ bool OpenSystemSettings(SystemSettingsType type) {
|
|||
return true;
|
||||
}
|
||||
|
||||
crl::time LastUserInputTime() {
|
||||
auto idleTime = 0LL;
|
||||
return objc_idleTime(idleTime) ? (crl::now() - crl::time(idleTime)) : _lastUserAction;
|
||||
}
|
||||
|
||||
} // namespace Platform
|
||||
|
||||
void psNewVersion() {
|
||||
|
|
|
@ -145,12 +145,6 @@ bool psIdleSupported() {
|
|||
return GetLastInputInfo(&lii);
|
||||
}
|
||||
|
||||
crl::time psIdleTime() {
|
||||
LASTINPUTINFO lii;
|
||||
lii.cbSize = sizeof(LASTINPUTINFO);
|
||||
return GetLastInputInfo(&lii) ? (GetTickCount() - lii.dwTime) : (crl::now() - _lastUserAction);
|
||||
}
|
||||
|
||||
QStringList psInitLogs() {
|
||||
return _initLogs;
|
||||
}
|
||||
|
@ -350,6 +344,12 @@ QString CurrentExecutablePath(int argc, char *argv[]) {
|
|||
return QString();
|
||||
}
|
||||
|
||||
crl::time LastUserInputTime() {
|
||||
LASTINPUTINFO lii;
|
||||
lii.cbSize = sizeof(LASTINPUTINFO);
|
||||
return GetLastInputInfo(&lii) ? (crl::now() + lii.dwTime - GetTickCount()) : _lastUserAction;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
QString GetLangCodeById(unsigned lngId) {
|
||||
|
|
|
@ -36,6 +36,8 @@ inline void ReInitOnTopPanel(QWidget *panel) {
|
|||
|
||||
QString CurrentExecutablePath(int argc, char *argv[]);
|
||||
|
||||
crl::time LastUserInputTime();
|
||||
|
||||
namespace ThirdParty {
|
||||
|
||||
inline void start() {
|
||||
|
@ -59,7 +61,6 @@ void psDeleteDir(const QString &dir);
|
|||
|
||||
void psUserActionDone();
|
||||
bool psIdleSupported();
|
||||
crl::time psIdleTime();
|
||||
|
||||
QStringList psInitLogs();
|
||||
void psClearInitLogs();
|
||||
|
|
Loading…
Reference in New Issue