mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Move autolock checking to Core::Application.
This commit is contained in:
parent
4b354b0928
commit
27af83267e
9 changed files with 63 additions and 62 deletions
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
|
#include "core/application.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui/widgets/checkbox.h"
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
|
@ -45,6 +46,6 @@ void AutoLockBox::durationChanged(int seconds) {
|
||||||
Local::writeUserSettings();
|
Local::writeUserSettings();
|
||||||
Global::RefLocalPasscodeChanged().notify();
|
Global::RefLocalPasscodeChanged().notify();
|
||||||
|
|
||||||
_session->checkAutoLock();
|
Core::App().checkAutoLock();
|
||||||
closeBox();
|
closeBox();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "core/application.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/input_fields.h"
|
#include "ui/widgets/input_fields.h"
|
||||||
|
@ -519,7 +520,7 @@ void PasscodeBox::save(bool force) {
|
||||||
const auto weak = Ui::MakeWeak(this);
|
const auto weak = Ui::MakeWeak(this);
|
||||||
cSetPasscodeBadTries(0);
|
cSetPasscodeBadTries(0);
|
||||||
Local::setPasscode(pwd.toUtf8());
|
Local::setPasscode(pwd.toUtf8());
|
||||||
_session->localPasscodeChanged();
|
Core::App().localPasscodeChanged();
|
||||||
if (weak) {
|
if (weak) {
|
||||||
closeBox();
|
closeBox();
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kQuitPreventTimeoutMs = 1500;
|
constexpr auto kQuitPreventTimeoutMs = crl::time(1500);
|
||||||
|
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -99,12 +100,18 @@ Application::Application(not_null<Launcher*> launcher)
|
||||||
, _emojiKeywords(std::make_unique<ChatHelpers::EmojiKeywords>())
|
, _emojiKeywords(std::make_unique<ChatHelpers::EmojiKeywords>())
|
||||||
, _audio(std::make_unique<Media::Audio::Instance>())
|
, _audio(std::make_unique<Media::Audio::Instance>())
|
||||||
, _logo(Window::LoadLogo())
|
, _logo(Window::LoadLogo())
|
||||||
, _logoNoMargin(Window::LoadLogoNoMargin()) {
|
, _logoNoMargin(Window::LoadLogoNoMargin())
|
||||||
|
, _autoLockTimer([=] { checkAutoLock(); }) {
|
||||||
Expects(!_logo.isNull());
|
Expects(!_logo.isNull());
|
||||||
Expects(!_logoNoMargin.isNull());
|
Expects(!_logoNoMargin.isNull());
|
||||||
|
|
||||||
Ui::Integration::Set(&_private->uiIntegration);
|
Ui::Integration::Set(&_private->uiIntegration);
|
||||||
|
|
||||||
|
passcodeLockChanges(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
_shouldLockAt = 0;
|
||||||
|
}, _lifetime);
|
||||||
|
|
||||||
activeAccount().sessionChanges(
|
activeAccount().sessionChanges(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (_mediaView) {
|
if (_mediaView) {
|
||||||
|
@ -697,6 +704,43 @@ void Application::lockByTerms(const Window::TermsLock &data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::checkAutoLock() {
|
||||||
|
if (!Global::LocalPasscode()
|
||||||
|
|| passcodeLocked()
|
||||||
|
|| !_account->sessionExists()) {
|
||||||
|
_shouldLockAt = 0;
|
||||||
|
_autoLockTimer.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkLocalTime();
|
||||||
|
const auto now = crl::now();
|
||||||
|
const auto shouldLockInMs = Global::AutoLock() * 1000LL;
|
||||||
|
const auto checkTimeMs = now - lastNonIdleTime();
|
||||||
|
if (checkTimeMs >= shouldLockInMs || (_shouldLockAt > 0 && now > _shouldLockAt + kAutoLockTimeoutLateMs)) {
|
||||||
|
_shouldLockAt = 0;
|
||||||
|
_autoLockTimer.cancel();
|
||||||
|
lockByPasscode();
|
||||||
|
} else {
|
||||||
|
_shouldLockAt = now + (shouldLockInMs - checkTimeMs);
|
||||||
|
_autoLockTimer.callOnce(shouldLockInMs - checkTimeMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::checkAutoLockIn(crl::time time) {
|
||||||
|
if (_autoLockTimer.isActive()) {
|
||||||
|
auto remain = _autoLockTimer.remainingTime();
|
||||||
|
if (remain > 0 && remain <= time) return;
|
||||||
|
}
|
||||||
|
_autoLockTimer.callOnce(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::localPasscodeChanged() {
|
||||||
|
_shouldLockAt = 0;
|
||||||
|
_autoLockTimer.cancel();
|
||||||
|
checkAutoLock();
|
||||||
|
}
|
||||||
|
|
||||||
void Application::unlockTerms() {
|
void Application::unlockTerms() {
|
||||||
if (_termsLock) {
|
if (_termsLock) {
|
||||||
_termsLock = nullptr;
|
_termsLock = nullptr;
|
||||||
|
|
|
@ -199,6 +199,10 @@ public:
|
||||||
rpl::producer<bool> lockChanges() const;
|
rpl::producer<bool> lockChanges() const;
|
||||||
rpl::producer<bool> lockValue() const;
|
rpl::producer<bool> lockValue() const;
|
||||||
|
|
||||||
|
void checkAutoLock();
|
||||||
|
void checkAutoLockIn(crl::time time);
|
||||||
|
void localPasscodeChanged();
|
||||||
|
|
||||||
[[nodiscard]] crl::time lastNonIdleTime() const;
|
[[nodiscard]] crl::time lastNonIdleTime() const;
|
||||||
void updateNonIdle();
|
void updateNonIdle();
|
||||||
|
|
||||||
|
@ -288,6 +292,9 @@ private:
|
||||||
rpl::event_stream<bool> _termsLockChanges;
|
rpl::event_stream<bool> _termsLockChanges;
|
||||||
std::unique_ptr<Window::TermsLock> _termsLock;
|
std::unique_ptr<Window::TermsLock> _termsLock;
|
||||||
|
|
||||||
|
crl::time _shouldLockAt = 0;
|
||||||
|
base::Timer _autoLockTimer;
|
||||||
|
|
||||||
base::Timer _saveSettingsTimer;
|
base::Timer _saveSettingsTimer;
|
||||||
|
|
||||||
struct LeaveSubscription {
|
struct LeaveSubscription {
|
||||||
|
|
|
@ -35,7 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Main {
|
namespace Main {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
|
|
||||||
constexpr auto kLegacyCallsPeerToPeerNobody = 4;
|
constexpr auto kLegacyCallsPeerToPeerNobody = 4;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -47,7 +46,6 @@ Session::Session(
|
||||||
: _account(account)
|
: _account(account)
|
||||||
, _settings(std::move(settings))
|
, _settings(std::move(settings))
|
||||||
, _saveSettingsTimer([=] { Local::writeUserSettings(); })
|
, _saveSettingsTimer([=] { Local::writeUserSettings(); })
|
||||||
, _autoLockTimer([=] { checkAutoLock(); })
|
|
||||||
, _api(std::make_unique<ApiWrap>(this))
|
, _api(std::make_unique<ApiWrap>(this))
|
||||||
, _calls(std::make_unique<Calls::Instance>(this))
|
, _calls(std::make_unique<Calls::Instance>(this))
|
||||||
, _downloader(std::make_unique<Storage::DownloadManagerMtproto>(_api.get()))
|
, _downloader(std::make_unique<Storage::DownloadManagerMtproto>(_api.get()))
|
||||||
|
@ -60,10 +58,6 @@ Session::Session(
|
||||||
, _diceStickersPacks(std::make_unique<Stickers::DicePacks>(this))
|
, _diceStickersPacks(std::make_unique<Stickers::DicePacks>(this))
|
||||||
, _changelogs(Core::Changelogs::Create(this))
|
, _changelogs(Core::Changelogs::Create(this))
|
||||||
, _supportHelper(Support::Helper::Create(this)) {
|
, _supportHelper(Support::Helper::Create(this)) {
|
||||||
Core::App().passcodeLockChanges(
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
_shouldLockAt = 0;
|
|
||||||
}, _lifetime);
|
|
||||||
Core::App().lockChanges(
|
Core::App().lockChanges(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
notifications().updateAll();
|
notifications().updateAll();
|
||||||
|
@ -157,48 +151,12 @@ not_null<MTP::Instance*> Session::mtp() {
|
||||||
return _account->mtp();
|
return _account->mtp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::localPasscodeChanged() {
|
|
||||||
_shouldLockAt = 0;
|
|
||||||
_autoLockTimer.cancel();
|
|
||||||
checkAutoLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::termsDeleteNow() {
|
void Session::termsDeleteNow() {
|
||||||
api().request(MTPaccount_DeleteAccount(
|
api().request(MTPaccount_DeleteAccount(
|
||||||
MTP_string("Decline ToS update")
|
MTP_string("Decline ToS update")
|
||||||
)).send();
|
)).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::checkAutoLock() {
|
|
||||||
if (!Global::LocalPasscode()
|
|
||||||
|| Core::App().passcodeLocked()) {
|
|
||||||
_shouldLockAt = 0;
|
|
||||||
_autoLockTimer.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::App().checkLocalTime();
|
|
||||||
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)) {
|
|
||||||
_shouldLockAt = 0;
|
|
||||||
_autoLockTimer.cancel();
|
|
||||||
Core::App().lockByPasscode();
|
|
||||||
} else {
|
|
||||||
_shouldLockAt = now + (shouldLockInMs - checkTimeMs);
|
|
||||||
_autoLockTimer.callOnce(shouldLockInMs - checkTimeMs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::checkAutoLockIn(crl::time time) {
|
|
||||||
if (_autoLockTimer.isActive()) {
|
|
||||||
auto remain = _autoLockTimer.remainingTime();
|
|
||||||
if (remain > 0 && remain <= time) return;
|
|
||||||
}
|
|
||||||
_autoLockTimer.callOnce(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Session::supportMode() const {
|
bool Session::supportMode() const {
|
||||||
return (_supportHelper != nullptr);
|
return (_supportHelper != nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,9 +121,6 @@ public:
|
||||||
return *_calls;
|
return *_calls;
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkAutoLock();
|
|
||||||
void checkAutoLockIn(crl::time time);
|
|
||||||
void localPasscodeChanged();
|
|
||||||
void termsDeleteNow();
|
void termsDeleteNow();
|
||||||
|
|
||||||
[[nodiscard]] rpl::lifetime &lifetime() {
|
[[nodiscard]] rpl::lifetime &lifetime() {
|
||||||
|
@ -145,9 +142,6 @@ private:
|
||||||
Settings _settings;
|
Settings _settings;
|
||||||
base::Timer _saveSettingsTimer;
|
base::Timer _saveSettingsTimer;
|
||||||
|
|
||||||
crl::time _shouldLockAt = 0;
|
|
||||||
base::Timer _autoLockTimer;
|
|
||||||
|
|
||||||
const std::unique_ptr<ApiWrap> _api;
|
const std::unique_ptr<ApiWrap> _api;
|
||||||
const std::unique_ptr<Calls::Instance> _calls;
|
const std::unique_ptr<Calls::Instance> _calls;
|
||||||
const std::unique_ptr<Storage::DownloadManagerMtproto> _downloader;
|
const std::unique_ptr<Storage::DownloadManagerMtproto> _downloader;
|
||||||
|
|
|
@ -18,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Main {
|
namespace Main {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
|
|
||||||
constexpr auto kLegacyCallsPeerToPeerNobody = 4;
|
constexpr auto kLegacyCallsPeerToPeerNobody = 4;
|
||||||
constexpr auto kVersionTag = -1;
|
constexpr auto kVersionTag = -1;
|
||||||
constexpr auto kVersion = 1;
|
constexpr auto kVersion = 1;
|
||||||
|
|
|
@ -3061,7 +3061,7 @@ void MainWidget::feedDifference(
|
||||||
const MTPVector<MTPChat> &chats,
|
const MTPVector<MTPChat> &chats,
|
||||||
const MTPVector<MTPMessage> &msgs,
|
const MTPVector<MTPMessage> &msgs,
|
||||||
const MTPVector<MTPUpdate> &other) {
|
const MTPVector<MTPUpdate> &other) {
|
||||||
session().checkAutoLock();
|
Core::App().checkAutoLock();
|
||||||
session().data().processUsers(users);
|
session().data().processUsers(users);
|
||||||
session().data().processChats(chats);
|
session().data().processChats(chats);
|
||||||
feedMessageIds(other);
|
feedMessageIds(other);
|
||||||
|
@ -3523,8 +3523,7 @@ MainWidget::~MainWidget() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::updateOnline(bool gotOtherOffline) {
|
void MainWidget::updateOnline(bool gotOtherOffline) {
|
||||||
if (this != App::main()) return;
|
crl::on_main(this, [] { Core::App().checkAutoLock(); });
|
||||||
InvokeQueued(this, [=] { session().checkAutoLock(); });
|
|
||||||
|
|
||||||
bool isOnline = !App::quitting() && App::wnd()->isActive();
|
bool isOnline = !App::quitting() && App::wnd()->isActive();
|
||||||
int updateIn = Global::OnlineUpdatePeriod();
|
int updateIn = Global::OnlineUpdatePeriod();
|
||||||
|
@ -3660,7 +3659,7 @@ void MainWidget::checkIdleFinish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::mtpNewSessionCreated() {
|
void MainWidget::mtpNewSessionCreated() {
|
||||||
session().checkAutoLock();
|
Core::App().checkAutoLock();
|
||||||
updSeq = 0;
|
updSeq = 0;
|
||||||
MTP_LOG(0, ("getDifference { after new_session_created }%1"
|
MTP_LOG(0, ("getDifference { after new_session_created }%1"
|
||||||
).arg(cTestMode() ? " TESTMODE" : ""));
|
).arg(cTestMode() ? " TESTMODE" : ""));
|
||||||
|
@ -3668,7 +3667,7 @@ void MainWidget::mtpNewSessionCreated() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::mtpUpdateReceived(const MTPUpdates &updates) {
|
void MainWidget::mtpUpdateReceived(const MTPUpdates &updates) {
|
||||||
session().checkAutoLock();
|
Core::App().checkAutoLock();
|
||||||
_lastUpdateTime = crl::now();
|
_lastUpdateTime = crl::now();
|
||||||
_noUpdatesTimer.callOnce(kNoUpdatesTimeout);
|
_noUpdatesTimer.callOnce(kNoUpdatesTimeout);
|
||||||
if (!requestingDifference()
|
if (!requestingDifference()
|
||||||
|
|
|
@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "platform/win/windows_dlls.h"
|
#include "platform/win/windows_dlls.h"
|
||||||
#include "core/sandbox.h"
|
#include "core/sandbox.h"
|
||||||
|
#include "core/application.h"
|
||||||
#include "ui/inactive_press.h"
|
#include "ui/inactive_press.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "main/main_session.h"
|
|
||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
|
@ -95,9 +95,7 @@ bool EventFilter::mainWindowEvent(
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
|
|
||||||
case WM_TIMECHANGE: {
|
case WM_TIMECHANGE: {
|
||||||
if (Main::Session::Exists()) {
|
Core::App().checkAutoLockIn(100);
|
||||||
Auth().checkAutoLockIn(100);
|
|
||||||
}
|
|
||||||
} return false;
|
} return false;
|
||||||
|
|
||||||
case WM_WTSSESSION_CHANGE: {
|
case WM_WTSSESSION_CHANGE: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue