Xbox Cloud Gaming app for PS5 Homebrew
C
Game page: the service's estimated wait to start the game, beside Play
Rafael Abud Ferreira7836dac299d7
diff --git a/src/app/price_loop.cpp b/src/app/price_loop.cppindex be9bf21..bd95354 100644--- a/src/app/price_loop.cpp+++ b/src/app/price_loop.cpp@@ -14,12 +14,14 @@#include <algorithm>#include <ctime>#include <map>+#include <memory>namespace xc::app {namespace {std::mutex g_priceMutex;std::string g_priceMarket, g_priceLanguage; // set by setPriceMarket() (empty: not yet)+std::unique_ptr<xcloud::GssvClient> g_queueClient; // g_priceMutexplatform::Thread g_priceThread;std::atomic<bool> g_stopPrices{false};constexpr int64_t kPriceTtlSeconds = 24 * 3600;@@ -47,6 +49,11 @@ void setPriceMarket(const std::string& market, const std::string& language) {g_priceLanguage = language;}+void setQueueClient(const xcloud::GssvClient* gssv) {+ std::lock_guard<std::mutex> lock(g_priceMutex);+ g_queueClient = gssv ? std::make_unique<xcloud::GssvClient>(*gssv) : nullptr;+}+namespace {void priceLoop() {@@ -89,6 +96,17 @@ void priceLoop() {}XC_LOGI("details of %s: %s", id.c_str(), ok ? "ok" : err.empty() ? "not in the catalog" : err.c_str());}+ // The open page's queue estimate (a game the account can play).+ if (std::string title = g_ui->queueWanted(platform::nowMs()); !title.empty()) {+ std::unique_ptr<xcloud::GssvClient> client;+ {+ std::lock_guard<std::mutex> lock(g_priceMutex);+ if (g_queueClient) client = std::make_unique<xcloud::GssvClient>(*g_queueClient);+ }+ int seconds = client ? client->titleWaitSeconds(title) : -1;+ XC_LOGI("queue estimate for %s: %d s", title.c_str(), seconds);+ g_ui->setQueueTime(title, seconds);+ }std::vector<std::string> ids = market.empty() ? std::vector<std::string>() : g_ui->pricesWanted(20, true);if (ids.empty()) {platform::sleepMs(300);diff --git a/src/app/ps5_app.h b/src/app/ps5_app.hindex 7631d0e..59984e2 100644--- a/src/app/ps5_app.h+++ b/src/app/ps5_app.h@@ -9,6 +9,7 @@#include "app/settings.h"#include "ui/app_ui.h"#include "ui/stream_menu.h"+#include "xcloud/gssv.h"#include <atomic>#include <cstdint>@@ -57,5 +58,8 @@ extern std::atomic<bool> g_restartWanted;// --- Store prices (price_loop.cpp) -----------------------------------------------void startPriceLoop();void setPriceMarket(const std::string& market, const std::string& language);+// The signed-in xCloud client (a copy), for the open game page's queue+// estimate; nullptr after signing out.+void setQueueClient(const xcloud::GssvClient* gssv);} // namespace xc::appdiff --git a/src/app/worker.cpp b/src/app/worker.cppindex 14a56e8..1429578 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -537,6 +537,7 @@ void loadLibrary(xcloud::GssvClient& gssv) {auto library = std::make_shared<app::Library>();library->setCachePath(platform::dataDir() + "/library.json");setPriceMarket(gssv.session().market.empty() ? "US" : gssv.session().market, ui::catalogLanguage());+ setQueueClient(&gssv);bool shown = false;// Hands the library's current state to the UI (copies).auto publish = [](const app::Library& lib) {@@ -639,6 +640,7 @@ void worker() {// Nothing of this account stays for the next one: its library// stops loading, its cache goes, the lists empty.stopHydration();+ setQueueClient(nullptr);am.signOut();::unlink((platform::dataDir() + "/library.json").c_str());{diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex ba93bad..f5007b6 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -599,6 +599,22 @@ std::string AppUi::detailWanted(uint64_t nowMs) {return detail_.productId;}+std::string AppUi::queueWanted(uint64_t nowMs) {+ std::lock_guard<std::mutex> lock(mutex_);+ if (screen_ != Screen::Details || !detail_.playable || detail_.purchasable || detail_.titleId.empty()) return {};+ if (detail_.titleId == queueAskedFor_ && nowMs - queueAskedAt_ < 60000) return {};+ queueAskedFor_ = detail_.titleId;+ queueAskedAt_ = nowMs;+ return detail_.titleId;+}++void AppUi::setQueueTime(const std::string& titleId, int seconds) {+ std::lock_guard<std::mutex> lock(mutex_);+ queueTitle_ = titleId;+ queueSeconds_ = seconds;+ if (detail_.titleId == titleId) dirty_ = true;+}+void AppUi::setDetailInfo(const std::string& productId, const std::string& description, const std::string& publisher,const std::vector<std::string>& categories, const std::string& heroUrl) {std::lock_guard<std::mutex> lock(mutex_);@@ -3113,6 +3129,15 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {c.line(tx - 8, ty - 13, tx + 13, ty, 4, kWhite);c.line(tx - 8, ty + 13, tx + 13, ty, 4, kWhite);fonts_.semibold.draw(c, tr(Str::Play), play.x + 108, play.y + 20, 32, kWhite);+ // The service's estimate of the wait to start it, beside Play.+ if (queueTitle_ == g->titleId && queueSeconds_ >= 0) {+ std::string wait = queueSeconds_ < 60 ? trf(Str::QueueSeconds, std::to_string(queueSeconds_))+ : trf(Str::QueueMinutes, std::to_string((queueSeconds_ + 59) / 60));+ int w = fonts_.regular.measure(wait, 26);+ Rect pill{play.x + play.w + 32, play.y + 14, w + 44, 48};+ c.fillRect(pill, rgba(0, 0, 0, 150), 24); // readable over any hero art+ fonts_.regular.draw(c, wait, pill.x + 22, pill.y + 10, 26, kWhite);+ }drawHints(c, {{kIconCross, tr(Str::Play)},{kIconOptions, tr(Str::GameSettings)},{kIconSquare, tr(hidden_.count(g->productId) ? Str::Unhide : Str::Hide)},diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex c1d56a5..27b6c8f 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -210,6 +210,11 @@ public:// The game whose page is open, if its description or hero art hasn't// arrived; asked again every 5 s while missing (empty otherwise).std::string detailWanted(uint64_t nowMs);+ // The open page's game (xCloud title id) whose queue estimate is due+ // (one a minute per game); empty when none.+ std::string queueWanted(uint64_t nowMs);+ // Its estimate in seconds (-1: unknown, not shown).+ void setQueueTime(const std::string& titleId, int seconds);// Fills in the open page when it shows `productId`, and keeps the details// for the next time that game's page opens.void setDetailInfo(const std::string& productId, const std::string& description, const std::string& publisher,@@ -456,6 +461,9 @@ private:std::set<std::string> pricesAsked_;std::string detailAskedFor_;uint64_t detailAskedAt_ = 0;+ std::string queueAskedFor_, queueTitle_;+ uint64_t queueAskedAt_ = 0;+ int queueSeconds_ = -1; // for queueTitle_struct DetailInfo {std::string description, publisher, heroUrl;std::vector<std::string> categories;diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 64af23e..b6b2129 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -260,6 +260,8 @@ constexpr Column kEnglish = {"A secure connection was refused: something on the network (a DNS server, proxy or filter) is answering for Microsoft's sites. Try without it, then try again.", // ConnectionIntercepted"PS5 date and time look wrong (%s): some content can't load. Set them in Settings > System > Date and Time.", // ClockWrongNotice"Your sign-in couldn't be saved on the console, so it will be asked again next time. Please report it (Settings > △).", // SignInNotSaved+ "Estimated wait: %s s", // QueueSeconds+ "Estimated wait: %s min", // QueueMinutes};constexpr Column kPortugueseBR = {@@ -490,6 +492,8 @@ constexpr Column kPortugueseBR = {"Uma conexão segura foi recusada: algo na rede (um servidor DNS, proxy ou filtro) está respondendo no lugar dos sites da Microsoft. Tente sem ele e tente de novo.","A data e a hora do PS5 parecem erradas (%s): parte do conteúdo não carrega. Acerte em Configurações > Sistema > Data e hora.","Não foi possível salvar o login no console, então ele será pedido de novo na próxima vez. Relate o problema (Configurações > △).",+ "Espera estimada: %s s", // QueueSeconds+ "Espera estimada: %s min", // QueueMinutes};constexpr Column kSpanish = {@@ -720,6 +724,8 @@ constexpr Column kSpanish = {"Se rechazó una conexión segura: algo en la red (un servidor DNS, proxy o filtro) responde en lugar de los sitios de Microsoft. Prueba sin él y vuelve a intentarlo.","La fecha y la hora de la PS5 parecen incorrectas (%s): parte del contenido no carga. Ajústalas en Ajustes > Sistema > Fecha y hora.","No se pudo guardar el inicio de sesión en la consola, así que se pedirá de nuevo la próxima vez. Infórmalo (Ajustes > △).",+ "Espera estimada: %s s", // QueueSeconds+ "Espera estimada: %s min", // QueueMinutes};constexpr Column kFrench = {@@ -950,6 +956,8 @@ constexpr Column kFrench = {"Une connexion sécurisée a été refusée : quelque chose sur le réseau (serveur DNS, proxy ou filtre) répond à la place des sites de Microsoft. Essayez sans, puis réessayez.","La date et l'heure de la PS5 semblent fausses (%s) : une partie du contenu ne se charge pas. Réglez-les dans Paramètres > Système > Date et heure.","Impossible d'enregistrer la connexion sur la console : elle sera redemandée la prochaine fois. Signalez-le (Paramètres > △).",+ "Attente estimée : %s s", // QueueSeconds+ "Attente estimée : %s min", // QueueMinutes};constexpr Column kGerman = {@@ -1180,6 +1188,8 @@ constexpr Column kGerman = {"Eine sichere Verbindung wurde abgelehnt: Etwas im Netzwerk (DNS-Server, Proxy oder Filter) antwortet anstelle der Microsoft-Seiten. Versuche es ohne und dann erneut.","Datum und Uhrzeit der PS5 scheinen falsch zu sein (%s): Einige Inhalte laden nicht. Stelle sie unter Einstellungen > System > Datum und Uhrzeit ein.","Die Anmeldung konnte nicht auf der Konsole gespeichert werden und wird beim nächsten Mal erneut abgefragt. Bitte melde das (Einstellungen > △).",+ "Geschätzte Wartezeit: %s s", // QueueSeconds+ "Geschätzte Wartezeit: %s Min.", // QueueMinutes};constexpr Column kItalian = {@@ -1410,6 +1420,8 @@ constexpr Column kItalian = {"Una connessione sicura è stata rifiutata: qualcosa nella rete (un server DNS, proxy o filtro) risponde al posto dei siti Microsoft. Prova senza e riprova.","La data e l'ora della PS5 sembrano errate (%s): alcuni contenuti non si caricano. Impostale in Impostazioni > Sistema > Data e ora.","Impossibile salvare l'accesso sulla console: verrà richiesto di nuovo la prossima volta. Segnalalo (Impostazioni > △).",+ "Attesa stimata: %s s", // QueueSeconds+ "Attesa stimata: %s min", // QueueMinutes};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 1187eee..c228c56 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -237,6 +237,8 @@ enum class Str {ConnectionIntercepted, // a certificate refused as untrusted or for another nameClockWrongNotice, // notification: signed in, but some content refused for the clock; "%s" = the dateSignInNotSaved, // notification: the sign-in couldn't be written (asked again next start)+ QueueSeconds, // game page, beside Play: the service's estimated wait (%s: seconds)+ QueueMinutes, // ... in minutes (%s)Count};diff --git a/src/xcloud/gssv.cpp b/src/xcloud/gssv.cppindex 288d3e9..6f2177e 100644--- a/src/xcloud/gssv.cpp+++ b/src/xcloud/gssv.cpp@@ -497,6 +497,14 @@ int GssvClient::waitTimeSeconds() {return static_cast<int>((*j)["estimatedTotalWaitTimeInSeconds"].asInt(-1));}+int GssvClient::titleWaitSeconds(const std::string& titleId) {+ if (titleId.empty() || login_.gsToken.empty()) return -1;+ auto r = net::perform(authed(resolution_, login_, "GET", url("/v1/waittime/" + titleId)));+ auto j = json::parse(r.body);+ if (!r.ok() || !j) return -1;+ return static_cast<int>((*j)["estimatedTotalWaitTimeInSeconds"].asInt(-1));+}+bool GssvClient::connect(const std::string& msaTransferToken, std::string& err) {json::Value body = json::Value::object();body.set("userToken", msaTransferToken);diff --git a/src/xcloud/gssv.h b/src/xcloud/gssv.hindex 2d68ee8..4148416 100644--- a/src/xcloud/gssv.h+++ b/src/xcloud/gssv.h@@ -125,6 +125,9 @@ public:bool sessionState(SessionStatus& out, std::string& err);// Estimated queue time in seconds while WaitingForResources (-1 unknown).int waitTimeSeconds();+ // Before a session: the estimated wait to start `titleId` (xCloud title+ // id), in seconds; -1 unknown.+ int titleWaitSeconds(const std::string& titleId);// Required in ReadyToConnect for cloud sessions: an MSA token for the// console-transfer purpose (see AuthManager::consoleTransferToken).bool connect(const std::string& msaTransferToken, std::string& err);