2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-04 00:25:17 +00:00

Move passcode management from MainWindow.

Check for auto lock in AuthSession. Don't autolock while video plays.
Closes #3219
This commit is contained in:
John Preston
2017-04-15 21:48:54 +03:00
parent e3aacc8072
commit de7c886008
14 changed files with 88 additions and 52 deletions

View File

@@ -108,13 +108,12 @@ MainWindow::MainWindow() {
_inactiveTimer.setSingleShot(true);
connect(&_inactiveTimer, SIGNAL(timeout()), this, SLOT(onInactiveTimer()));
connect(&_autoLockTimer, SIGNAL(timeout()), this, SLOT(checkAutoLock()));
subscribe(Global::RefSelfChanged(), [this] { updateGlobalMenu(); });
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
themeUpdated(data);
});
subscribe(Messenger::Instance().authSessionChanged(), [this] { checkAuthSession(); });
subscribe(Messenger::Instance().passcodedChanged(), [this] { updateGlobalMenu(); });
checkAuthSession();
setAttribute(Qt::WA_NoSystemBackground);
@@ -237,12 +236,8 @@ void MainWindow::clearPasscode() {
if (_intro) {
_intro->showAnimated(bg, true);
} else {
t_assert(_main != nullptr);
_main->showAnimated(bg, true);
}
AuthSession::Current().notifications().updateAll();
updateGlobalMenu();
if (_main) {
_main->checkStartUrl();
}
}
@@ -262,32 +257,6 @@ void MainWindow::setupPasscode() {
} else {
setInnerFocus();
}
_shouldLockAt = 0;
if (AuthSession::Exists()) {
AuthSession::Current().notifications().updateAll();
}
updateGlobalMenu();
}
void MainWindow::checkAutoLockIn(int msec) {
if (_autoLockTimer.isActive()) {
int remain = _autoLockTimer.remainingTime();
if (remain > 0 && remain <= msec) return;
}
_autoLockTimer.start(msec);
}
void MainWindow::checkAutoLock() {
if (!Global::LocalPasscode() || App::passcoded()) return;
App::app()->checkLocalTime();
auto ms = getms(true), idle = psIdleTime(), should = Global::AutoLock() * 1000LL;
if (idle >= should || (_shouldLockAt > 0 && ms > _shouldLockAt + 3000LL)) {
setupPasscode();
} else {
_shouldLockAt = ms + (should - idle);
_autoLockTimer.start(should - idle);
}
}
void MainWindow::setupIntro() {