Use crl::on_main_queue for chained init steps.

This commit is contained in:
John Preston
2026-03-06 22:37:17 +04:00
parent ffea1e3917
commit 68e1504685
2 changed files with 32 additions and 54 deletions
+31 -53
View File
@@ -181,56 +181,7 @@ Session::Session(
_selfUserpicView = view.cloud; _selfUserpicView = view.cloud;
}, lifetime()); }, lifetime());
// Storage::Account uses Main::Account::session() in those methods. crl::on_main_queue(this, { [=] {
// So they can't be called during Main::Session construction.
// They are deferred via crl::on_main which fires after the
// constructor returns and _session is set.
//
// Steps are chained via crl::on_main so that paint events
// can be processed between heavy file reads.
const auto steps = std::make_shared<std::vector<Fn<void()>>>(
std::initializer_list<Fn<void()>>{
[=] {
local().readInstalledStickers();
}, [=] {
local().readInstalledMasks();
}, [=] {
local().readInstalledCustomEmoji();
}, [=] {
data().stickers().notifyUpdated(Data::StickersType::Stickers);
data().stickers().notifyUpdated(Data::StickersType::Masks);
data().stickers().notifyUpdated(Data::StickersType::Emoji);
}, [=] {
local().readFeaturedStickers();
}, [=] {
local().readFeaturedCustomEmoji();
}, [=] {
local().readRecentStickers();
local().readRecentMasks();
local().readFavedStickers();
local().readSavedGifs();
}, [=] {
data().stickers().notifyUpdated(Data::StickersType::Stickers);
data().stickers().notifyUpdated(Data::StickersType::Masks);
data().stickers().notifyUpdated(Data::StickersType::Emoji);
data().stickers().notifySavedGifsUpdated();
DEBUG_LOG(("Init: Account stored data load finished."));
},
});
const auto runNext = std::make_shared<Fn<void()>>();
*runNext = crl::guard(this, [=] {
if (steps->empty()) {
return;
}
auto step = std::move(steps->front());
steps->erase(steps->begin());
step();
if (!steps->empty()) {
crl::on_main(*runNext);
}
});
crl::on_main(this, [=] {
using Flag = Data::PeerUpdate::Flag; using Flag = Data::PeerUpdate::Flag;
changes().peerUpdates( changes().peerUpdates(
_user, _user,
@@ -259,9 +210,36 @@ Session::Session(
}); });
saveSettingsDelayed(); saveSettingsDelayed();
} }
}, [=] {
crl::on_main(*runNext); // Storage::Account uses Main::Account::session() in those methods.
}); // So they can't be called during Main::Session construction.
//
// They are deferred via crl::on_main which fires after the
// constructor returns and _session is set.
//
// Steps are chained via crl::on_main so that paint events
// can be processed between heavy file reads.
local().readInstalledStickers();
}, [=] {
local().readInstalledMasks();
}, [=] {
local().readInstalledCustomEmoji();
}, [=] {
local().readFeaturedStickers();
}, [=] {
local().readFeaturedCustomEmoji();
}, [=] {
local().readRecentStickers();
local().readRecentMasks();
local().readFavedStickers();
local().readSavedGifs();
}, [=] {
data().stickers().notifyUpdated(Data::StickersType::Stickers);
data().stickers().notifyUpdated(Data::StickersType::Masks);
data().stickers().notifyUpdated(Data::StickersType::Emoji);
data().stickers().notifySavedGifsUpdated();
DEBUG_LOG(("Init: Account stored data load finished."));
} }).dispatch();
#ifndef TDESKTOP_DISABLE_SPELLCHECK #ifndef TDESKTOP_DISABLE_SPELLCHECK
Spellchecker::Start(this); Spellchecker::Start(this);