mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added auto-close timer for cloud password management section.
This commit is contained in:
parent
e364b80d0a
commit
2f58a7d3c4
3 changed files with 30 additions and 20 deletions
|
@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "settings/cloud_password/settings_cloud_password_common.h"
|
#include "settings/cloud_password/settings_cloud_password_common.h"
|
||||||
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "base/timer.h"
|
||||||
|
#include "core/application.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "lottie/lottie_icon.h"
|
#include "lottie/lottie_icon.h"
|
||||||
#include "main/main_session.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(
|
void SetupHeader(
|
||||||
not_null<Ui::VerticalLayout*> content,
|
not_null<Ui::VerticalLayout*> content,
|
||||||
const QString &lottie,
|
const QString &lottie,
|
||||||
|
|
|
@ -132,17 +132,22 @@ void Manage::setupContent() {
|
||||||
// we should forget the current password.
|
// we should forget the current password.
|
||||||
setStepData(std::move(currentStepData));
|
setStepData(std::move(currentStepData));
|
||||||
|
|
||||||
const auto state = cloudPassword().stateCurrent();
|
const auto quit = [=] {
|
||||||
if (!state) {
|
|
||||||
setStepData(StepData());
|
setStepData(StepData());
|
||||||
showBack();
|
showBack();
|
||||||
|
};
|
||||||
|
|
||||||
|
SetupAutoCloseTimer(content->lifetime(), quit);
|
||||||
|
|
||||||
|
const auto state = cloudPassword().stateCurrent();
|
||||||
|
if (!state) {
|
||||||
|
quit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cloudPassword().state(
|
cloudPassword().state(
|
||||||
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
||||||
if (!_requestLifetime && !state.hasPassword) {
|
if (!_requestLifetime && !state.hasPassword) {
|
||||||
setStepData(StepData());
|
quit();
|
||||||
showBack();
|
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "settings/settings_local_passcode.h"
|
#include "settings/settings_local_passcode.h"
|
||||||
|
|
||||||
#include "base/platform/base_platform_last_input.h"
|
#include "base/platform/base_platform_last_input.h"
|
||||||
#include "base/timer.h"
|
|
||||||
#include "boxes/auto_lock_box.h"
|
#include "boxes/auto_lock_box.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
@ -31,9 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kTimerCheck = crl::time(1000 * 60);
|
|
||||||
constexpr auto kAutoCloseTimeout = crl::time(1000 * 60 * 10);
|
|
||||||
|
|
||||||
void SetPasscode(
|
void SetPasscode(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const QString &pass) {
|
const QString &pass) {
|
||||||
|
@ -42,16 +38,6 @@ void SetPasscode(
|
||||||
Core::App().localPasscodeChanged();
|
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
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
@ -127,7 +113,9 @@ void LocalPasscodeEnter::setupContent() {
|
||||||
}, content->lifetime());
|
}, content->lifetime());
|
||||||
|
|
||||||
if (isChange) {
|
if (isChange) {
|
||||||
SetupAutoCloseTimer(content->lifetime(), [=] { _showBack.fire({}); });
|
CloudPassword::SetupAutoCloseTimer(
|
||||||
|
content->lifetime(),
|
||||||
|
[=] { _showBack.fire({}); });
|
||||||
}
|
}
|
||||||
|
|
||||||
AddSkip(content);
|
AddSkip(content);
|
||||||
|
@ -441,7 +429,9 @@ void LocalPasscodeManage::setupContent() {
|
||||||
};
|
};
|
||||||
const auto state = content->lifetime().make_state<State>();
|
const auto state = content->lifetime().make_state<State>();
|
||||||
|
|
||||||
SetupAutoCloseTimer(content->lifetime(), [=] { _showBack.fire({}); });
|
CloudPassword::SetupAutoCloseTimer(
|
||||||
|
content->lifetime(),
|
||||||
|
[=] { _showBack.fire({}); });
|
||||||
|
|
||||||
AddSkip(content);
|
AddSkip(content);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue