From cbad993bba4f4d7174d5357e9792b06794751437 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 29 Jun 2020 20:07:56 +0400 Subject: [PATCH] Fix app start without data. --- Telegram/SourceFiles/main/main_account.cpp | 6 +--- Telegram/SourceFiles/main/main_domain.cpp | 28 ++++++++++++------- Telegram/SourceFiles/main/main_domain.h | 1 + Telegram/SourceFiles/storage/localstorage.cpp | 2 ++ .../SourceFiles/storage/storage_domain.cpp | 1 + 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index f165ffaabe..192dc8ac97 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -68,11 +68,7 @@ Storage::Domain &Account::domainLocal() const { const QByteArray &passcode) { Expects(!_appConfig); - const auto result = _local->legacyStart(passcode); - if (result == Storage::StartResult::Success) { - start(nullptr); - } - return result; + return _local->legacyStart(passcode); } std::unique_ptr Account::prepareToStart( diff --git a/Telegram/SourceFiles/main/main_domain.cpp b/Telegram/SourceFiles/main/main_domain.cpp index 845787c248..c61aa3533c 100644 --- a/Telegram/SourceFiles/main/main_domain.cpp +++ b/Telegram/SourceFiles/main/main_domain.cpp @@ -25,6 +25,10 @@ namespace Main { Domain::Domain(const QString &dataName) : _dataName(dataName) , _local(std::make_unique(this, dataName)) { + _active.changes( + ) | rpl::take(1) | rpl::start_with_next([] { + Local::rewriteSettingsIfNeeded(); + }, _lifetime); } Domain::~Domain() = default; @@ -39,7 +43,7 @@ Storage::StartResult Domain::start(const QByteArray &passcode) { const auto result = _local->start(passcode); if (result == Storage::StartResult::Success) { activateAfterStarting(); - Local::rewriteSettingsIfNeeded(); + crl::on_main(&Core::App(), [=] { suggestExportIfNeeded(); }); } else { Assert(!started()); } @@ -52,6 +56,19 @@ void Domain::finish() { base::take(_accounts); } +void Domain::suggestExportIfNeeded() { + Expects(started()); + + for (const auto &[index, account] : _accounts) { + if (const auto session = account->maybeSession()) { + const auto settings = session->local().readExportSettings(); + if (const auto availableAt = settings.availableAt) { + session->data().suggestStartExport(availableAt); + } + } + } +} + void Domain::accountAddedInStorage(AccountWithIndex accountWithIndex) { Expects(accountWithIndex.account != nullptr); @@ -95,15 +112,6 @@ void Domain::activateAfterStarting() { activate(toActivate); removePasscodeIfEmpty(); - - for (const auto &[index, account] : _accounts) { - if (const auto session = account->maybeSession()) { - const auto settings = session->local().readExportSettings(); - if (const auto availableAt = settings.availableAt) { - session->data().suggestStartExport(availableAt); - } - } - } } const std::vector &Domain::accounts() const { diff --git a/Telegram/SourceFiles/main/main_domain.h b/Telegram/SourceFiles/main/main_domain.h index 5872995529..6e9da8386c 100644 --- a/Telegram/SourceFiles/main/main_domain.h +++ b/Telegram/SourceFiles/main/main_domain.h @@ -80,6 +80,7 @@ private: void checkForLastProductionConfig(not_null account); void updateUnreadBadge(); void scheduleUpdateUnreadBadge(); + void suggestExportIfNeeded(); const QString _dataName; const std::unique_ptr _local; diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index fa9eeb3a55..2e8b53e467 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -595,6 +595,8 @@ QString readAutoupdatePrefix() { } void writeBackground(const Data::WallPaper &paper, const QImage &image) { + Expects(_settingsWriteAllowed); + if (!_backgroundCanWrite) { return; } diff --git a/Telegram/SourceFiles/storage/storage_domain.cpp b/Telegram/SourceFiles/storage/storage_domain.cpp index 9a037a4345..b382a74a4c 100644 --- a/Telegram/SourceFiles/storage/storage_domain.cpp +++ b/Telegram/SourceFiles/storage/storage_domain.cpp @@ -83,6 +83,7 @@ void Domain::startWithSingleAccount( if (auto localKey = account->local().peekLegacyLocalKey()) { _localKey = std::move(localKey); encryptLocalKey(passcode); + account->start(nullptr); } else { generateLocalKey(); account->start(account->prepareToStart(_localKey));