Xbox Cloud Gaming app for PS5 Homebrew
C
fix(core): hold splash until signed in with input lock, eliminate false 24 games popup, and clean logs
Rafael Abud Ferreirae3c85594b7a4
diff --git a/src/app/app_core.cpp b/src/app/app_core.cppindex 6e3044e..23463c7 100644--- a/src/app/app_core.cpp+++ b/src/app/app_core.cpp@@ -664,11 +664,6 @@ bool coreStartup() {g_ui->setOwned(initialLib->owned(), initialLib->purchasable(), initialLib->ownedKnown());g_ui->setMembership(initialLib->gamePassMember());g_ui->setSearchPools(initialLib->gamePassSearchPool(), initialLib->librarySearchPool());- struct stat accSt;- if (::stat((platform::dataDir() + "/account.json").c_str(), &accSt) == 0 && accSt.st_size > 0) {- g_ui->showHome();- g_ui->setLoading(true, 0, 0);- }XC_LOGI("instant-resume: loaded offline cache (%zu rows, %zu owned) in 0.01s",initialLib->rows().size(), initialLib->owned().size());}diff --git a/src/app/library.cpp b/src/app/library.cppindex ee39e49..f71fc3e 100644--- a/src/app/library.cpp+++ b/src/app/library.cpp@@ -826,8 +826,8 @@ size_t Library::syncDelta(xcloud::GssvClient& gssv, const Changed& changed, std:newProducts.push_back(t.productId);}for (const auto& alt : t.alternateProductIds) {- if (!alt.empty() && !products_.count(alt)) {- newProducts.push_back(alt);+ if (!alt.empty() && !t.titleId.empty() && t.titleId != "None") {+ cloudTitleOf_[alt] = t.titleId;}}}@@ -847,32 +847,46 @@ size_t Library::syncDelta(xcloud::GssvClient& gssv, const Changed& changed, std:std::sort(newProducts.begin(), newProducts.end());newProducts.erase(std::unique(newProducts.begin(), newProducts.end()), newProducts.end());- size_t newCount = newProducts.size();- if (newCount > 0) {+ size_t newCount = 0;+ if (!newProducts.empty()) {std::string fetchErr;xcloud::fetchProducts(newProducts, market_, language_, products_, fetchErr, false);- for (auto& row : layout_) {- if (row.isGrid) {- for (const auto& pid : newProducts) {- bool exists = false;- for (const auto& item : row.items) {- if (item.first == pid) { exists = true; break; }- }- if (!exists) {- std::string tid = cloudTitleOf_.count(pid) ? cloudTitleOf_[pid] : "";- row.items.emplace_back(pid, tid);- }- }- } else if (!row.recent && row.badges) {- for (const auto& pid : newProducts) {- bool exists = false;- for (const auto& item : row.items) {- if (item.first == pid) { exists = true; break; }+ std::vector<std::string> actuallyAdded;+ for (const auto& pid : newProducts) {+ auto it = products_.find(pid);+ if (it != products_.end() && !it->second.title.empty()) {+ actuallyAdded.push_back(pid);+ } else {+ products_[pid].productId = pid;+ products_[pid].detailedAt = platform::nowMs();+ }+ }+ newCount = actuallyAdded.size();++ if (newCount > 0) {+ for (auto& row : layout_) {+ if (row.isGrid) {+ for (const auto& pid : actuallyAdded) {+ bool exists = false;+ for (const auto& item : row.items) {+ if (item.first == pid) { exists = true; break; }+ }+ if (!exists) {+ std::string tid = cloudTitleOf_.count(pid) ? cloudTitleOf_[pid] : "";+ row.items.emplace_back(pid, tid);+ }}- if (!exists) {- std::string tid = cloudTitleOf_.count(pid) ? cloudTitleOf_[pid] : "";- row.items.insert(row.items.begin(), {pid, tid});+ } else if (!row.recent && row.badges) {+ for (const auto& pid : actuallyAdded) {+ bool exists = false;+ for (const auto& item : row.items) {+ if (item.first == pid) { exists = true; break; }+ }+ if (!exists) {+ std::string tid = cloudTitleOf_.count(pid) ? cloudTitleOf_[pid] : "";+ row.items.insert(row.items.begin(), {pid, tid});+ }}}}diff --git a/src/app/settings.cpp b/src/app/settings.cppindex ffe3d51..c77b2a0 100644--- a/src/app/settings.cpp+++ b/src/app/settings.cpp@@ -122,11 +122,11 @@ bool Settings::load(const std::string& path) {if ((*j)["settingsVersion"].asInt(1) < 2) {if (deband == 1) deband = 3;if (upscaler == 0) upscaler = 2;- XC_LOGI("settings: from before v0.8.0; block smoothing %d, upscaling %d", deband, upscaler);+ XC_LOGD("settings: from before v0.8.0; block smoothing %d, upscaling %d", deband, upscaler);}if ((*j)["settingsVersion"].asInt(1) < 3) {if (sharpness == 0) sharpness = 2;- XC_LOGI("settings: upgraded default sharpness to %d (FidelityFX RCAS)", sharpness);+ XC_LOGD("settings: upgraded default sharpness to %d (FidelityFX RCAS)", sharpness);}regionRtt.clear();for (const auto& [name, ms] : (*j)["regionRtt"].members())diff --git a/src/app/worker.cpp b/src/app/worker.cppindex 77fd611..da3ecc1 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -894,7 +894,11 @@ void loadLibrary(auth::AuthManager& am, xcloud::GssvClient& gssv, bool forceRefrif (!forceRefresh && existingLib && existingLib->ownedKnown()) {XC_LOGI("library: delta-sync against active library (forceRefresh=%d)", forceRefresh);- g_ui->setLoading(true, 0, 0);+ if (g_ui->screen() == ui::Screen::Splash) {+ g_ui->showSplash(ui::tr(ui::Str::LoadingGames));+ } else {+ g_ui->setLoading(true, 0, 0);+ }auto publish = [](const app::Library& lib) {g_ui->setRows(lib.rows());g_ui->setOwned(lib.owned(), lib.purchasable(), lib.ownedKnown());@@ -911,6 +915,13 @@ void loadLibrary(auth::AuthManager& am, xcloud::GssvClient& gssv, bool forceRefrstd::string msg = ui::trf(ui::Str::LibraryUpdatedCount, std::to_string(newCount));if (!shell::caps().console) g_ui->showToast(msg);platform::notify(msg);+ } else if (forceRefresh) {+ std::string msg = ui::tr(ui::Str::LibraryUpToDate);+ if (!shell::caps().console) g_ui->showToast(msg);+ platform::notify(msg);+ }+ if (g_ui->screen() == ui::Screen::Splash) {+ g_ui->showHome();}return;}diff --git a/src/display/gpu.cpp b/src/display/gpu.cppindex 957d949..c95ccd7 100644--- a/src/display/gpu.cpp+++ b/src/display/gpu.cpp@@ -725,14 +725,14 @@ bool createPipelines() {sizeof kShader_a4k_s_conv3};g.a4kReady = createPipeline(g.a4kD2s, kShader_a4k_d2s, sizeof kShader_a4k_d2s, d2s, 3, 0);for (int i = 0; i < 4 && g.a4kReady; ++i) g.a4kReady = createPipeline(g.a4kConv[i], code[i], bytes[i], conv, 2, 0);- if (!g.a4kReady) XC_LOGW("gpu: no Anime4K pipelines; FSR only");+ if (!g.a4kReady) XC_LOGD("gpu: no Anime4K pipelines; FSR only");const uint32_t* rcode[4] = {kShader_a4k_r_conv0, kShader_a4k_r_conv1, kShader_a4k_r_conv2, kShader_a4k_r_conv3};const size_t rbytes[4] = {sizeof kShader_a4k_r_conv0, sizeof kShader_a4k_r_conv1, sizeof kShader_a4k_r_conv2,sizeof kShader_a4k_r_conv3};g.restoreReady = g.a4kReady; // it uses the same feature mapsfor (int i = 0; i < 4 && g.restoreReady; ++i)g.restoreReady = createPipeline(g.restoreConv[i], rcode[i], rbytes[i], conv, 2, 0);- if (g.a4kReady && !g.restoreReady) XC_LOGW("gpu: no Anime4K Restore pipelines");+ if (g.a4kReady && !g.restoreReady) XC_LOGD("gpu: no Anime4K Restore pipelines");}const VkDescriptorPoolSize sizes[] = {{sampled, 40}, {storage, 40}};VkDescriptorPoolCreateInfo pool{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};@@ -839,7 +839,7 @@ bool videoImages(uint32_t w, uint32_t h) {!createImage(g.features[1], VK_FORMAT_R16G16B16A16_SFLOAT, w, h, VK_IMAGE_USAGE_STORAGE_BIT) ||!createImage(g.a4k, VK_FORMAT_R8G8B8A8_UNORM, w * 2, h * 2,VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT)) {- XC_LOGW("gpu: no Anime4K feature maps; FSR only");+ XC_LOGD("gpu: no Anime4K feature maps; FSR only");g.a4kReady = false;} else {// picture -> f0 -> f1 -> f0 -> f1 -> 2x (direct into upscaled when 2x == box, else g.a4k -> EASU)diff --git a/src/media/decoder.cpp b/src/media/decoder.cppindex d8037d9..efd1494 100644--- a/src/media/decoder.cpp+++ b/src/media/decoder.cpp@@ -41,10 +41,8 @@ void ffmpegLog(void*, int level, const char* fmt, va_list ap) {std::vsnprintf(line, sizeof line, fmt, ap);size_t n = std::strlen(line);while (n && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = 0;- // The first messages at info level (diagnostics), the rest at debug.- static std::atomic<int> shown{0};- if (shown++ < 40)- XC_LOGI("ffmpeg: %s", line);+ if (level <= AV_LOG_ERROR)+ XC_LOGE("ffmpeg: %s", line);elseXC_LOGD("ffmpeg: %s", line);}@@ -262,7 +260,7 @@ bool VideoDecoder::decode(const uint8_t* data, size_t len, Picture& out, uint32_}if (rc < 0 && rc != AVERROR(EAGAIN)) {needsKeyframe_ = true;- if (failuresLogged_++ < 20) XC_LOGI("h264 send failed: %s (%zu bytes)", averr(rc).c_str(), len);+ if (failuresLogged_++ == 0) XC_LOGD("h264 send failed: %s (%zu bytes)", averr(rc).c_str(), len);return false;}int sent = rc;@@ -273,8 +271,8 @@ bool VideoDecoder::decode(const uint8_t* data, size_t len, Picture& out, uint32_}if (rc < 0) {needsKeyframe_ = true;- if (failuresLogged_++ < 20)- XC_LOGI("h264 no picture: send=%d receive=%s (%zu bytes, first NAL type %d)", sent, averr(rc).c_str(),+ if (failuresLogged_++ == 0)+ XC_LOGD("h264 no picture: send=%d receive=%s (%zu bytes, first NAL type %d)", sent, averr(rc).c_str(),len, len > 4 ? data[4] & 0x1f : -1);return false;}@@ -282,7 +280,7 @@ bool VideoDecoder::decode(const uint8_t* data, size_t len, Picture& out, uint32_int again = avcodec_send_packet(ctx_, packet_);if (again < 0) {needsKeyframe_ = true;- if (failuresLogged_++ < 20) XC_LOGI("h264 packet dropped: %s (%zu bytes)", averr(again).c_str(), len);+ if (failuresLogged_++ == 0) XC_LOGD("h264 packet dropped: %s (%zu bytes)", averr(again).c_str(), len);}}diff --git a/src/net/http.cpp b/src/net/http.cppindex bbb4090..054f834 100644--- a/src/net/http.cpp+++ b/src/net/http.cpp@@ -846,6 +846,8 @@ Response performPaced(const Request& req) {int seconds = std::atoi(resp.header("retry-after").c_str());XC_LOGW("%s: HTTP 429, nothing more to it for %d s", url.host.c_str(), std::clamp(seconds > 0 ? seconds : 5, 1, 30));g_pacer.throttled(url.host, seconds, platform::nowMs());+ } else if (resp.status >= 500) {+ XC_LOGW("%s: HTTP %d (%s)", url.host.c_str(), resp.status, req.method.empty() ? "GET" : req.method.c_str());}return resp;}diff --git a/src/stream/h264_receiver.cpp b/src/stream/h264_receiver.cppindex 2f13569..cb79257 100644--- a/src/stream/h264_receiver.cpp+++ b/src/stream/h264_receiver.cpp@@ -335,9 +335,9 @@ void H264Receiver::accept(const uint8_t* d, size_t n, uint64_t now, const rtc::m// as a hole instead, NACKed when the next packet shows it (and// still missing if it was), then the frame dropped and a key frame// asked for, like any loss.- if (oversized_++ % 100 == 0)- XC_LOGW("video: RTP payload of %zu bytes is larger than %zu, treated as lost (%llu so far)", end - off,- kMaxPayload, static_cast<unsigned long long>(oversized_));+ if (oversized_++ == 0)+ XC_LOGW("video: RTP payload of %zu bytes is larger than %zu, treated as lost", end - off,+ kMaxPayload);return;}if (missing_.erase(seq)) ++stats_.recovered;diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex f416e7b..45d738e 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -1404,6 +1404,7 @@ void AppUi::showError(const std::string& message, const std::string& url) {error_ = message;errorUrl_ = url;errorGame_ = {};+ loading_ = false;regionRefused_ = countryPickerOpen_ = false;dirty_ = true;}@@ -1414,6 +1415,7 @@ void AppUi::showRegionRefused(const std::string& message) {error_ = message;errorUrl_.clear();errorGame_ = {};+ loading_ = false;regionRefused_ = true;countryPickerOpen_ = false;dirty_ = true;@@ -1425,6 +1427,7 @@ void AppUi::showPlayError(const std::string& message, const GameTile& game) {error_ = message;errorUrl_.clear();errorGame_ = game;+ loading_ = false;regionRefused_ = countryPickerOpen_ = false;dirty_ = true;}@@ -4038,6 +4041,10 @@ UiEvent AppUi::handle(const NavInput& in) {}} else if (in.accept) {ev.action = Action::Retry;+ } else if ((in.square || in.back) && !regionRefused_ && (!rows_.empty() || !owned_.empty())) {+ screen_ = Screen::Home;+ loading_ = false;+ dirty_ = true;}if (regionRefused_ && in.square) {countryPickerOpen_ = true;@@ -5491,6 +5498,9 @@ void AppUi::drawError(Canvas& c) {drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconSquare, tr(Str::TryOtherCountry)},{kIconOptions, tr(Str::Settings)}, {kIconTriangle, tr(Str::ReportProblem)},{kIconTouchpad, tr(Str::HoldSignOut)}});+ else if (!rows_.empty() || !owned_.empty())+ drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconSquare, tr(Str::OfflineMode)},+ {kIconTriangle, tr(Str::ReportProblem)}, {kIconTouchpad, tr(Str::HoldSignOut)}});elsedrawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconTriangle, tr(Str::ReportProblem)},{kIconTouchpad, tr(Str::HoldSignOut)}});diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 2c295c0..36cf8e4 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -439,6 +439,7 @@ constexpr Column kEnglish = {"Hold to reset", // HoldToReset"Library is already up to date", // LibraryUpToDate"Library updated (%s new games)", // LibraryUpdatedCount+ "Offline mode", // OfflineMode};constexpr Column kPortugueseBR = {@@ -848,6 +849,7 @@ constexpr Column kPortugueseBR = {"Segure para restaurar", // HoldToReset"Biblioteca já está atualizada", // LibraryUpToDate"Biblioteca atualizada (%s novos jogos)", // LibraryUpdatedCount+ "Modo offline", // OfflineMode};constexpr Column kSpanish = {@@ -1257,6 +1259,7 @@ constexpr Column kSpanish = {"Mantén para restablecer", // HoldToReset"La biblioteca ya está actualizada", // LibraryUpToDate"Biblioteca actualizada (%s nuevos juegos)", // LibraryUpdatedCount+ "Modo sin conexión", // OfflineMode};constexpr Column kFrench = {@@ -1666,6 +1669,7 @@ constexpr Column kFrench = {"Maintenir pour réinitialiser", // HoldToReset"La bibliothèque est déjà à jour", // LibraryUpToDate"Bibliothèque mise à jour (%s nouveaux jeux)", // LibraryUpdatedCount+ "Mode hors ligne", // OfflineMode};constexpr Column kGerman = {@@ -2075,6 +2079,7 @@ constexpr Column kGerman = {"Halten zum Zurücksetzen", // HoldToReset"Bibliothek ist bereits aktuell", // LibraryUpToDate"Bibliothek aktualisiert (%s neue Spiele)", // LibraryUpdatedCount+ "Offline-Modus", // OfflineMode};constexpr Column kItalian = {@@ -2484,6 +2489,7 @@ constexpr Column kItalian = {"Tieni premuto per ripristinare", // HoldToReset"La libreria è già aggiornata", // LibraryUpToDate"Libreria aggiornata (%s nuovi giochi)", // LibraryUpdatedCount+ "Modalità non in linea", // OfflineMode};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 1a07603..7e4f847 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -416,6 +416,7 @@ enum class Str {HoldToReset,LibraryUpToDate,LibraryUpdatedCount,+ OfflineMode,Count};diff --git a/src/util/log.cpp b/src/util/log.cppindex 70db4bf..8e31c86 100644--- a/src/util/log.cpp+++ b/src/util/log.cpp@@ -17,6 +17,11 @@ FILE* g_file = nullptr;std::string g_recentLogs;constexpr size_t kMaxRecentLogs = 64 * 1024; // 64 KiB ring buffer+std::string g_lastMsg;+Level g_lastLevel = Level::Info;+bool g_hasLastMsg = false;+size_t g_repeatCount = 0;+const char* tag(Level l) {switch (l) {case Level::Debug: return "D";@@ -26,12 +31,59 @@ const char* tag(Level l) {}return "?";}++void appendRecentLocked(const char* line, size_t lineLen) {+ if (lineLen == 0) return;+ g_recentLogs.append(line, lineLen);+ if (g_recentLogs.size() > kMaxRecentLogs) {+ size_t excess = g_recentLogs.size() - kMaxRecentLogs;+ size_t nextNl = g_recentLogs.find('\n', excess);+ if (nextNl != std::string::npos && nextNl + 1 < g_recentLogs.size()) {+ g_recentLogs.erase(0, nextNl + 1);+ } else {+ g_recentLogs.erase(0, excess);+ }+ }+}++void flushRepeatsLocked() {+ if (g_repeatCount > 0) {+ char repLine[128];+ int len = std::snprintf(repLine, sizeof repLine, " [last message repeated %zu %s]\n",+ g_repeatCount, g_repeatCount == 1 ? "time" : "times");+ if (len > 0) {+ std::fprintf(stderr, "%s", repLine);+ if (g_file) {+ std::fputs(repLine, g_file);+ std::fflush(g_file);+ }+ appendRecentLocked(repLine, static_cast<size_t>(len));+ }+ g_repeatCount = 0;+ }+ g_hasLastMsg = false;+ g_lastMsg.clear();+}++struct LogCleanup {+ ~LogCleanup() {+ std::lock_guard<std::mutex> lock(g_mutex);+ flushRepeatsLocked();+ if (g_file) {+ std::fclose(g_file);+ g_file = nullptr;+ }+ }+};+static LogCleanup s_cleanup;+} // namespacevoid setLevel(Level level) { g_level = level; }bool setFile(const char* path) {std::lock_guard<std::mutex> lock(g_mutex);+ flushRepeatsLocked();if (g_file) {std::fclose(g_file);g_file = nullptr;@@ -43,9 +95,15 @@ bool setFile(const char* path) {std::string recentLogs() {std::lock_guard<std::mutex> lock(g_mutex);+ flushRepeatsLocked();return g_recentLogs;}+void flush() {+ std::lock_guard<std::mutex> lock(g_mutex);+ flushRepeatsLocked();+}+void write(Level level, const char* fmt, ...) {if (level < g_level) return;char msg[2048];@@ -64,23 +122,21 @@ void write(Level level, const char* fmt, ...) {int lineLen = std::snprintf(line, sizeof line, "%s [%s] %s\n", ts, tag(level), msg);std::lock_guard<std::mutex> lock(g_mutex);+ if (g_hasLastMsg && level == g_lastLevel && g_lastMsg == msg) {+ ++g_repeatCount;+ return;+ }+ flushRepeatsLocked();+ g_lastMsg = msg;+ g_lastLevel = level;+ g_hasLastMsg = true;+std::fprintf(stderr, "%s", line);if (g_file) {std::fputs(line, g_file);std::fflush(g_file);}- if (lineLen > 0) {- g_recentLogs.append(line, static_cast<size_t>(lineLen));- if (g_recentLogs.size() > kMaxRecentLogs) {- size_t excess = g_recentLogs.size() - kMaxRecentLogs;- size_t nextNl = g_recentLogs.find('\n', excess);- if (nextNl != std::string::npos && nextNl + 1 < g_recentLogs.size()) {- g_recentLogs.erase(0, nextNl + 1);- } else {- g_recentLogs.erase(0, excess);- }- }- }+ appendRecentLocked(line, static_cast<size_t>(lineLen));}} // namespace xc::logdiff --git a/src/util/log.h b/src/util/log.hindex 5a886ed..d83e929 100644--- a/src/util/log.h+++ b/src/util/log.h@@ -17,6 +17,9 @@ bool setFile(const char* path);// Returns recent log lines kept in memory (up to 64 KiB).std::string recentLogs();+// Flushes any buffered repeated log notifications.+void flush();+void write(Level level, const char* fmt, ...) __attribute__((format(printf, 2, 3)));} // namespace xc::logdiff --git a/tests/test_main.cpp b/tests/test_main.cppindex 7034973..1190765 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -33,6 +33,7 @@#include "ui/stream_menu.h"#include "ui/strings.h"#include "util/json.h"+#include "util/log.h"#include "auth/auth_manager.h"#include "stream/h264_receiver.h"#include "input/kbm.h"@@ -5344,7 +5345,188 @@ static void testBlock1Corrections() {}}+static void testBloco2Corrections() {+ // 1. Splash screen input lock & Screen::Error offline option+ {+ ui::Fonts fonts;+ ui::ImageCache images([] {});+ ui::AppUi app(fonts, images);+ CHECK(app.screen() == ui::Screen::Splash);++ // All inputs while on Splash must be ignored/dropped+ ui::NavInput in;+ in.accept = true;+ in.back = true;+ in.options = true;+ in.square = true;+ in.triangle = true;+ in.up = true;+ in.down = true;+ in.left = true;+ in.right = true;+ ui::UiEvent ev = app.handle(in);+ CHECK(ev.action == ui::Action::None);+ CHECK(app.screen() == ui::Screen::Splash);++ // Error screen without cached rows cannot enter offline mode+ app.showError("Connection failed");+ CHECK(app.screen() == ui::Screen::Error);+ in = {};+ in.square = true;+ ev = app.handle(in);+ CHECK(app.screen() == ui::Screen::Error);++ // Populate cached rows+ ui::GameRow row;+ row.title = "Offline Cached Games";+ ui::GameTile tile;+ tile.productId = "PROD_CACHE_1";+ tile.titleId = "TITLE_CACHE_1";+ tile.name = "Offline Game";+ row.tiles.push_back(tile);+ app.setRows({row});++ // Error screen WITH cached rows: Square or Circle(Back) enters offline mode (Screen::Home)+ in = {};+ in.square = true;+ ev = app.handle(in);+ CHECK(app.screen() == ui::Screen::Home);++ app.showError("Network timed out");+ CHECK(app.screen() == ui::Screen::Error);+ in = {};+ in.back = true;+ ev = app.handle(in);+ CHECK(app.screen() == ui::Screen::Home);++ // Error screen: loading flag is cleared when error is displayed and when offline mode is entered+ app.setLoading(true, 5, 10);+ app.showError("Disconnected");+ CHECK(app.screen() == ui::Screen::Error);+ in = {};+ in.square = true;+ ev = app.handle(in);+ CHECK(app.screen() == ui::Screen::Home);++ // Error screen with owned games but empty rows: can enter offline mode+ ui::AppUi appOwned(fonts, images);+ ui::GameTile ownedTile;+ ownedTile.productId = "OWNED_1";+ ownedTile.titleId = "TITLE_1";+ ownedTile.playable = true;+ appOwned.setOwned({ownedTile}, {}, true);+ appOwned.showError("Auth error");+ CHECK(appOwned.screen() == ui::Screen::Error);+ in = {};+ in.square = true;+ ev = appOwned.handle(in);+ CHECK(appOwned.screen() == ui::Screen::Home);+ }++ // 2. syncDelta: Eliminate false 24 new games popup+ {+ app::Library lib;+ xcloud::GssvClient gssv;+ std::string err;++ // Set up test transport where listTitles returns 24 alternate IDs+ // and fetchProducts returns empty/failure for them+ net::setTestTransport([&](const net::Request& req) {+ net::Response r;+ if (req.url.find("titles") != std::string::npos) {+ r.status = 200;+ // Return 1 title with 24 alternate product IDs+ json::Value root = json::Value::object();+ json::Value results = json::Value::array();+ json::Value item = json::Value::object();+ item.set("titleId", "GAME_HQ");+ json::Value details = json::Value::object();+ details.set("productId", "PROD_HQ");+ item.set("details", details);+ json::Value alts = json::Value::array();+ for (int i = 1; i <= 24; ++i) {+ alts.push("ALT_PROD_" + std::to_string(i));+ }+ item.set("alternateProductIds", alts);+ results.push(item);+ root.set("results", results);+ r.body = root.dump();+ return r;+ }+ if (req.url.find("sigls") != std::string::npos) {+ r.status = 200;+ r.body = R"({"productIds":["PROD_HQ"]})";+ return r;+ }+ if (req.url.find("products") != std::string::npos) {+ r.status = 200;+ // Only return PROD_HQ with valid metadata, none of the 24 alternate IDs+ r.body = R"({+ "Products": {+ "PROD_HQ": {+ "ProductTitle": "Call of Duty HQ"+ }+ }+ })";+ return r;+ }+ r.status = 200;+ r.body = "{}";+ return r;+ });++ // First sync: PROD_HQ is added (1 new game)+ size_t count1 = lib.syncDelta(gssv, [&] {}, err);+ CHECK(count1 == 1);++ // Second sync (subsequent boot): PROD_HQ is already in products_,+ // and 24 alternate IDs must NOT be computed as new games! newCount must be 0!+ size_t count2 = lib.syncDelta(gssv, [&] {}, err);+ CHECK(count2 == 0);++ net::setTestTransport({});+ }++ // 3. Log hygiene & consecutive duplicate suppression+ {+ xc::log::setLevel(xc::log::Level::Info);++ // Write identical message 5 times+ XC_LOGI("bloco2_hygiene_test_repeated_log");+ XC_LOGI("bloco2_hygiene_test_repeated_log");+ XC_LOGI("bloco2_hygiene_test_repeated_log");+ XC_LOGI("bloco2_hygiene_test_repeated_log");+ XC_LOGI("bloco2_hygiene_test_repeated_log");++ // Write a distinct message to trigger repeat count flush+ XC_LOGI("bloco2_hygiene_test_distinct_log");++ std::string after = xc::log::recentLogs();+ CHECK(after.find("bloco2_hygiene_test_repeated_log") != std::string::npos);+ CHECK(after.find("last message repeated 4 times") != std::string::npos);+ CHECK(after.find("bloco2_hygiene_test_distinct_log") != std::string::npos);++ // Test singular repetition: exactly 2 identical logs+ XC_LOGI("bloco2_hygiene_test_twice_log");+ XC_LOGI("bloco2_hygiene_test_twice_log");+ xc::log::flush();+ std::string afterTwice = xc::log::recentLogs();+ CHECK(afterTwice.find("bloco2_hygiene_test_twice_log") != std::string::npos);+ CHECK(afterTwice.find("last message repeated 1 time]") != std::string::npos);++ // Test flush clears last message state: same message emitted after flush is printed afresh+ XC_LOGI("bloco2_hygiene_test_twice_log");+ xc::log::flush();+ std::string afterFlush = xc::log::recentLogs();+ size_t pos1 = afterFlush.find("bloco2_hygiene_test_twice_log");+ CHECK(pos1 != std::string::npos);+ size_t pos2 = afterFlush.find("bloco2_hygiene_test_twice_log", pos1 + 1);+ CHECK(pos2 != std::string::npos);+ }+}+int main() {+ testBloco2Corrections();testBlock1Corrections();testCallOfDutyModernWarfare4CatalogAndRefresh();testBlock3Features();