mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Fix logouting from the passcode.
This commit is contained in:
parent
ba103fdd40
commit
c83659f0c7
9 changed files with 85 additions and 73 deletions
|
@ -456,13 +456,6 @@ void Application::logout(Main::Account *account) {
|
|||
account->logOut();
|
||||
} else {
|
||||
accounts().resetWithForgottenPasscode();
|
||||
|
||||
if (Global::LocalPasscode()) {
|
||||
Global::SetLocalPasscode(false);
|
||||
Global::RefLocalPasscodeChanged().notify();
|
||||
}
|
||||
Core::App().unlockPasscode();
|
||||
Core::App().unlockTerms();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -460,9 +460,8 @@ void Account::loggedOut() {
|
|||
window->tempDirDelete(Local::ClearManagerAll);
|
||||
}
|
||||
destroySession();
|
||||
Core::App().unlockTerms();
|
||||
local().reset();
|
||||
Local::reset();
|
||||
|
||||
cSetOtherOnline(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "main/main_session.h"
|
||||
#include "storage/storage_accounts.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include "facades.h"
|
||||
|
||||
namespace Main {
|
||||
|
||||
|
@ -73,6 +74,7 @@ void Accounts::activateAfterStarting() {
|
|||
}
|
||||
|
||||
activate(_activeIndex);
|
||||
removePasscodeIfEmpty();
|
||||
}
|
||||
|
||||
const base::flat_map<int, std::unique_ptr<Account>> &Accounts::list() const {
|
||||
|
@ -131,7 +133,7 @@ void Accounts::watchSession(not_null<Account*> account) {
|
|||
account->startMtp();
|
||||
account->sessionChanges(
|
||||
) | rpl::filter([=](Session *session) {
|
||||
return !session && _accounts.size() > 1;
|
||||
return !session; // removeRedundantAccounts may remove passcode lock.
|
||||
}) | rpl::start_with_next([=](Session *session) {
|
||||
if (account == _active.current()) {
|
||||
activateAuthedAccount();
|
||||
|
@ -156,6 +158,20 @@ void Accounts::activateAuthedAccount() {
|
|||
}
|
||||
}
|
||||
|
||||
bool Accounts::removePasscodeIfEmpty() {
|
||||
if (_accounts.size() != 1 || _active.current()->sessionExists()) {
|
||||
return false;
|
||||
}
|
||||
Local::reset();
|
||||
if (!Global::LocalPasscode()) {
|
||||
return false;
|
||||
}
|
||||
// We completely logged out, remove the passcode if it was there.
|
||||
Core::App().unlockPasscode();
|
||||
_local->setPasscode(QByteArray());
|
||||
return true;
|
||||
}
|
||||
|
||||
void Accounts::removeRedundantAccounts() {
|
||||
Expects(started());
|
||||
|
||||
|
@ -169,7 +185,8 @@ void Accounts::removeRedundantAccounts() {
|
|||
}
|
||||
i = _accounts.erase(i);
|
||||
}
|
||||
if (_accounts.size() != was) {
|
||||
|
||||
if (!removePasscodeIfEmpty() && _accounts.size() != was) {
|
||||
scheduleWriteAccounts();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
private:
|
||||
void activateAfterStarting();
|
||||
void activateAuthedAccount();
|
||||
bool removePasscodeIfEmpty();
|
||||
void removeRedundantAccounts();
|
||||
void watchSession(not_null<Account*> account);
|
||||
void scheduleWriteAccounts();
|
||||
|
|
|
@ -358,6 +358,32 @@ MainWidget::MainWidget(
|
|||
Core::UpdateChecker checker;
|
||||
checker.start();
|
||||
}
|
||||
|
||||
auto &api = session().api();
|
||||
api.requestNotifySettings(MTP_inputNotifyUsers());
|
||||
api.requestNotifySettings(MTP_inputNotifyChats());
|
||||
api.requestNotifySettings(MTP_inputNotifyBroadcasts());
|
||||
|
||||
cSetOtherOnline(0);
|
||||
session().user()->loadUserpic();
|
||||
|
||||
auto &local = session().local();
|
||||
local.readInstalledStickers();
|
||||
local.readFeaturedStickers();
|
||||
local.readRecentStickers();
|
||||
local.readFavedStickers();
|
||||
local.readSavedGifs();
|
||||
auto &data = session().data();
|
||||
if (const auto availableAt = local.readExportSettings().availableAt) {
|
||||
data.suggestStartExport(availableAt);
|
||||
}
|
||||
auto &stickers = data.stickers();
|
||||
stickers.notifyUpdated();
|
||||
stickers.notifySavedGifsUpdated();
|
||||
|
||||
_history->start();
|
||||
|
||||
Core::App().checkStartUrl();
|
||||
}
|
||||
|
||||
MainWidget::~MainWidget() = default;
|
||||
|
@ -2498,7 +2524,7 @@ void MainWidget::updateWindowAdaptiveLayout() {
|
|||
// dialogs widget to provide a wide enough chat history column.
|
||||
// Don't shrink the column on the first call, when window is inited.
|
||||
if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn
|
||||
&& _started && _controller->widget()->positionInited()) {
|
||||
&& _controller->widget()->positionInited()) {
|
||||
//auto chatWidth = layout.chatWidth;
|
||||
//if (_history->willSwitchToTabbedSelectorWithWidth(chatWidth)) {
|
||||
// auto thirdColumnWidth = _history->tabbedSelectorSectionWidth();
|
||||
|
@ -2547,39 +2573,6 @@ void MainWidget::searchInChat(Dialogs::Key chat) {
|
|||
}
|
||||
}
|
||||
|
||||
void MainWidget::start() {
|
||||
auto &api = session().api();
|
||||
api.requestNotifySettings(MTP_inputNotifyUsers());
|
||||
api.requestNotifySettings(MTP_inputNotifyChats());
|
||||
api.requestNotifySettings(MTP_inputNotifyBroadcasts());
|
||||
|
||||
cSetOtherOnline(0);
|
||||
session().user()->loadUserpic();
|
||||
|
||||
_started = true;
|
||||
auto &local = session().local();
|
||||
local.readInstalledStickers();
|
||||
local.readFeaturedStickers();
|
||||
local.readRecentStickers();
|
||||
local.readFavedStickers();
|
||||
local.readSavedGifs();
|
||||
auto &data = session().data();
|
||||
if (const auto availableAt = local.readExportSettings().availableAt) {
|
||||
data.suggestStartExport(availableAt);
|
||||
}
|
||||
auto &stickers = data.stickers();
|
||||
stickers.notifyUpdated();
|
||||
stickers.notifySavedGifsUpdated();
|
||||
|
||||
_history->start();
|
||||
|
||||
Core::App().checkStartUrl();
|
||||
}
|
||||
|
||||
bool MainWidget::started() {
|
||||
return _started;
|
||||
}
|
||||
|
||||
void MainWidget::openPeerByName(
|
||||
const QString &username,
|
||||
MsgId msgId,
|
||||
|
|
|
@ -118,15 +118,12 @@ public:
|
|||
|
||||
void showAnimated(const QPixmap &bgAnimCache, bool back = false);
|
||||
|
||||
void start();
|
||||
|
||||
void openPeerByName(
|
||||
const QString &name,
|
||||
MsgId msgId = ShowAtUnreadMsgId,
|
||||
const QString &startToken = QString(),
|
||||
FullMsgId clickFromMessageId = FullMsgId());
|
||||
|
||||
bool started();
|
||||
void activate();
|
||||
|
||||
void windowShown();
|
||||
|
@ -349,8 +346,7 @@ private:
|
|||
|
||||
void handleHistoryBack();
|
||||
|
||||
not_null<Window::SessionController*> _controller;
|
||||
bool _started = false;
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
|
||||
Ui::Animations::Simple _a_show;
|
||||
bool _showBack = false;
|
||||
|
|
|
@ -197,15 +197,17 @@ void MainWindow::clearWidgetsHook() {
|
|||
destroyLayer();
|
||||
_mediaPreview.destroy();
|
||||
_main.destroy();
|
||||
_passcodeLock.destroy();
|
||||
_intro.destroy();
|
||||
if (!Core::App().passcodeLocked()) {
|
||||
_passcodeLock.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap MainWindow::grabInner() {
|
||||
if (_intro) {
|
||||
return Ui::GrabWidget(_intro);
|
||||
} else if (_passcodeLock) {
|
||||
if (_passcodeLock) {
|
||||
return Ui::GrabWidget(_passcodeLock);
|
||||
} else if (_intro) {
|
||||
return Ui::GrabWidget(_intro);
|
||||
} else if (_main) {
|
||||
return Ui::GrabWidget(_main);
|
||||
}
|
||||
|
@ -242,10 +244,14 @@ void MainWindow::clearPasscodeLock() {
|
|||
if (_intro) {
|
||||
auto bg = grabInner();
|
||||
_passcodeLock.destroy();
|
||||
_intro->show();
|
||||
updateControlsGeometry();
|
||||
_intro->showAnimated(bg, true);
|
||||
} else if (_main) {
|
||||
auto bg = grabInner();
|
||||
_passcodeLock.destroy();
|
||||
_main->show();
|
||||
updateControlsGeometry();
|
||||
_main->showAnimated(bg, true);
|
||||
Core::App().checkStartUrl();
|
||||
}
|
||||
|
@ -257,14 +263,17 @@ void MainWindow::setupIntro() {
|
|||
|
||||
clearWidgets();
|
||||
_intro.create(bodyWidget(), &account());
|
||||
updateControlsGeometry();
|
||||
|
||||
if (animated) {
|
||||
_intro->showAnimated(bg);
|
||||
if (_passcodeLock) {
|
||||
_intro->hide();
|
||||
} else {
|
||||
setInnerFocus();
|
||||
_intro->show();
|
||||
updateControlsGeometry();
|
||||
if (animated) {
|
||||
_intro->showAnimated(bg);
|
||||
} else {
|
||||
setInnerFocus();
|
||||
}
|
||||
}
|
||||
|
||||
fixOrder();
|
||||
}
|
||||
|
||||
|
@ -275,18 +284,19 @@ void MainWindow::setupMain() {
|
|||
auto bg = animated ? grabInner() : QPixmap();
|
||||
|
||||
clearWidgets();
|
||||
|
||||
_main.create(bodyWidget(), sessionController());
|
||||
_main->show();
|
||||
updateControlsGeometry();
|
||||
|
||||
if (animated) {
|
||||
_main->showAnimated(bg);
|
||||
if (_passcodeLock) {
|
||||
_main->hide();
|
||||
} else {
|
||||
_main->activate();
|
||||
_main->show();
|
||||
updateControlsGeometry();
|
||||
if (animated) {
|
||||
_main->showAnimated(bg);
|
||||
} else {
|
||||
_main->activate();
|
||||
}
|
||||
Core::App().checkStartUrl();
|
||||
}
|
||||
_main->start();
|
||||
|
||||
fixOrder();
|
||||
}
|
||||
|
||||
|
@ -663,7 +673,10 @@ void MainWindow::showLogoutConfirmation() {
|
|||
? &sessionController()->session().account()
|
||||
: nullptr;
|
||||
const auto weak = base::make_weak(account);
|
||||
const auto callback = crl::guard(weak, [=] {
|
||||
const auto callback = [=] {
|
||||
if (account && !weak) {
|
||||
return;
|
||||
}
|
||||
if (account
|
||||
&& account->sessionExists()
|
||||
&& account->session().data().exportInProgress()) {
|
||||
|
@ -674,7 +687,7 @@ void MainWindow::showLogoutConfirmation() {
|
|||
} else {
|
||||
Core::App().logout(account);
|
||||
}
|
||||
});
|
||||
};
|
||||
Ui::show(Box<ConfirmBox>(
|
||||
tr::lng_sure_logout(tr::now),
|
||||
tr::lng_settings_logout(tr::now),
|
||||
|
|
|
@ -543,6 +543,7 @@ void Account::reset() {
|
|||
_cacheBigFileTotalTimeLimit = Database::Settings().totalTimeLimit;
|
||||
_mapChanged = true;
|
||||
writeMap();
|
||||
writeMtpData();
|
||||
|
||||
crl::async([base = _basePath, names = std::move(names)] {
|
||||
for (const auto &name : names) {
|
||||
|
|
|
@ -149,9 +149,8 @@ void PasscodeLockWidget::submit() {
|
|||
}
|
||||
|
||||
const auto passcode = _passcode->text().toUtf8();
|
||||
const auto controller = window()->sessionController();
|
||||
auto &accounts = Core::App().accounts();
|
||||
const auto correct = controller
|
||||
const auto correct = accounts.started()
|
||||
? accounts.local().checkPasscode(passcode)
|
||||
: (accounts.start(passcode)
|
||||
!= Storage::StartResult::IncorrectPasscode);
|
||||
|
|
Loading…
Add table
Reference in a new issue