Skip to content

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

C++

Keep the chosen Library sort when using More

Leonardo Lobatofdd4241d4b10
diff --git a/src/homebrew/browse.cpp b/src/homebrew/browse.cpp
index c33b647..e975153 100644
--- a/src/homebrew/browse.cpp
+++ b/src/homebrew/browse.cpp
@@ -144,7 +144,8 @@ std::vector<const Game*> filtered_games(const State& state)
result.push_back(&game);
}
- if (state.library.sort == "name")
+ const auto& sort = state.library.view_sort.empty() ? state.library.sort : state.library.view_sort;
+ if (sort == "name")
{
std::stable_sort(result.begin(), result.end(), [&](const Game* left, const Game* right) {
if(!state.simulation_mode) {
@@ -154,25 +155,25 @@ std::vector<const Game*> filtered_games(const State& state)
return ascii_lower(left->title) < ascii_lower(right->title);
});
}
- else if (state.library.sort == "recent-played")
+ else if (sort == "recent-played")
{
std::stable_sort(result.begin(), result.end(), [](const Game* left, const Game* right) {
return optional_descending(left->last_played, right->last_played);
});
}
- else if (state.library.sort == "recent-added")
+ else if (sort == "recent-added")
{
std::stable_sort(result.begin(), result.end(), [](const Game* left, const Game* right) {
return optional_descending(left->added_at, right->added_at);
});
}
- else if (state.library.sort == "playtime")
+ else if (sort == "playtime")
{
std::stable_sort(result.begin(), result.end(), [](const Game* left, const Game* right) {
return optional_descending(left->playtime_minutes, right->playtime_minutes);
});
}
- else if (state.library.sort == "install-size")
+ else if (sort == "install-size")
{
std::stable_sort(result.begin(), result.end(), [](const Game* left, const Game* right) {
return optional_descending(left->install_bytes, right->install_bytes);
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index 59318a6..67a1dfe 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -2800,6 +2800,9 @@ bool Simulation::installed_list_open() const {
}
void Simulation::rebuild_view() {
+ // The Library left for another tab: the order "More" showed ends with that visit.
+ if (state_.navigation.route != Route::Library && state_.navigation.route != Route::Details)
+ state_.library.view_sort.clear();
// An uninstall batch lives while its list is open; later stops are notices again.
if (!rebuilding_overlay_ && uninstall_batch_ && !installed_list_open()) uninstall_batch_.reset();
const bool has_overlay = state_.editor.active || !state_.navigation.modals.empty();
@@ -4950,8 +4953,9 @@ void Simulation::activate() {
state_.navigation.focus_key.rfind("shelf-", 0) == 0 && state_.navigation.focus_key.size() > 5 &&
state_.navigation.focus_key.compare(state_.navigation.focus_key.size() - 5, 5, "-more") == 0) {
// "More" at the end of Continue playing: every game in the Library, most recently played first.
+ // Only this visit: the sort the player chose comes back when the Library is opened again.
state_.library.scope = "all";
- state_.library.sort = "recent-played";
+ state_.library.view_sort = "recent-played";
state_.library.query.clear();
state_.navigation.library_rail_focused = false;
state_.navigation.route = Route::Library;
@@ -5706,13 +5710,13 @@ void Simulation::activate() {
state_.navigation.modals.clear();
pending_destructive_action_.clear();
} else if (action_name.rfind("sort-", 0) == 0) {
- state_.library.sort = action_name.substr(5); close_modal(); reconcile_library_selection(state_); save_profile();
+ state_.library.sort = action_name.substr(5); state_.library.view_sort.clear(); close_modal(); reconcile_library_selection(state_); save_profile();
} else if (action_name.rfind("filter-", 0) == 0) {
const auto filter = action_name.substr(7);
if (state_.library.filters.contains(filter)) state_.library.filters.erase(filter); else state_.library.filters.insert(filter);
close_modal(); reconcile_library_selection(state_); save_profile();
} else if (action_name == "filters-reset") {
- state_.library.filters.clear(); state_.library.sort = "name"; close_modal(); reconcile_library_selection(state_); save_profile();
+ state_.library.filters.clear(); state_.library.sort = "name"; state_.library.view_sort.clear(); close_modal(); reconcile_library_selection(state_); save_profile();
} else if (action_name == "game-settings") {
const auto id = state_.navigation.selected_game_id;
const auto setup = game_setups_.find(id);
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index 7e3ecc3..d8584c4 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -317,6 +317,9 @@ struct UserLibrary {
std::string query;
std::string scope = "all";
std::string sort = "name";
+ // The order "More" on Continue playing shows (most recently played first) while the Library,
+ // or a game opened from it, is on screen. Never saved: `sort` stays the player's own choice.
+ std::string view_sort;
std::set<std::string> filters;
};
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index b39e2af..ecd139c 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -889,6 +889,46 @@ void live_sort_sheet_refreshes_the_library() {
"the disabled row asks for nothing");
}
+// "More" on Continue playing shows the Library most recently played first, for that visit only: the
+// sort the player chose stays saved and comes back when the Library is opened again.
+void continue_playing_more_keeps_the_chosen_sort() {
+ auto model=make_live();
+ model.UpdateAccount({AuthState::SignedIn,"123","Synthetic",{},{},true});
+ std::vector<GameSummary> games;
+ for(playden::GameId id=1;id<=25;++id) {
+ auto summary=game(id,"Game "+std::to_string(100+id));
+ summary.last_played_unix_seconds=1'700'000'000ULL+id;
+ summary.playtime_minutes=id%2 ? 1000+id : id;
+ games.push_back(std::move(summary));
+ }
+ check(model.UpdateLibrary({std::move(games),false,{},false,false,{}}),"played library loaded");
+ check(model.action("r1") && model.action("triangle"),"live filter modal opens");
+ activate(model,"sort-playtime");
+ check(model.state().library.sort=="playtime" && model.visible_games().front()->id==25,"playtime sort chosen");
+ check(model.action("l1") && model.state().navigation.route==Route::Home,"back to Home");
+ for(int step=0;step<30 && model.state().navigation.focus_key!="shelf-continue-more";++step) model.action("right");
+ check(model.state().navigation.focus_key=="shelf-continue-more","More on Continue playing focused");
+ check(model.action("cross") && model.state().navigation.route==Route::Library,"More opens the Library");
+ const auto more=model.visible_games();
+ check(more.size()==25 && more.front()->id==25 && more[1]->id==24,"More lists the most recently played first");
+ check(model.state().library.sort=="playtime" && model.ExportOrganization().sort=="playtime",
+ "More does not replace the saved sort");
+ check(model.action("details:24") && model.action("circle") && model.state().navigation.route==Route::Library &&
+ model.visible_games()[1]->id==24,"a game opened from More returns to the same order");
+ check(model.action("l1") && model.action("r1") && model.state().navigation.route==Route::Library,"Library opened again");
+ const auto again=model.visible_games();
+ check(again.front()->id==25 && again[1]->id==23,"the chosen playtime sort is back");
+
+ // Choosing a sort in the More view keeps it.
+ check(model.action("l1"),"back to Home");
+ for(int step=0;step<30 && model.state().navigation.focus_key!="shelf-continue-more";++step) model.action("right");
+ check(model.action("cross") && model.action("triangle"),"sort sheet from the More view");
+ activate(model,"sort-name");
+ check(model.state().library.sort=="name" && model.visible_games().front()->id==1,"a chosen sort replaces the More order");
+ check(model.action("l1") && model.action("r1") && model.state().library.sort=="name" &&
+ model.visible_games().front()->id==1,"and stays chosen");
+}
+
void live_uninstall_removes_title_and_keeps_saves() {
using playden::homebrew::InstallRequestKind;
using playden::homebrew::LiveRuntimeGame;
@@ -2085,6 +2125,7 @@ int main() {
live_saves_upload_all();
live_filters_only_use_available_facts();
live_sort_sheet_refreshes_the_library();
+ continue_playing_more_keeps_the_chosen_sort();
live_empty_filter_keeps_the_signed_in_account();
projects_only_owned_facts_and_delivery_status();
loading_and_failure_preserve_last_good_snapshot();
diff --git a/tests/homebrew_persistence_integration_test.cpp b/tests/homebrew_persistence_integration_test.cpp
index bc7f2b3..1f9b117 100644
--- a/tests/homebrew_persistence_integration_test.cpp
+++ b/tests/homebrew_persistence_integration_test.cpp
@@ -28,6 +28,18 @@ struct Auth final : AuthBackend {
struct Library final : LibraryBackend {
LibraryResult Fetch(const StoredSession&,const std::atomic<bool>&) override {return {LibraryError::kNone,{{42,"Synthetic game",{},{},{}}},false};}
};
+// Enough played games for Continue playing to end with More.
+struct PlayedLibrary final : LibraryBackend {
+ LibraryResult Fetch(const StoredSession&,const std::atomic<bool>&) override {
+ LibraryResult result{LibraryError::kNone,{},false};
+ for(GameId id=1;id<=25;++id) {
+ GameSummary game{id,"Played "+std::to_string(100+id),{},{},{}};
+ game.last_played_unix_seconds=1700000000ULL+id;game.playtime_minutes=id%2 ? 1000+id : id;
+ result.games.push_back(game);
+ }
+ return result;
+ }
+};
struct Organization final : OrganizationRepository {
explicit Organization(Storage& storage):store(storage){}
OrganizationStore store;
@@ -112,6 +124,36 @@ void RestartAndDeletion(const std::filesystem::path& root) {
assert(preferences.Load().status==PreferencesLoadStatus::kLoaded);
}
}
+// The sort chosen in Sort and filters is the one the Library opens with after a restart, also when
+// "More" on Continue playing was used last.
+void SortSurvivesRestart(const std::filesystem::path& root) {
+ Storage storage(root.string());PreferencesStore preferences(storage);Organization organization(storage);LibraryCache cache(storage);
+ Sessions sessions;Auth auth;PlayedLibrary backend;
+ {
+ Simulation model({}, {},ModelMode::Live);LibraryService library(backend,sessions,&cache);
+ app::PersistenceService persistence(preferences,organization);Controller controller(model,auth,sessions,&library,&persistence);
+ Wait(controller,[&]{return model.state().games.size()==25 && !model.state().library_loading;});
+ assert(model.action("r1"));if(model.state().navigation.library_rail_focused)assert(model.action("right"));
+ assert(model.action("triangle"));Choose(model,"sort-playtime");
+ assert(model.state().library.sort=="playtime");
+ assert(model.action("l1") && model.state().navigation.route==Route::Home);
+ for(int step=0;step<30 && model.state().navigation.focus_key!="shelf-continue-more";++step) model.action("right");
+ assert(model.action("cross") && model.state().navigation.route==Route::Library);
+ assert(model.visible_games().front()->id==25 && model.visible_games()[1]->id==24);
+ Wait(controller,[&]{const auto saved=organization.Load(123);return saved.ok() && saved.value() && saved.value()->sort=="playtime";});
+ controller.Shutdown();
+ }
+ const auto saved=organization.Load(123);
+ assert(saved.ok() && saved.value() && saved.value()->sort=="playtime");
+ {
+ Simulation model({}, {},ModelMode::Live);LibraryService library(backend,sessions,&cache);
+ app::PersistenceService persistence(preferences,organization);Controller controller(model,auth,sessions,&library,&persistence);
+ Wait(controller,[&]{return model.state().games.size()==25 && !model.state().library_loading && model.state().library.sort=="playtime";});
+ assert(model.action("r1") && model.state().navigation.route==Route::Library);
+ const auto games=model.visible_games();
+ assert(games.front()->id==25 && games[1]->id==23);
+ }
+}
void EditWhileLoading(const std::filesystem::path& root) {
Storage storage(root.string());PreferencesStore preferences(storage);Organization organization(storage);LibraryCache cache(storage);
OrganizationSnapshot seed;seed.favorites.insert(77);seed.notes[77]="Keep unrelated note";
@@ -133,5 +175,5 @@ void EditWhileLoading(const std::filesystem::path& root) {
}
int main() {
const auto root=std::filesystem::temp_directory_path()/("playden-persistence-integration-"+std::to_string(getpid()));
- std::filesystem::create_directories(root);RestartAndDeletion(root);EditWhileLoading(root/"delayed");std::filesystem::remove_all(root);
+ std::filesystem::create_directories(root);RestartAndDeletion(root);EditWhileLoading(root/"delayed");SortSurvivesRestart(root/"sort");std::filesystem::remove_all(root);
}