mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Removed LocalPasscode global variable from facades.
This commit is contained in:
parent
7852c82eab
commit
54dd63d61a
13 changed files with 74 additions and 51 deletions
|
@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "passport/passport_encryption.h"
|
||||
#include "passport/passport_panel_edit_contact.h"
|
||||
#include "settings/settings_privacy_security.h"
|
||||
#include "facades.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_passport.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
@ -119,7 +118,12 @@ PasscodeBox::PasscodeBox(
|
|||
, _turningOff(turningOff)
|
||||
, _about(st::boxWidth - st::boxPadding.left() * 1.5)
|
||||
, _oldPasscode(this, st::defaultInputField, tr::lng_passcode_enter_old())
|
||||
, _newPasscode(this, st::defaultInputField, Global::LocalPasscode() ? tr::lng_passcode_enter_new() : tr::lng_passcode_enter_first())
|
||||
, _newPasscode(
|
||||
this,
|
||||
st::defaultInputField,
|
||||
session->domain().local().hasLocalPasscode()
|
||||
? tr::lng_passcode_enter_new()
|
||||
: tr::lng_passcode_enter_first())
|
||||
, _reenterPasscode(this, st::defaultInputField, tr::lng_passcode_confirm_new())
|
||||
, _passwordHint(this, st::defaultInputField, tr::lng_cloud_password_hint())
|
||||
, _recoverEmail(this, st::defaultInputField, tr::lng_cloud_password_email())
|
||||
|
@ -164,7 +168,9 @@ rpl::producer<> PasscodeBox::clearUnconfirmedPassword() const {
|
|||
}
|
||||
|
||||
bool PasscodeBox::currentlyHave() const {
|
||||
return _cloudPwd ? (!!_cloudFields.curRequest) : Global::LocalPasscode();
|
||||
return _cloudPwd
|
||||
? (!!_cloudFields.curRequest)
|
||||
: _session->domain().local().hasLocalPasscode();
|
||||
}
|
||||
|
||||
bool PasscodeBox::onlyCheckCurrent() const {
|
||||
|
@ -520,7 +526,7 @@ void PasscodeBox::save(bool force) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Core::App().domain().local().checkPasscode(old.toUtf8())) {
|
||||
if (_session->domain().local().checkPasscode(old.toUtf8())) {
|
||||
cSetPasscodeBadTries(0);
|
||||
if (_turningOff) pwd = conf = QString();
|
||||
} else {
|
||||
|
@ -588,7 +594,7 @@ void PasscodeBox::save(bool force) {
|
|||
closeReplacedBy();
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
cSetPasscodeBadTries(0);
|
||||
Core::App().domain().local().setPasscode(pwd.toUtf8());
|
||||
_session->domain().local().setPasscode(pwd.toUtf8());
|
||||
Core::App().localPasscodeChanged();
|
||||
if (weak) {
|
||||
closeBox();
|
||||
|
|
|
@ -321,8 +321,6 @@ void Application::startDomain() {
|
|||
startSettingsAndBackground();
|
||||
}
|
||||
if (state != Storage::StartResult::Success) {
|
||||
Global::SetLocalPasscode(true);
|
||||
Global::RefLocalPasscodeChanged().notify();
|
||||
lockByPasscode();
|
||||
DEBUG_LOG(("Application Info: passcode needed..."));
|
||||
}
|
||||
|
@ -910,7 +908,7 @@ bool Application::someSessionExists() const {
|
|||
}
|
||||
|
||||
void Application::checkAutoLock() {
|
||||
if (!Global::LocalPasscode()
|
||||
if (!_domain->local().hasLocalPasscode()
|
||||
|| passcodeLocked()
|
||||
|| !someSessionExists()) {
|
||||
_shouldLockAt = 0;
|
||||
|
@ -1146,7 +1144,7 @@ void Application::startShortcuts() {
|
|||
return true;
|
||||
});
|
||||
request->check(Command::Lock) && request->handle([=] {
|
||||
if (!passcodeLocked() && Global::LocalPasscode()) {
|
||||
if (!passcodeLocked() && _domain->local().hasLocalPasscode()) {
|
||||
lockByPasscode();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_keys.h"
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_session_settings.h"
|
||||
#include "apiwrap.h"
|
||||
|
@ -34,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/window_main_menu.h"
|
||||
#include "storage/storage_media_prepare.h"
|
||||
#include "storage/storage_account.h"
|
||||
#include "storage/storage_domain.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_chat.h"
|
||||
|
@ -268,8 +270,13 @@ Widget::Widget(
|
|||
_cancelSearch->setClickedCallback([this] { onCancelSearch(); });
|
||||
_jumpToDate->entity()->setClickedCallback([this] { showJumpToDate(); });
|
||||
_chooseFromUser->entity()->setClickedCallback([this] { showSearchFrom(); });
|
||||
_lockUnlock->setVisible(Global::LocalPasscode());
|
||||
subscribe(Global::RefLocalPasscodeChanged(), [this] { updateLockUnlockVisibility(); });
|
||||
rpl::single(
|
||||
rpl::empty_value()
|
||||
) | rpl::then(
|
||||
session().domain().local().localPasscodeChanged()
|
||||
) | rpl::start_with_next([=] {
|
||||
updateLockUnlockVisibility();
|
||||
}, lifetime());
|
||||
_lockUnlock->setClickedCallback([this] {
|
||||
_lockUnlock->setIconOverride(&st::dialogsUnlockIcon, &st::dialogsUnlockIconOver);
|
||||
Core::App().lockByPasscode();
|
||||
|
@ -1502,7 +1509,7 @@ void Widget::updateLockUnlockVisibility() {
|
|||
if (_a_show.animating()) {
|
||||
return;
|
||||
}
|
||||
const auto hidden = !Global::LocalPasscode();
|
||||
const auto hidden = !session().domain().local().hasLocalPasscode();
|
||||
if (_lockUnlock->isHidden() != hidden) {
|
||||
_lockUnlock->setVisible(!hidden);
|
||||
updateControlsGeometry();
|
||||
|
@ -1560,7 +1567,7 @@ void Widget::updateControlsGeometry() {
|
|||
auto smallLayoutWidth = (st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPadding.x());
|
||||
auto smallLayoutRatio = (width() < st::columnMinimalWidthLeft) ? (st::columnMinimalWidthLeft - width()) / float64(st::columnMinimalWidthLeft - smallLayoutWidth) : 0.;
|
||||
auto filterLeft = (controller()->filtersWidth() ? st::dialogsFilterSkip : st::dialogsFilterPadding.x() + _mainMenuToggle->width()) + st::dialogsFilterPadding.x();
|
||||
auto filterRight = (Global::LocalPasscode() ? (st::dialogsFilterPadding.x() + _lockUnlock->width()) : st::dialogsFilterSkip) + st::dialogsFilterPadding.x();
|
||||
auto filterRight = (_lockUnlock->isVisible() ? (st::dialogsFilterPadding.x() + _lockUnlock->width()) : st::dialogsFilterSkip) + st::dialogsFilterPadding.x();
|
||||
auto filterWidth = qMax(width(), st::columnMinimalWidthLeft) - filterLeft - filterRight;
|
||||
auto filterAreaHeight = st::topBarHeight;
|
||||
_searchControls->setGeometry(0, filterAreaTop, width(), filterAreaHeight);
|
||||
|
|
|
@ -352,9 +352,6 @@ struct Data {
|
|||
bool UseProxyForCalls = false;
|
||||
base::Observable<void> ConnectionTypeChanged;
|
||||
|
||||
bool LocalPasscode = false;
|
||||
base::Observable<void> LocalPasscodeChanged;
|
||||
|
||||
base::Variable<DBIWorkMode> WorkMode = { dbiwmWindowAndTray };
|
||||
};
|
||||
|
||||
|
@ -392,9 +389,6 @@ DefineVar(Global, MTP::ProxyData::Settings, ProxySettings);
|
|||
DefineVar(Global, bool, UseProxyForCalls);
|
||||
DefineRefVar(Global, base::Observable<void>, ConnectionTypeChanged);
|
||||
|
||||
DefineVar(Global, bool, LocalPasscode);
|
||||
DefineRefVar(Global, base::Observable<void>, LocalPasscodeChanged);
|
||||
|
||||
DefineRefVar(Global, base::Variable<DBIWorkMode>, WorkMode);
|
||||
|
||||
} // namespace Global
|
||||
|
|
|
@ -124,9 +124,6 @@ DeclareVar(MTP::ProxyData::Settings, ProxySettings);
|
|||
DeclareVar(bool, UseProxyForCalls);
|
||||
DeclareRefVar(base::Observable<void>, ConnectionTypeChanged);
|
||||
|
||||
DeclareVar(bool, LocalPasscode);
|
||||
DeclareRefVar(base::Observable<void>, LocalPasscodeChanged);
|
||||
|
||||
DeclareRefVar(base::Variable<DBIWorkMode>, WorkMode);
|
||||
|
||||
} // namespace Global
|
||||
|
|
|
@ -340,7 +340,7 @@ bool Domain::removePasscodeIfEmpty() {
|
|||
return false;
|
||||
}
|
||||
Local::reset();
|
||||
if (!Global::LocalPasscode()) {
|
||||
if (!_local->hasLocalPasscode()) {
|
||||
return false;
|
||||
}
|
||||
// We completely logged out, remove the passcode if it was there.
|
||||
|
|
|
@ -27,8 +27,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "core/update_checker.h"
|
||||
#include "core/application.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include "storage/storage_domain.h"
|
||||
#include "data/data_session.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_session.h"
|
||||
#include "mtproto/facade.h"
|
||||
#include "facades.h"
|
||||
|
@ -313,7 +315,9 @@ void SetupSpellchecker(
|
|||
#endif // !TDESKTOP_DISABLE_SPELLCHECK
|
||||
}
|
||||
|
||||
void SetupSystemIntegrationContent(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupSystemIntegrationContent(
|
||||
Window::SessionController *controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
const auto checkbox = [&](rpl::producer<QString> &&label, bool checked) {
|
||||
return object_ptr<Ui::Checkbox>(
|
||||
container,
|
||||
|
@ -409,9 +413,10 @@ void SetupSystemIntegrationContent(not_null<Ui::VerticalLayout*> container) {
|
|||
Core::App().saveSettingsDelayed();
|
||||
}, nativeFrame->lifetime());
|
||||
}
|
||||
if (Platform::AutostartSupported()) {
|
||||
const auto minimizedToggled = [] {
|
||||
return cStartMinimized() && !Global::LocalPasscode();
|
||||
if (Platform::AutostartSupported() && controller) {
|
||||
const auto minimizedToggled = [=] {
|
||||
return cStartMinimized()
|
||||
&& !controller->session().domain().local().hasLocalPasscode();
|
||||
};
|
||||
|
||||
const auto autostart = addCheckbox(
|
||||
|
@ -441,7 +446,7 @@ void SetupSystemIntegrationContent(not_null<Ui::VerticalLayout*> container) {
|
|||
) | rpl::filter([=](bool checked) {
|
||||
return (checked != minimizedToggled());
|
||||
}) | rpl::start_with_next([=](bool checked) {
|
||||
if (Global::LocalPasscode()) {
|
||||
if (controller->session().domain().local().hasLocalPasscode()) {
|
||||
minimized->entity()->setChecked(false);
|
||||
Ui::show(Box<InformBox>(
|
||||
tr::lng_error_start_minimized_passcoded(tr::now)));
|
||||
|
@ -451,8 +456,7 @@ void SetupSystemIntegrationContent(not_null<Ui::VerticalLayout*> container) {
|
|||
}
|
||||
}, minimized->lifetime());
|
||||
|
||||
base::ObservableViewer(
|
||||
Global::RefLocalPasscodeChanged()
|
||||
controller->session().domain().local().localPasscodeChanged(
|
||||
) | rpl::start_with_next([=] {
|
||||
minimized->entity()->setChecked(minimizedToggled());
|
||||
}, minimized->lifetime());
|
||||
|
@ -474,9 +478,11 @@ void SetupSystemIntegrationContent(not_null<Ui::VerticalLayout*> container) {
|
|||
}
|
||||
}
|
||||
|
||||
void SetupSystemIntegrationOptions(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupSystemIntegrationOptions(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
auto wrap = object_ptr<Ui::VerticalLayout>(container);
|
||||
SetupSystemIntegrationContent(wrap.data());
|
||||
SetupSystemIntegrationContent(controller, wrap.data());
|
||||
if (wrap->count() > 0) {
|
||||
container->add(object_ptr<Ui::OverrideMargins>(
|
||||
container,
|
||||
|
@ -544,6 +550,7 @@ void SetupPerformance(
|
|||
}
|
||||
|
||||
void SetupSystemIntegration(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(Type)> showOther) {
|
||||
AddDivider(container);
|
||||
|
@ -556,7 +563,7 @@ void SetupSystemIntegration(
|
|||
)->addClickHandler([=] {
|
||||
showOther(Type::Calls);
|
||||
});
|
||||
SetupSystemIntegrationOptions(container);
|
||||
SetupSystemIntegrationOptions(controller, container);
|
||||
AddSkip(container);
|
||||
}
|
||||
|
||||
|
@ -601,7 +608,7 @@ void Advanced::setupContent(not_null<Window::SessionController*> controller) {
|
|||
AddSkip(content);
|
||||
SetupDataStorage(controller, content);
|
||||
SetupAutoDownload(controller, content);
|
||||
SetupSystemIntegration(content, [=](Type type) {
|
||||
SetupSystemIntegration(controller, content, [=](Type type) {
|
||||
_showOther.fire_copy(type);
|
||||
});
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ void SetupConnectionType(
|
|||
not_null<Ui::VerticalLayout*> container);
|
||||
bool HasUpdate();
|
||||
void SetupUpdate(not_null<Ui::VerticalLayout*> container);
|
||||
void SetupSystemIntegrationContent(not_null<Ui::VerticalLayout*> container);
|
||||
void SetupSystemIntegrationContent(
|
||||
Window::SessionController *controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
void SetupAnimations(not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
class Advanced : public Section {
|
||||
|
|
|
@ -75,7 +75,9 @@ object_ptr<Ui::RpWidget> CreateIntroSettings(
|
|||
}
|
||||
{
|
||||
auto wrap = object_ptr<Ui::VerticalLayout>(result);
|
||||
SetupSystemIntegrationContent(wrap.data());
|
||||
SetupSystemIntegrationContent(
|
||||
window->sessionController(),
|
||||
wrap.data());
|
||||
if (wrap->count() > 0) {
|
||||
AddDivider(result);
|
||||
AddSkip(result);
|
||||
|
|
|
@ -39,7 +39,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_session.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_session.h"
|
||||
#include "storage/storage_domain.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "apiwrap.h"
|
||||
#include "facades.h"
|
||||
|
@ -56,14 +58,6 @@ constexpr auto kUpdateTimeout = 60 * crl::time(1000);
|
|||
|
||||
using Privacy = ApiWrap::Privacy;
|
||||
|
||||
rpl::producer<> PasscodeChanges() {
|
||||
return rpl::single(
|
||||
rpl::empty_value()
|
||||
) | rpl::then(base::ObservableViewer(
|
||||
Global::RefLocalPasscodeChanged()
|
||||
));
|
||||
}
|
||||
|
||||
QString PrivacyBase(Privacy::Key key, Privacy::Option option) {
|
||||
using Key = Privacy::Key;
|
||||
using Option = Privacy::Option;
|
||||
|
@ -257,9 +251,12 @@ void SetupLocalPasscode(
|
|||
AddSkip(container);
|
||||
AddSubsectionTitle(container, tr::lng_settings_passcode_title());
|
||||
|
||||
auto has = PasscodeChanges(
|
||||
) | rpl::map([] {
|
||||
return Global::LocalPasscode();
|
||||
auto has = rpl::single(
|
||||
rpl::empty_value()
|
||||
) | rpl::then(
|
||||
controller->session().domain().local().localPasscodeChanged()
|
||||
) | rpl::map([=] {
|
||||
return controller->session().domain().local().hasLocalPasscode();
|
||||
});
|
||||
auto text = rpl::combine(
|
||||
tr::lng_passcode_change(),
|
||||
|
|
|
@ -838,7 +838,6 @@ bool ReadSetting(
|
|||
if (!CheckStreamStatus(stream)) return false;
|
||||
|
||||
Core::App().settings().setAutoLock(v);
|
||||
Global::RefLocalPasscodeChanged().notify();
|
||||
context.legacyRead = true;
|
||||
} break;
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "mtproto/mtproto_config.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_account.h"
|
||||
#include "facades.h"
|
||||
|
||||
namespace Storage {
|
||||
namespace {
|
||||
|
@ -116,6 +115,7 @@ void Domain::encryptLocalKey(const QByteArray &passcode) {
|
|||
EncryptedDescriptor passKeyData(MTP::AuthKey::kSize);
|
||||
_localKey->write(passKeyData.stream);
|
||||
_passcodeKeyEncrypted = PrepareEncrypted(passKeyData, _passcodeKey);
|
||||
_hasLocalPasscode = !passcode.isEmpty();
|
||||
}
|
||||
|
||||
Domain::StartModernResult Domain::startModern(
|
||||
|
@ -156,6 +156,7 @@ Domain::StartModernResult Domain::startModern(
|
|||
|
||||
_passcodeKeyEncrypted = keyEncrypted;
|
||||
_passcodeKeySalt = salt;
|
||||
_hasLocalPasscode = !passcode.isEmpty();
|
||||
|
||||
if (!DecryptLocal(info, infoEncrypted, _localKey)) {
|
||||
LOG(("App Error: could not decrypt info."));
|
||||
|
@ -261,8 +262,7 @@ void Domain::setPasscode(const QByteArray &passcode) {
|
|||
encryptLocalKey(passcode);
|
||||
writeAccounts();
|
||||
|
||||
Global::SetLocalPasscode(!passcode.isEmpty());
|
||||
Global::RefLocalPasscodeChanged().notify();
|
||||
_passcodeKeyChanged.fire({});
|
||||
}
|
||||
|
||||
int Domain::oldVersion() const {
|
||||
|
@ -277,4 +277,12 @@ QString Domain::webviewDataPath() const {
|
|||
return BaseGlobalPath() + "webview";
|
||||
}
|
||||
|
||||
rpl::producer<> Domain::localPasscodeChanged() const {
|
||||
return _passcodeKeyChanged.events();
|
||||
}
|
||||
|
||||
bool Domain::hasLocalPasscode() const {
|
||||
return _hasLocalPasscode;
|
||||
}
|
||||
|
||||
} // namespace Storage
|
||||
|
|
|
@ -46,6 +46,9 @@ public:
|
|||
|
||||
[[nodiscard]] QString webviewDataPath() const;
|
||||
|
||||
[[nodiscard]] rpl::producer<> localPasscodeChanged() const;
|
||||
[[nodiscard]] bool hasLocalPasscode() const;
|
||||
|
||||
private:
|
||||
enum class StartModernResult {
|
||||
Success,
|
||||
|
@ -70,6 +73,9 @@ private:
|
|||
QByteArray _passcodeKeyEncrypted;
|
||||
int _oldVersion = 0;
|
||||
|
||||
bool _hasLocalPasscode = false;
|
||||
rpl::event_stream<> _passcodeKeyChanged;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Storage
|
||||
|
|
Loading…
Add table
Reference in a new issue