Fix first passcode unlock.

Fixes #4811.
This commit is contained in:
John Preston 2018-06-07 10:44:38 +03:00
parent 31ec831c71
commit 35659536c5
6 changed files with 38 additions and 48 deletions

View File

@ -417,8 +417,9 @@ public:
if (range.first == range.second) {
return 0;
}
const auto result = (range.second - range.first);
impl().erase(range.first, range.second);
return (range.second - range.first);
return result;
}
iterator erase(const_iterator where) {

View File

@ -297,8 +297,9 @@ public:
if (range.first == range.second) {
return 0;
}
const auto result = (range.second - range.first);
impl().erase(range.first, range.second);
return (range.second - range.first);
return result;
}
iterator erase(const_iterator where) {

View File

@ -128,9 +128,11 @@ void MainWindow::firstShow() {
}
void MainWindow::clearWidgetsHook() {
Expects(_passcodeLock == nullptr || !Global::LocalPasscode());
auto wasMain = (_main != nullptr);
_passcodeLock.destroy();
_main.destroy();
_passcodeLock.destroy();
_intro.destroy();
if (wasMain) {
App::clearHistories();
@ -177,18 +179,20 @@ void MainWindow::clearPasscodeLock() {
_passcodeLock.destroy();
if (_intro) {
_intro->showAnimated(bg, true);
} else {
Assert(_main != nullptr);
} else if (_main) {
_main->showAnimated(bg, true);
Messenger::Instance().checkStartUrl();
} else {
Messenger::Instance().startMtp();
if (AuthSession::Exists()) {
setupMain();
} else {
setupIntro();
}
}
}
void MainWindow::setupIntro() {
if (_intro && !_intro->isHidden() && !_main) {
return;
}
Ui::hideSettingsAndLayer(anim::type::instant);
auto animated = (_main || _passcodeLock);
@ -273,13 +277,13 @@ void MainWindow::sendServiceHistoryRequest() {
}
void MainWindow::setupMain(const MTPUser *self) {
Expects(AuthSession::Exists());
auto animated = (_intro || _passcodeLock);
auto bg = animated ? grabInner() : QPixmap();
clearWidgets();
Assert(AuthSession::Exists());
_main.create(bodyWidget(), controller());
_main->show();
updateControlsGeometry();

View File

@ -151,24 +151,19 @@ Messenger::Messenger(not_null<Core::Launcher*> launcher)
if (state == Local::ReadMapPassNeeded) {
Global::SetLocalPasscode(true);
Global::RefLocalPasscodeChanged().notify();
lockByPasscode();
DEBUG_LOG(("Application Info: passcode needed..."));
} else {
DEBUG_LOG(("Application Info: local map read..."));
startMtp();
}
DEBUG_LOG(("Application Info: MTP started..."));
DEBUG_LOG(("Application Info: showing."));
if (state == Local::ReadMapPassNeeded) {
lockByPasscode();
} else {
DEBUG_LOG(("Application Info: MTP started..."));
if (AuthSession::Exists()) {
_window->setupMain();
} else {
_window->setupIntro();
}
}
DEBUG_LOG(("Application Info: showing."));
_window->firstShow();
if (cStartToSettings()) {
@ -1037,8 +1032,12 @@ void Messenger::lockByPasscode() {
}
void Messenger::unlockPasscode() {
cSetPasscodeBadTries(0);
clearPasscodeLock();
_window->clearPasscodeLock();
}
void Messenger::clearPasscodeLock() {
cSetPasscodeBadTries(0);
_passcodeLock = false;
}
@ -1202,6 +1201,7 @@ void Messenger::loggedOut() {
Global::SetLocalPasscode(false);
Global::RefLocalPasscodeChanged().notify();
}
clearPasscodeLock();
Media::Player::mixer()->stopAndClear();
if (const auto w = getActiveWindow()) {
w->tempDirDelete(Local::ClearManagerAll);

View File

@ -233,6 +233,7 @@ private:
void photoUpdated(const FullMsgId &msgId, const MTPInputFile &file);
void resetAuthorizationKeys();
void authSessionDestroy();
void clearPasscodeLock();
void loggedOut();
not_null<Core::Launcher*> _launcher;

View File

@ -132,35 +132,18 @@ void PasscodeLockWidget::submit() {
return;
}
if (App::main()) {
if (Local::checkPasscode(_passcode->text().toUtf8())) {
Messenger::Instance().unlockPasscode(); // Destroys this widget.
return;
} else {
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
cSetPasscodeLastTry(getms(true));
error();
return;
}
} else {
if (Local::readMap(_passcode->text().toUtf8()) != Local::ReadMapPassNeeded) {
cSetPasscodeBadTries(0);
Messenger::Instance().startMtp();
// Destroys this widget.
if (AuthSession::Exists()) {
App::wnd()->setupMain();
} else {
App::wnd()->setupIntro();
}
} else {
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
cSetPasscodeLastTry(getms(true));
error();
return;
}
const auto passcode = _passcode->text().toUtf8();
const auto correct = App::main()
? Local::checkPasscode(passcode)
: (Local::readMap(passcode) != Local::ReadMapPassNeeded);
if (!correct) {
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
cSetPasscodeLastTry(getms(true));
error();
return;
}
Messenger::Instance().unlockPasscode(); // Destroys this widget.
}
void PasscodeLockWidget::error() {