Added auto-close timer for cloud password management section.

This commit is contained in:
23rd 2022-05-10 02:50:43 +03:00
parent e364b80d0a
commit 2f58a7d3c4
3 changed files with 30 additions and 20 deletions

View file

@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "settings/cloud_password/settings_cloud_password_common.h"
#include "apiwrap.h"
#include "base/timer.h"
#include "core/application.h"
#include "lang/lang_keys.h"
#include "lottie/lottie_icon.h"
#include "main/main_session.h"
@ -98,6 +100,19 @@ BottomButton CreateBottomDisableButton(
};
}
void SetupAutoCloseTimer(rpl::lifetime &lifetime, Fn<void()> callback) {
constexpr auto kTimerCheck = crl::time(1000 * 60);
constexpr auto kAutoCloseTimeout = crl::time(1000 * 60 * 10);
const auto timer = lifetime.make_state<base::Timer>([=] {
const auto idle = crl::now() - Core::App().lastNonIdleTime();
if (idle >= kAutoCloseTimeout) {
callback();
}
});
timer->callEach(kTimerCheck);
}
void SetupHeader(
not_null<Ui::VerticalLayout*> content,
const QString &lottie,

View file

@ -132,17 +132,22 @@ void Manage::setupContent() {
// we should forget the current password.
setStepData(std::move(currentStepData));
const auto state = cloudPassword().stateCurrent();
if (!state) {
const auto quit = [=] {
setStepData(StepData());
showBack();
};
SetupAutoCloseTimer(content->lifetime(), quit);
const auto state = cloudPassword().stateCurrent();
if (!state) {
quit();
return;
}
cloudPassword().state(
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
if (!_requestLifetime && !state.hasPassword) {
setStepData(StepData());
showBack();
quit();
}
}, lifetime());

View file

@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "settings/settings_local_passcode.h"
#include "base/platform/base_platform_last_input.h"
#include "base/timer.h"
#include "boxes/auto_lock_box.h"
#include "core/application.h"
#include "lang/lang_keys.h"
@ -31,9 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Settings {
namespace {
constexpr auto kTimerCheck = crl::time(1000 * 60);
constexpr auto kAutoCloseTimeout = crl::time(1000 * 60 * 10);
void SetPasscode(
not_null<Window::SessionController*> controller,
const QString &pass) {
@ -42,16 +38,6 @@ void SetPasscode(
Core::App().localPasscodeChanged();
}
void SetupAutoCloseTimer(rpl::lifetime &lifetime, Fn<void()> callback) {
const auto timer = lifetime.make_state<base::Timer>([=] {
const auto idle = crl::now() - Core::App().lastNonIdleTime();
if (idle >= kAutoCloseTimeout) {
callback();
}
});
timer->callEach(kTimerCheck);
}
} // namespace
namespace details {
@ -127,7 +113,9 @@ void LocalPasscodeEnter::setupContent() {
}, content->lifetime());
if (isChange) {
SetupAutoCloseTimer(content->lifetime(), [=] { _showBack.fire({}); });
CloudPassword::SetupAutoCloseTimer(
content->lifetime(),
[=] { _showBack.fire({}); });
}
AddSkip(content);
@ -441,7 +429,9 @@ void LocalPasscodeManage::setupContent() {
};
const auto state = content->lifetime().make_state<State>();
SetupAutoCloseTimer(content->lifetime(), [=] { _showBack.fire({}); });
CloudPassword::SetupAutoCloseTimer(
content->lifetime(),
[=] { _showBack.fire({}); });
AddSkip(content);