Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Keep the Queue's place when opening a game from it

Leonardo Lobato096c15f0116c
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index bb0e514..cc8f4e7 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -2102,7 +2102,7 @@ void Controller::TickInstalls() {
for (const auto& game : snapshot.installed) installed.push_back({game.id, game.install_bytes, game.volume_id, game.available});
std::vector<LiveCompletedDownload> completed;
for (const auto& finished : snapshot.completed)
- completed.push_back({finished.id, finished.install_bytes, finished.volume_id, finished.finished_at});
+ completed.push_back({finished.id, finished.install_bytes, finished.volume_id, finished.finished_at, finished.update_bytes});
model_.UpdateInstalls(jobs, installed, completed);
}
void Controller::TickStoreDetails() {
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index c7da5ea..14900a8 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -2216,7 +2216,9 @@ void Simulation::UpdateInstalls(const std::vector<LiveInstallJob>& jobs, const s
job.game_id = finished.game_id;
job.queue_order = order++;
job.state = JobState::Downloaded;
- job.completed_bytes = job.total_bytes = finished.install_bytes;
+ // An update lists what it downloaded, not the whole game.
+ job.update = finished.update_bytes > 0;
+ job.completed_bytes = job.total_bytes = job.update ? finished.update_bytes : finished.install_bytes;
job.volume_id = finished.volume_id;
job.finished_at = finished.finished_at;
job.completion_applied = true;
@@ -4195,7 +4197,11 @@ void Simulation::rebuild_view() {
state_.navigation.selected_game_id = selected_game_id;
}
view_ = {};
- if (state_.navigation.route != Route::Downloads) queue_shown_ = false;
+ // A game's page opened from the Queue is part of that visit: Back finds the same section open.
+ const bool queue_details = state_.navigation.route == Route::Details && state_.navigation.detail_origin == Route::Downloads &&
+ !queue_return_focus_.empty();
+ if (state_.navigation.route != Route::Downloads && !queue_details) queue_shown_ = false;
+ if (state_.navigation.route != Route::Downloads && !queue_details) queue_return_focus_.clear();
view_.surface = route_name(state_.navigation.route);
view_.show_simulation_label = state_.simulation_mode;
if (state_.editor.active) view_.surface = "keyboard";
@@ -6165,6 +6171,16 @@ void Simulation::close_modal() {
state_.navigation.focus_key = opener;
}
+// A game's page from a Queue row (after its dialog closed): it starts on its first action, as from the
+// Library, and Back returns to that row with the same section open.
+void Simulation::open_details_from_queue(GameId id) {
+ queue_return_focus_ = state_.navigation.focus_key;
+ state_.navigation.selected_game_id = id; state_.navigation.detail_id = id;
+ state_.navigation.detail_origin = Route::Downloads; state_.navigation.route = Route::Details;
+ details_primary_pending_ = live();
+ state_.navigation.focus_key = live() ? "details-favorite" : (is_installed(state_, id) ? "details-play" : "details-install");
+}
+
void Simulation::start_logs() {
state_.log_state = LogState::Loading;
state_.log_lines.clear();
@@ -6588,6 +6604,8 @@ void Simulation::cancel() {
} else if (state_.navigation.route == Route::Details || state_.navigation.route == Route::Session) {
state_.navigation.route = state_.navigation.route == Route::Session ? Route::Details : state_.navigation.detail_origin;
state_.navigation.focus_key = state_.navigation.route == Route::Details ? "details-play" : game_key(state_.navigation.selected_game_id);
+ if (state_.navigation.route == Route::Downloads && !queue_return_focus_.empty()) state_.navigation.focus_key = queue_return_focus_;
+ queue_return_focus_.clear();
} else if (state_.navigation.route != Route::Home) {
state_.navigation.route = Route::Home;
state_.navigation.focus_key = game_key(state_.navigation.selected_game_id);
@@ -7407,8 +7425,7 @@ void Simulation::activate() {
} else if (action_name.rfind("prep-open-", 0) == 0) {
const auto id = key_id(std::string_view(action_name).substr(std::strlen("prep-open-")));
close_modal();
- state_.navigation.selected_game_id = id; state_.navigation.detail_id = id;
- state_.navigation.detail_origin = Route::Downloads; state_.navigation.route = Route::Details;
+ open_details_from_queue(id);
} else if (action_name.rfind("prep-recreate-", 0) == 0) {
// The same request as Maintenance › Recreate bottle. The runtime refuses to remove a title that runs,
// so this doesn't wait for the console's answer on whether the game runs, as Maintenance's rows do.
@@ -7703,10 +7720,10 @@ void Simulation::activate() {
}
close_modal();
} else if (action_name.rfind("job-open-", 0) == 0) {
- if (const auto* job = find_job(state_, action_name.substr(9))) {
- state_.navigation.selected_game_id = job->game_id; state_.navigation.detail_id = job->game_id; state_.navigation.detail_origin = Route::Downloads; state_.navigation.route = Route::Details;
- }
+ const auto* job = find_job(state_, action_name.substr(9));
+ const auto id = job ? job->game_id : GameId{};
close_modal();
+ if (id.valid()) open_details_from_queue(id);
} else if (action_name == "job-clear-completed") {
close_modal();
if (live()) pending_install_requests_.push_back({InstallRequestKind::ClearCompleted, {}});
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index d566623..f644e6e 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -126,6 +126,7 @@ struct LiveCompletedDownload {
std::uint64_t install_bytes = 0;
std::string volume_id;
std::int64_t finished_at = 0; // Unix seconds
+ std::uint64_t update_bytes = 0; // an update: what it downloaded; 0 for an install
};
// A drive the real install service can use. Space is absent when the platform cannot report it.
struct LiveVolume {
@@ -1146,6 +1147,7 @@ private:
int settings_focus_index_ = 0;
int queue_focus_index_ = 0; // Queue: the focused row's place, for when that row goes away
bool queue_shown_ = false; // Queue was on screen at the last rebuild
+ std::string queue_return_focus_; // Queue: the row a game page was opened from, focused again on Back
std::string settings_focus_section_;
struct OrganizationJournalEntry {
@@ -1207,6 +1209,7 @@ private:
void open_modal(ModalEntry modal);
void prepare_next(GameId id);
void close_modal();
+ void open_details_from_queue(GameId id);
void start_editor(std::string purpose, std::string value, bool secret = false);
// Sign-in screen: opened in the remembered method, its actions, and the form's secrets wiped.
void open_sign_in(bool reauthenticate = false);
diff --git a/src/homebrew/view.cpp b/src/homebrew/view.cpp
index 313e826..1a8492f 100644
--- a/src/homebrew/view.cpp
+++ b/src/homebrew/view.cpp
@@ -2112,7 +2112,7 @@ class Render::Impl
if (entry->completed)
{
// The files are here; preparing them is the Preparation section's.
- value = job->game_id.store == Store::kLocal ? "Copied" : "Downloaded";
+ value = job->game_id.store == Store::kLocal ? "Copied" : job->update ? "Updated" : "Downloaded";
tone = "good";
aside = byte_count(job->total_bytes);
if (job->finished_at > 0 && !state.simulation_mode)
diff --git a/src/installs/install_service.cpp b/src/installs/install_service.cpp
index ebea56a..a34d18e 100644
--- a/src/installs/install_service.cpp
+++ b/src/installs/install_service.cpp
@@ -106,7 +106,7 @@ std::vector<CompletedDownload> AllCompletedDownloads(const std::vector<Installed
for (const auto& game : installed) {
if (game.finished_at <= 0 || game.finished_at > now || now - game.finished_at > kCompletedDays * 24 * 60 * 60) continue;
if (std::find(dismissed.begin(), dismissed.end(), std::make_pair(game.id, game.finished_at)) != dismissed.end()) continue;
- completed.push_back({game.id, game.install_bytes, game.volume_id, game.finished_at});
+ completed.push_back({game.id, game.install_bytes, game.volume_id, game.finished_at, game.update_bytes});
}
std::stable_sort(completed.begin(), completed.end(), [](const CompletedDownload& left, const CompletedDownload& right) {
return left.finished_at > right.finished_at;
@@ -1066,11 +1066,13 @@ void InstallService::Run() {
// Uninstalled meanwhile: the uninstall deletes the files.
erase_job();
} else if (job && result.ok && next_update) {
+ const auto downloaded = job->view.done_bytes;
erase_job();
for (auto& game : installed_) {
if (game.id != *next) continue;
game.install_bytes = result.install_bytes;
game.finished_at = WallNow();
+ game.update_bytes = downloaded;
game.record = ReadInstallRecord(next_root + "/" + kRecord);
}
} else if (job && job->cancel_requested && next_update && !locked_on_disk) {
diff --git a/src/installs/install_service.h b/src/installs/install_service.h
index c869ec3..744fd45 100644
--- a/src/installs/install_service.h
+++ b/src/installs/install_service.h
@@ -106,6 +106,8 @@ struct InstalledGame {
// What its install record says (branch, language, depots); none while its folder is unavailable or
// the record can't be read.
std::optional<InstalledRecord> record;
+ // An update that finished this session: what it downloaded (0 for an install, or after a restart).
+ std::uint64_t update_bytes = 0;
};
// A recent finished download that Downloads lists after the queue until the player dismisses it.
@@ -114,6 +116,7 @@ struct CompletedDownload {
std::uint64_t install_bytes = 0;
std::string volume_id;
std::int64_t finished_at = 0;
+ std::uint64_t update_bytes = 0; // an update: what it downloaded; 0 for an install
};
// Installs that finished at most `kCompletedDays` before `now` and were not dismissed (a dismissal
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index adbfb72..c6e38f9 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -2524,6 +2524,46 @@ void live_completed_downloads_follow_the_queue() {
"Clear completed empties the list");
}
+void live_queue_game_page_returns_to_its_row() {
+ using namespace playden::homebrew;
+ auto model = make_live();
+ model.SetWallClock(100'000);
+ model.UpdateAccount({AuthState::SignedIn, "123", "Synthetic", {}, {}, true});
+ check(model.UpdateLibrary({{game(SteamId(42), "Updated"), game(SteamId(43), "Installed"), game(SteamId(44), "Another"),
+ game(SteamId(46), "One more"), game(SteamId(47), "And another"), game(SteamId(45), "Earlier")},
+ false, {}, false, false, {}}), "library loaded");
+ // 42 finished an update that downloaded 30 of its 100 bytes. 45 is far down the list.
+ model.UpdateInstalls({}, {{SteamId(42), 100, "internal", true}, {SteamId(43), 50, "internal", true}, {SteamId(44), 10, "internal", true},
+ {SteamId(46), 10, "internal", true}, {SteamId(47), 10, "internal", true}, {SteamId(45), 300, "m2", true}},
+ {{SteamId(43), 50, "internal", 99'990}, {SteamId(42), 100, "internal", 99'880, 30}, {SteamId(44), 10, "internal", 99'870},
+ {SteamId(46), 10, "internal", 99'860}, {SteamId(47), 10, "internal", 99'850}, {SteamId(45), 300, "m2", 92'800}});
+ const auto& jobs = model.state().jobs;
+ const auto updated = std::find_if(jobs.begin(), jobs.end(), [](const Job& job) { return job.game_id == SteamId(42); });
+ const auto installed = std::find_if(jobs.begin(), jobs.end(), [](const Job& job) { return job.game_id == SteamId(43); });
+ check(updated != jobs.end() && updated->update && updated->total_bytes == 30 && updated->completed_bytes == 30,
+ "a finished update lists what it downloaded, not the whole game");
+ check(installed != jobs.end() && !installed->update && installed->total_bytes == 50, "a finished install lists the game's size");
+
+ model.action("r1");
+ model.action("r1");
+ check(model.state().navigation.route == Route::Downloads && model.state().queue_expanded == kQueueDownloads, "Downloads open");
+ // The page's first action, as the Library opens it.
+ check(model.action("details:45"), "details open");
+ const auto first_action = model.state().navigation.focus_key;
+ model.action("circle");
+ check(model.state().navigation.route == Route::Downloads, "back in Downloads");
+ activate(model, "job-45");
+ activate(model, "job-open-45");
+ check(model.state().navigation.route == Route::Details && model.state().navigation.detail_id == SteamId(45), "Open game shows its page");
+ check(model.state().navigation.focus_key == first_action,
+ "the page starts on its first action, not on the button at the Queue row's place");
+ model.action("circle");
+ check(model.state().navigation.route == Route::Downloads && model.state().navigation.focus_key == "job-45" &&
+ model.state().queue_expanded == kQueueDownloads && has_row(model, "job-45"),
+ "Back returns to the same row, with Downloads still open");
+
+}
+
void game_collections_sheet_adds_and_removes_the_game() {
using namespace playden::homebrew;
auto model = make_live();
@@ -3778,6 +3818,7 @@ int main() {
live_install_confirmation_checks_space_and_unknowns();
live_install_notifications();
live_completed_downloads_follow_the_queue();
+ live_queue_game_page_returns_to_its_row();
live_download_card_keeps_queue_order();
game_collections_sheet_adds_and_removes_the_game();
live_log_viewer();
diff --git a/tests/install_service_test.cpp b/tests/install_service_test.cpp
index 63551d3..dc80289 100644
--- a/tests/install_service_test.cpp
+++ b/tests/install_service_test.cpp
@@ -939,6 +939,10 @@ void UpdatesAnInstalledGame(const std::filesystem::path& root) {
for (const auto& entry : snapshot.installed)
if (entry.id == game) CHECK(entry.record && entry.record->branch == "beta" && entry.finished_at > 0);
CHECK(std::count_if(snapshot.installed.begin(), snapshot.installed.end(), [&](const InstalledGame& g) { return g.id == game; }) == 1);
+ // Its finished entry says what the update downloaded, not the game's size.
+ const auto finished = std::find_if(snapshot.completed.begin(), snapshot.completed.end(),
+ [&](const playden::installs::CompletedDownload& entry) { return entry.id == game; });
+ CHECK(finished != snapshot.completed.end() && finished->update_bytes == 10 && finished->install_bytes == 8192);
CHECK(RegistryLine(root, "700") == "700\tinternal\t8192");
{
std::lock_guard<std::mutex> lock(runner.mutex);