2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Fix app start without data.

This commit is contained in:
John Preston
2020-06-29 20:07:56 +04:00
parent 40971d6da6
commit cbad993bba
5 changed files with 23 additions and 15 deletions

View File

@@ -25,6 +25,10 @@ namespace Main {
Domain::Domain(const QString &dataName)
: _dataName(dataName)
, _local(std::make_unique<Storage::Domain>(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::AccountWithIndex> &Domain::accounts() const {