From 68e1504685854156b85bde73d6555d051e39f034 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 6 Mar 2026 22:37:17 +0400 Subject: [PATCH] Use crl::on_main_queue for chained init steps. --- Telegram/SourceFiles/main/main_session.cpp | 84 ++++++++-------------- Telegram/lib_crl | 2 +- 2 files changed, 32 insertions(+), 54 deletions(-) diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index 31be2eaa86..3b00a73f31 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -181,56 +181,7 @@ Session::Session( _selfUserpicView = view.cloud; }, lifetime()); - // 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. - const auto steps = std::make_shared>>( - std::initializer_list>{ - [=] { - 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>(); - *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, [=] { + crl::on_main_queue(this, { [=] { using Flag = Data::PeerUpdate::Flag; changes().peerUpdates( _user, @@ -259,9 +210,36 @@ Session::Session( }); 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 Spellchecker::Start(this); diff --git a/Telegram/lib_crl b/Telegram/lib_crl index a41edfcfa8..f770e4e8be 160000 --- a/Telegram/lib_crl +++ b/Telegram/lib_crl @@ -1 +1 @@ -Subproject commit a41edfcfa8c04057deb8a1a38fca145248a9421a +Subproject commit f770e4e8be24553b22278a8ac07f5eb3c7aa6547