Play your Steam library's Windows games on a jailbroken PS5.
C++
Add a Stay signed in toggle to Steam sign-in
Leonardo Lobatoc73e145a9143
diff --git a/cmake/HomebrewUI.cmake b/cmake/HomebrewUI.cmakeindex fcc85a5..38d94ba 100644--- a/cmake/HomebrewUI.cmake+++ b/cmake/HomebrewUI.cmake@@ -599,7 +599,7 @@ if(BUILD_TESTING)add_executable(homebrew_account_test"${CMAKE_SOURCE_DIR}/tests/homebrew_account_test.cpp")target_compile_features(homebrew_account_test PRIVATE cxx_std_20)- target_link_libraries(homebrew_account_test PRIVATE playden_homebrew_controller)+ target_link_libraries(homebrew_account_test PRIVATE playden_homebrew_controller playden_local_session_repository)add_test(NAME homebrew_account COMMAND homebrew_account_test)add_executable(library_controller_test "${CMAKE_SOURCE_DIR}/tests/library_controller_test.cpp")diff --git a/src/app/preferences.cpp b/src/app/preferences.cppindex 5281696..49cca18 100644--- a/src/app/preferences.cpp+++ b/src/app/preferences.cpp@@ -33,7 +33,8 @@ PreferencesLoadResult PreferencesStore::Load() const {const std::string serialized = ToString(read.value());// Version 1 holds only reduce_motion; version 2 adds title_store_suffix; version 3 cloud_saves_auto;- // version 4 steam_sign_in_password; version 5 downloads_slow_network.+ // version 4 steam_sign_in_password; version 5 downloads_slow_network; version 6 steam_stay_signed_in+ // (on in files older than that).for (const int motion : {0, 1}) {if (serialized == std::string("version=1\nreduce_motion=") + char('0' + motion) + "\n") {Preferences preferences;@@ -87,6 +88,25 @@ PreferencesLoadResult PreferencesStore::Load() const {preferences.downloads_slow_network = slow == 1;return PreferencesLoadResult{preferences, PreferencesLoadStatus::kLoaded, std::string()};}+ for (const int suffix : {0, 1})+ for (const int cloud : {0, 1})+ for (const int password : {0, 1})+ for (const int slow : {0, 1})+ for (const int stay : {0, 1})+ if (serialized == std::string("version=6\nreduce_motion=") + char('0' + motion) ++ "\ntitle_store_suffix=" + char('0' + suffix) + "\ncloud_saves_auto=" + char('0' + cloud) ++ "\nsteam_sign_in_password=" + char('0' + password) ++ "\ndownloads_slow_network=" + char('0' + slow) ++ "\nsteam_stay_signed_in=" + char('0' + stay) + "\n") {+ Preferences preferences;+ preferences.reduce_motion = motion == 1;+ preferences.title_store_suffix = suffix == 1;+ preferences.cloud_saves_auto = cloud == 1;+ preferences.steam_sign_in_password = password == 1;+ preferences.downloads_slow_network = slow == 1;+ preferences.steam_stay_signed_in = stay == 1;+ return PreferencesLoadResult{preferences, PreferencesLoadStatus::kLoaded, std::string()};+ }}return PreferencesLoadResult{Preferences{}, PreferencesLoadStatus::kDefaultCorrupt,@@ -96,11 +116,12 @@ PreferencesLoadResult PreferencesStore::Load() const {Result<void> PreferencesStore::Save(const Preferences& preferences) const {const auto ready=storage_.EnsureRootDirectory();if(!ready.ok()) return ready;- const std::string text = std::string("version=5\nreduce_motion=") + (preferences.reduce_motion ? "1" : "0") ++ const std::string text = std::string("version=6\nreduce_motion=") + (preferences.reduce_motion ? "1" : "0") +"\ntitle_store_suffix=" + (preferences.title_store_suffix ? "1" : "0") +"\ncloud_saves_auto=" + (preferences.cloud_saves_auto ? "1" : "0") +"\nsteam_sign_in_password=" + (preferences.steam_sign_in_password ? "1" : "0") +- "\ndownloads_slow_network=" + (preferences.downloads_slow_network ? "1" : "0") + "\n";+ "\ndownloads_slow_network=" + (preferences.downloads_slow_network ? "1" : "0") ++ "\nsteam_stay_signed_in=" + (preferences.steam_stay_signed_in ? "1" : "0") + "\n";return storage_.WriteAtomic(kPreferencesPath, Bytes(text.begin(), text.end()));}diff --git a/src/app/preferences.h b/src/app/preferences.hindex 1d3428b..18266a9 100644--- a/src/app/preferences.h+++ b/src/app/preferences.h@@ -19,6 +19,9 @@ struct Preferences {// Downloads for slow networks: 8 pieces at a time instead of 4. Far from a fast Steam server each piece waits// long for its answer, and more of them in flight make up for it (#29); on a fast connection 4 is quicker.bool downloads_slow_network = false;+ // "Stay signed in" on the sign-in screen. Off, Steam's sign-in token stays in memory only and is never+ // saved on the PS5, so every Playden start asks for a sign-in. On (the default) keeps it in session.v1.+ bool steam_stay_signed_in = true;};enum class PreferencesLoadStatus {diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex ef30d77..25357d2 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -105,6 +105,9 @@ void Controller::Shutdown() {for (const auto action : model_.TakeServiceActions()) {if (action.store == Store::kSteam && (action == ServiceAction::SignOut || action == ServiceAction::SwitchAccount) &&phase_!=Phase::ClearLibrary && phase_!=Phase::ClearOrganization && phase_!=Phase::SignOut) SignOut(false);+ // Turned off just before quitting: the saved token must still go.+ if (action.store == Store::kSteam && action == ServiceAction::StaySignedIn && stay_signed_in_)+ stay_signed_in_(model_.state().stay_signed_in);}begin_after_clear_=false;// Each step is logged before it starts and with its time after, so a hang shows where it stopped.@@ -318,6 +321,9 @@ void Controller::Tick() {break;case ServiceAction::SignOut: SignOut(false); break;case ServiceAction::SwitchAccount: SignOut(true); break;+ case ServiceAction::StaySignedIn:+ if (stay_signed_in_) stay_signed_in_(model_.state().stay_signed_in);+ break;case ServiceAction::RefreshLibrary:if (phase_ == Phase::Idle && !model_.state().account().id.empty()) {if(library_) {diff --git a/src/homebrew/controller.hpp b/src/homebrew/controller.hppindex e165712..b3c7a69 100644--- a/src/homebrew/controller.hpp+++ b/src/homebrew/controller.hpp@@ -53,6 +53,8 @@ class Controller {void SetSelfUpdate(update::UpdateService* self_update) { self_update_ = self_update; }// Receives one line per shutdown step with how long it took, so a quit that hangs names the step.void SetShutdownLog(std::function<void(const std::string&)> log) { shutdown_log_ = std::move(log); }+ // The player turned "Stay signed in" on or off: the host moves the Steam session to disk or memory.+ void SetStaySignedIn(std::function<void(bool)> apply) { stay_signed_in_ = std::move(apply); }// Counts changes to the account's Steam licenses (steam::CmLicenseChanges): the library refreshes// once they settle for `delay`, so a game added on another device shows up.void SetLicenseChanges(std::function<std::uint64_t()> changes,@@ -105,6 +107,7 @@ class Controller {void TickSelfUpdate();void TickLicenseChanges();std::function<void(const std::string&)> shutdown_log_;+ std::function<void(bool)> stay_signed_in_;std::function<std::uint64_t()> license_changes_;std::chrono::steady_clock::duration license_refresh_delay_{};std::optional<std::uint64_t> seen_license_changes_;diff --git a/src/homebrew/host.cpp b/src/homebrew/host.cppindex f18ab1c..5780139 100644--- a/src/homebrew/host.cpp+++ b/src/homebrew/host.cpp@@ -406,6 +406,7 @@ int main(int argc, char** argv) {std::unique_ptr<playden::Storage> auth_storage;std::unique_ptr<playden::steam::CmClient> auth_cm;std::unique_ptr<playden::steam::AuthClient> auth;+ std::unique_ptr<playden::SessionVault> session_vault; // declared first: every session repository uses itstd::unique_ptr<playden::LocalSessionRepository> sessions;std::unique_ptr<playden::steam::LibraryClient> owned_library;std::unique_ptr<playden::LocalSessionRepository> library_sessions;@@ -491,10 +492,17 @@ int main(int argc, char** argv) {std::snprintf(line, sizeof(line), "auth_failure method=%s http=%ld eresult=%d", method, http_status, eresult);playden::app::AppendLogLine(log_directory, "auth.log", line);});+ // "Stay signed in" is known before the controller restores the session.+ const bool stay_signed_in = playden::PreferencesStore(*auth_storage).Load().preferences.steam_stay_signed_in;+ session_vault = std::make_unique<playden::SessionVault>(stay_signed_in);sessions = std::make_unique<playden::LocalSessionRepository>(- options->data_directory.string());+ options->data_directory.string(), [log_directory](const std::string& diagnostic) {+ playden::app::AppendLogLine(log_directory, "storage.log", diagnostic);+ }, session_vault.get());+ // Off: a session.v1 left from before is deleted unread.+ if (!stay_signed_in) (void)sessions->Clear();owned_library = std::make_unique<playden::steam::LibraryClient>(PLAYDEN_HOMEBREW_CA_BUNDLE);- library_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string());+ library_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string(), playden::LocalSessionRepository::DiagnosticReport{}, session_vault.get());library_storage = std::make_unique<playden::Storage>(options->data_directory.string());cm_client = std::make_unique<playden::steam::CmClient>(PLAYDEN_HOMEBREW_CA_BUNDLE, *library_storage);library_backend = std::make_unique<playden::steam::EntitledLibraryBackend>(*owned_library, *cm_client);@@ -507,11 +515,11 @@ int main(int argc, char** argv) {details_cm = std::make_unique<playden::steam::CmClient>(PLAYDEN_HOMEBREW_CA_BUNDLE, *library_storage);details_source = std::make_unique<playden::steam::CmAppDetailsSource>(*details_cm);details_source->SetLicensedDepots(&licensed_depots);- details_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string());+ details_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string(), playden::LocalSessionRepository::DiagnosticReport{}, session_vault.get());app_details = std::make_unique<playden::steam::AppDetailsService>(*details_source, *details_sessions);install_cm = std::make_unique<playden::steam::CmClient>(PLAYDEN_HOMEBREW_CA_BUNDLE, *library_storage);install_cdn = std::make_unique<playden::steam::CdnClient>(PLAYDEN_HOMEBREW_CA_BUNDLE);- install_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string());+ install_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string(), playden::LocalSessionRepository::DiagnosticReport{}, session_vault.get());install_runner = std::make_unique<playden::steam::SteamInstallRunner>(*install_sessions, *install_cm, *install_cdn);install_runner->SetLog([log_directory](std::uint32_t app, const char* step, const char* category, const char* detail) {char line[640];@@ -547,7 +555,7 @@ int main(int argc, char** argv) {cloud_runner->SetLog([log_directory](std::uint32_t app, const char* event, const std::string& message) {playden::app::AppendLogLine(log_directory, "cloud.log", "app=" + std::to_string(app) + " event=" + event + " " + message);});- cloud_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string());+ cloud_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string(), playden::LocalSessionRepository::DiagnosticReport{}, session_vault.get());cloud = std::make_unique<playden::steam::CloudService>(*cloud_runner, *cloud_sessions);simulation.SetLogDirectory(options->data_directory / "logs");simulation.SetRecipeExportTarget(options->data_directory / "logs", "");@@ -586,6 +594,11 @@ int main(int argc, char** argv) {services = std::make_unique<playden::homebrew::Controller>(simulation, *stores, persistence.get(), installs.get(),cloud.get(), nullptr, auth_log);services->SetLocalLibrary(local);+ services->SetStaySignedIn([repository = sessions.get(), log_directory](bool stay) {+ const auto moved = repository->SetPersist(stay);+ playden::app::AppendLogLine(log_directory, "auth.log", std::string("stay signed in ") + (stay ? "on" : "off") ++ " moved=" + (moved.ok() ? "1" : "0"));+ });store_details = std::make_unique<playden::steam::StoreDetailsService>(playden::homebrew::StoreFetch(PLAYDEN_HOMEBREW_CA_BUNDLE));services->SetStoreDetails(store_details.get());}diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cppindex 63b713e..d2ce7ab 100644--- a/src/homebrew/ps5.cpp+++ b/src/homebrew/ps5.cpp@@ -304,11 +304,17 @@ int main() {playden::app::AppendLogLine(log_root, "auth.log", std::string("restored path=") + path + " before " + before +" after " + after);});+ // "Stay signed in" is known before the controller restores the session. Off, the session lives+ // only in this vault, which all five repositories below share.+ const bool stay_signed_in = playden::PreferencesStore(auth_storage).Load().preferences.steam_stay_signed_in;+ playden::SessionVault session_vault(stay_signed_in);playden::LocalSessionRepository sessions(user_root, [](const std::string& diagnostic) {playden::app::AppendLogLine(log_root, "storage.log", diagnostic);- });+ }, &session_vault);+ // Off: a session.v1 left from before is deleted unread.+ if (!stay_signed_in) (void)sessions.Clear();playden::steam::LibraryClient owned_library(paths.trust_store);- playden::LocalSessionRepository library_sessions(user_root);+ playden::LocalSessionRepository library_sessions(user_root, {}, &session_vault);playden::Storage library_storage(user_root);playden::steam::CmClient cm_client(paths.trust_store, library_storage);cm_client.SetOwner("library");@@ -326,13 +332,13 @@ int main() {details_cm.SetSharedSession(steam_cm);playden::steam::CmAppDetailsSource details_source(details_cm);details_source.SetLicensedDepots(&licensed_depots);- playden::LocalSessionRepository details_sessions(user_root);+ playden::LocalSessionRepository details_sessions(user_root, {}, &session_vault);playden::steam::AppDetailsService app_details(details_source, details_sessions);playden::steam::CmClient install_cm(paths.trust_store, library_storage);install_cm.SetOwner("install");install_cm.SetSharedSession(steam_cm);playden::steam::CdnClient install_cdn(paths.trust_store);- playden::LocalSessionRepository install_sessions(user_root);+ playden::LocalSessionRepository install_sessions(user_root, {}, &session_vault);playden::steam::SteamInstallRunner install_runner(install_sessions, install_cm, install_cdn);install_runner.SetTuning([root = paths.title_root] {// A developer's tuning file wins over the setting.@@ -358,7 +364,7 @@ int main() {cloud_runner.SetLog([](std::uint32_t app, const char* event, const std::string& message) {playden::app::AppendLogLine(log_root, "cloud.log", "app=" + std::to_string(app) + " event=" + event + " " + message);});- playden::LocalSessionRepository cloud_sessions(user_root);+ playden::LocalSessionRepository cloud_sessions(user_root, {}, &session_vault);playden::steam::CloudService cloud(cloud_runner, cloud_sessions);simulation.SetLogDirectory(log_root);// Playden's own update: it looks for a newer release on GitHub at startup, stages it on@@ -655,6 +661,11 @@ int main() {// A game bought or added to the library elsewhere: Steam pushes the new license list.services.SetLicenseChanges([steam_cm] { return playden::steam::CmLicenseChanges(*steam_cm); });services.SetShutdownLog([](const std::string& line) { playden::app::AppendLogLine(log_root, "launch.log", line); });+ services.SetStaySignedIn([&sessions](bool stay) {+ const auto moved = sessions.SetPersist(stay);+ playden::app::AppendLogLine(log_root, "auth.log", std::string("stay signed in ") + (stay ? "on" : "off") ++ " moved=" + (moved.ok() ? "1" : "0"));+ });#endif#if PLAYDEN_UI_SIMULATIONplayden::homebrew::Render renderer(paths.assets_root);diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex 440b8ad..986698f 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -2416,7 +2416,7 @@ playden::OrganizationSnapshot Simulation::ExportOrganization() const {playden::Preferences Simulation::ExportPreferences() const {return {state_.reduced_motion, state_.title_store_suffix, state_.cloud_saves_auto, state_.sign_in_password,- state_.downloads_slow_network};+ state_.downloads_slow_network, state_.stay_signed_in};}void Simulation::apply_organization_snapshot(const playden::OrganizationSnapshot& snapshot) {@@ -2642,6 +2642,7 @@ bool Simulation::ApplyPreferences(PersistenceLoadToken token,state_.cloud_saves_auto = loaded.preferences.cloud_saves_auto;state_.sign_in_password = loaded.preferences.steam_sign_in_password;state_.downloads_slow_network = loaded.preferences.downloads_slow_network;+ state_.stay_signed_in = loaded.preferences.steam_stay_signed_in;captured_preferences_ = loaded.preferences;preferences_saved_revision_ = preferences_revision_;}@@ -2719,7 +2720,8 @@ bool Simulation::record_live_persistence() {after_preferences.title_store_suffix != captured_preferences_.title_store_suffix ||after_preferences.cloud_saves_auto != captured_preferences_.cloud_saves_auto ||after_preferences.steam_sign_in_password != captured_preferences_.steam_sign_in_password ||- after_preferences.downloads_slow_network != captured_preferences_.downloads_slow_network);+ after_preferences.downloads_slow_network != captured_preferences_.downloads_slow_network ||+ after_preferences.steam_stay_signed_in != captured_preferences_.steam_stay_signed_in);if (organization_changed && !snapshot_within_model_bounds(after_organization)) {apply_organization_snapshot(captured_organization_);@@ -2742,6 +2744,7 @@ bool Simulation::record_live_persistence() {state_.cloud_saves_auto = captured_preferences_.cloud_saves_auto;state_.sign_in_password = captured_preferences_.steam_sign_in_password;state_.downloads_slow_network = captured_preferences_.downloads_slow_network;+ state_.stay_signed_in = captured_preferences_.steam_stay_signed_in;organization_journal_full_ = true;force_organization_reset_ = false;force_organization_selection_ = false;@@ -4305,6 +4308,7 @@ void Simulation::rebuild_view() {row("signin-submit", RowKind::Action, "Sign in", "signin-submit").enabled =!form.account_name.empty() && !form.password.empty();row("signin-qr-mode", RowKind::Action, "Use QR code instead", "signin-qr-mode");+ row("signin-stay", RowKind::Toggle, "Stay signed in", "signin-stay").selected = state_.stay_signed_in;} else if (form.step == SignInStep::Submitting) {view_.subtitle = "Signing in to Steam…";row("signin-cancel", RowKind::Action, "Cancel", "signin-cancel");@@ -4356,8 +4360,10 @@ void Simulation::rebuild_view() {else if (state_.account().authentication == AuthState::Expired) row("qr-refresh", RowKind::Action, "Refresh code", "qr-refresh");else if (state_.account().authentication == AuthState::Failed) row("qr-retry", RowKind::Action, "Retry", "qr-retry");else row("qr-cancel", RowKind::Action, "Cancel", "qr-cancel");- if (state_.account().authentication != AuthState::Syncing)+ if (state_.account().authentication != AuthState::Syncing) {row("signin-password-mode", RowKind::Action, "Sign in with account name and password", "signin-password-mode");+ row("signin-stay", RowKind::Toggle, "Stay signed in", "signin-stay").selected = state_.stay_signed_in;+ }if (!live() && state_.account().authentication != AuthState::Syncing) row("qr-fixture-controls", RowKind::Action, "QR fixture controls", "qr-fixture-controls");} else if (state_.navigation.route == Route::Home) {view_.title = "Home";@@ -5299,6 +5305,11 @@ bool Simulation::sign_in_action(const std::string& action_name) {state_.navigation.focus_key = password ? (name.empty() ? "signin-account" : "signin-password") : "qr-cancel";if (live()) queue_service_action(password ? ServiceAction::UsePassword : ServiceAction::UseQr);else if (!password) scenario("qr-waiting");+ } else if (action_name == "signin-stay") {+ // In force at once: a sign-in that completes from now on follows the new choice.+ state_.stay_signed_in = !state_.stay_signed_in;+ save_profile();+ if (live()) queue_service_action(ServiceAction::StaySignedIn);} else if (action_name == "signin-account") {start_editor("Account name", form.account_name);} else if (action_name == "signin-password") {diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex 6fd4545..519b643 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -26,7 +26,7 @@ enum class ModelMode { Simulation, Live };// UsePassword/UseQr switch the sign-in screen's method; BeginPassword and SubmitCode carry the form's// secrets, which the controller takes with TakeSignInCredentials and TakeGuardCode.enum class ServiceAction { BeginQr, CancelQr, SignOut, SwitchAccount, RefreshLibrary, Reauthenticate,- UsePassword, UseQr, BeginPassword, SubmitCode };+ UsePassword, UseQr, BeginPassword, SubmitCode, StaySignedIn };// A service action for one store's account. The sign-in actions (QR, password, Steam Guard code) are Steam's.struct ServiceRequest {ServiceAction action = ServiceAction::BeginQr;@@ -566,6 +566,7 @@ struct State {// The Steam account's sign-in screen and its preference: the last sign-in used the account name and password.SignInForm sign_in;bool sign_in_password = false;+ bool stay_signed_in = true; // preference: keep Steam's sign-in token on the PS5 (else memory only)std::vector<Notice> notices;// Per-game settings: preset and player overrides (see runtime/game_settings.h).std::map<GameId, playden::runtime::GameSettingsRecord> game_settings;diff --git a/src/homebrew/view.cpp b/src/homebrew/view.cppindex 088cac9..de34919 100644--- a/src/homebrew/view.cpp+++ b/src/homebrew/view.cpp@@ -1211,8 +1211,11 @@ class Render::Implconst gfx::Rect panel{1036.0F, 224.0F, 640.0F, 430.0F};scene_.rounded_rect(panel, 14.0F, kPanel);const char *title = "Account name and password";- const char *detail = "Playden sends your password to Steam, encrypted, and keeps only Steam's sign-in token. "- "It never saves your password.";+ const char *detail = state.stay_signed_in+ ? "Playden sends your password to Steam, encrypted, and never saves it. It keeps Steam's sign-in token "+ "on this PS5 so you stay signed in."+ : "Playden sends your password to Steam, encrypted, and never saves it. It keeps Steam's sign-in token "+ "only until you close Playden. You will sign in again next time.";if (form.step == SignInStep::Submitting){title = "Signing in";@@ -1245,7 +1248,11 @@ class Render::Implconst bool storage_full = state.account().authentication == AuthState::Failed && state.account().storage_full;section_label(storage_full ? "Console storage" : "Connect Steam", 96.0F, 78.0F);draw_title(view, 96.0F, 272.0F, 720.0F);- draw_actions(view, 96.0F, 594.0F, 540.0F);+ // Four buttons fit above the footer; a fifth (the password form) lifts the column by one.+ const auto buttons = std::count_if(view.rows.begin(), view.rows.end(), [](const ViewRow &row) {+ return row.kind == RowKind::Action || row.kind == RowKind::Toggle;+ });+ draw_actions(view, 96.0F, buttons > 4 ? 514.0F : 594.0F, 540.0F);constexpr float qr_x = 1116.0F;constexpr float qr_y = 224.0F;constexpr int qr_side = 430;diff --git a/tests/homebrew_account_test.cpp b/tests/homebrew_account_test.cppindex f22e3f7..7158530 100644--- a/tests/homebrew_account_test.cpp+++ b/tests/homebrew_account_test.cpp@@ -1,4 +1,5 @@#include "homebrew/controller.hpp"+#include "steam/local_session_repository.h"#include <algorithm>#include <cassert>#include <chrono>@@ -722,4 +723,70 @@ void TitleNamesCarryTheirStore() {assert(TitleStoreSuffix(Store::kGog)==" (GOG)" && TitleStoreSuffix(Store::kEpic)==" (Epic)");assert(TitleStoreSuffix(Store::kLocal).empty());}-int main() { TitleNamesCarryTheirStore(); NoSteamSessionWithOtherGamesOpensHome(); FailedRestoreWithOtherGamesOpensHome(); OtherRestoreFailuresWithOtherGamesOpenHome(); SteamSignOutKeepsOtherGames(); PasswordSignInWithGuardCode(); PasswordFailuresAndCancel(); SlowLicenseCheckShowsAfterAFewSeconds(); CanceledStorageRetryKeepsSavedSessionIntent(); RevokedSessionCleanupRetriesAfterStorageRecovery(); StorageFailureKeepsVisibleAccount(); StorageFailureRetriesSavedSession(); ChallengeAndCancel(); AuthenticationRestoreAndSignOut(); FailedClearDoesNotSwitch(); SignInAgainKeepsTheAccount(); ExitHonorsClearWithoutStartingNewQr(); StorageFailureAndRevocation(); ConnectedLibraryAndOfflineRestart(); LicenseChangesRefreshTheLibrary(); OfflineRefreshFromTheLibraryReconnects(); ShutdownClearsLibraryBeforeSession(); RepeatedClearPreservesFirstIntent(); }+// "Stay signed in" off on the sign-in screen: the token stays in memory, session.v1 never appears,+// and the next start asks for a sign-in again.+void StaySignedInOffKeepsTheTokenInMemory() {+ const auto root=std::filesystem::temp_directory_path()/("playden-stay-signed-in-"+std::to_string(getpid()));+ std::filesystem::remove_all(root); std::filesystem::create_directories(root);+ const auto file=root/"session.v1";+ {+ SessionVault vault;+ LocalSessionRepository repo(root.string(),{},&vault);+ LocalSessionRepository library(root.string(),{},&vault);+ Simulation model({}, {},ModelMode::Live); Backend backend;+ Controller controller(model,backend,repo);+ controller.SetStaySignedIn([&](bool stay) { assert(repo.SetPersist(stay).ok()); });+ Wait(controller,[&]{return model.state().account().authentication==AuthState::SignedOut;});+ Connect(model); controller.Tick();+ const auto stay=[&]{+ const auto& rows=model.view().rows;+ return std::find_if(rows.begin(),rows.end(),[](const ViewRow& row){return row.key=="signin-stay";});+ };+ assert(stay()!=model.view().rows.end() && stay()->kind==RowKind::Toggle && stay()->selected);+ Choose(model,"signin-stay");+ assert(!model.state().stay_signed_in && !model.ExportPreferences().steam_stay_signed_in && !stay()->selected);+ controller.Tick();+ assert(!vault.persist());+ // The password form offers the same toggle.+ Choose(model,"signin-password-mode"); controller.Tick();+ assert(stay()!=model.view().rows.end() && !stay()->selected);+ Choose(model,"signin-qr-mode"); backend.approve=true;+ Wait(controller,[&]{return model.state().account().authentication==AuthState::SignedIn;});+ assert(!std::filesystem::exists(file));+ const auto shared=library.Load(); assert(shared.ok() && shared.value() && shared.value()->steam_id==12345);+ // Sign-out drops it from memory too.+ SignOut(model);+ Wait(controller,[&]{return model.state().account().authentication==AuthState::SignedOut;});+ assert(library.Load().ok() && !library.Load().value() && !std::filesystem::exists(file));+ // Signed in again, then Playden closes.+ Connect(model); backend.approve=true;+ Wait(controller,[&]{return model.state().account().authentication==AuthState::SignedIn;});+ controller.Shutdown();+ }+ {+ // The next start: nothing on disk, so the sign-in screen comes back.+ SessionVault vault(false);+ LocalSessionRepository repo(root.string(),{},&vault);+ Simulation model({}, {},ModelMode::Live); Backend backend;+ Controller controller(model,backend,repo);+ Wait(controller,[&]{return model.state().account().authentication==AuthState::SignedOut;});+ assert(backend.restores==0 && !std::filesystem::exists(file));+ controller.Shutdown();+ }+ {+ // Turned off just before quitting, while signed in from session.v1: the file still goes.+ { LocalSessionRepository writer(root.string()); assert(writer.Save(Session()).ok()); }+ SessionVault vault;+ LocalSessionRepository repo(root.string(),{},&vault);+ Simulation model({}, {},ModelMode::Live); Backend backend;+ Controller controller(model,backend,repo);+ controller.SetStaySignedIn([&](bool stay) { assert(repo.SetPersist(stay).ok()); });+ Wait(controller,[&]{return model.state().account().authentication==AuthState::SignedIn;});+ OpenSettings(model); Choose(model,"account"); Choose(model,"account-reauth");+ Choose(model,"signin-stay");+ controller.Shutdown();+ assert(!vault.persist() && !std::filesystem::exists(file));+ }+ std::filesystem::remove_all(root);+}+int main() { StaySignedInOffKeepsTheTokenInMemory(); TitleNamesCarryTheirStore(); NoSteamSessionWithOtherGamesOpensHome(); FailedRestoreWithOtherGamesOpensHome(); OtherRestoreFailuresWithOtherGamesOpenHome(); SteamSignOutKeepsOtherGames(); PasswordSignInWithGuardCode(); PasswordFailuresAndCancel(); SlowLicenseCheckShowsAfterAFewSeconds(); CanceledStorageRetryKeepsSavedSessionIntent(); RevokedSessionCleanupRetriesAfterStorageRecovery(); StorageFailureKeepsVisibleAccount(); StorageFailureRetriesSavedSession(); ChallengeAndCancel(); AuthenticationRestoreAndSignOut(); FailedClearDoesNotSwitch(); SignInAgainKeepsTheAccount(); ExitHonorsClearWithoutStartingNewQr(); StorageFailureAndRevocation(); ConnectedLibraryAndOfflineRestart(); LicenseChangesRefreshTheLibrary(); OfflineRefreshFromTheLibraryReconnects(); ShutdownClearsLibraryBeforeSession(); RepeatedClearPreservesFirstIntent(); }diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cppindex 46136a2..2335b66 100644--- a/tests/homebrew_library_model_test.cpp+++ b/tests/homebrew_library_model_test.cpp@@ -1505,6 +1505,17 @@ void live_details_focus_moves_to_play_once_enabled() {"notes are skipped");}+// Stay signed in: on by default; a saved Off comes back with the preferences.+void live_stay_signed_in_preference_loads() {+ auto model = make_live();+ check(model.state().stay_signed_in && model.ExportPreferences().steam_stay_signed_in, "stay signed in by default");+ playden::PreferencesLoadResult stay_off;+ stay_off.preferences.steam_stay_signed_in = false;+ check(model.ApplyPreferences(model.BeginPreferencesLoad(), stay_off) && !model.state().stay_signed_in &&+ !model.ExportPreferences().steam_stay_signed_in,+ "a saved stay signed in off loads");+}+// Settings › Sync Cloud saves automatically, on (it starts off).void sync_automatically(Simulation& model) {playden::PreferencesLoadResult loaded;@@ -2833,6 +2844,7 @@ int main() {live_import_choice_and_details();store_art_follows_the_store();non_canonical_game_keys_select_nothing();+ live_stay_signed_in_preference_loads();live_launch_failure_remains_visible_without_a_details_status_line();live_download_reorder_reaches_service();live_play_does_the_next_useful_thing();diff --git a/tests/preferences_test.cpp b/tests/preferences_test.cppindex 89eea45..6a3060c 100644--- a/tests/preferences_test.cpp+++ b/tests/preferences_test.cpp@@ -186,9 +186,9 @@ void SignInMethodPersistsAndVersionThreeOpensQr() {Check(store.Save(preferences).ok(), "sign-in method preference saves");const auto saved = storage.Read("preferences.conf");Check(saved.ok() && std::string(saved.value().begin(), saved.value().end()) ==- "version=5\nreduce_motion=0\ntitle_store_suffix=0\ncloud_saves_auto=1\nsteam_sign_in_password=1\n"- "downloads_slow_network=0\n",- "version 5 format");+ "version=6\nreduce_motion=0\ntitle_store_suffix=0\ncloud_saves_auto=1\nsteam_sign_in_password=1\n"+ "downloads_slow_network=0\nsteam_stay_signed_in=1\n",+ "version 6 format");const auto loaded = store.Load();Check(loaded.status == playden::PreferencesLoadStatus::kLoaded && loaded.preferences.steam_sign_in_password &&loaded.preferences.cloud_saves_auto,@@ -217,6 +217,34 @@ void SignInMethodPersistsAndVersionThreeOpensQr() {Check(store.Load().status == playden::PreferencesLoadStatus::kDefaultCorrupt, "bad sign-in value is corrupt");}+void StaySignedInDefaultsOnAndPersistsOff() {+ TemporaryDirectory directory;+ playden::Storage storage(directory.path());+ playden::PreferencesStore store(storage);+ Check(store.Load().preferences.steam_stay_signed_in, "a fresh install stays signed in");+ const std::string version_five =+ "version=5\nreduce_motion=0\ntitle_store_suffix=0\ncloud_saves_auto=0\nsteam_sign_in_password=1\n"+ "downloads_slow_network=1\n";+ Check(storage.WriteAtomic("preferences.conf", playden::Bytes(version_five.begin(), version_five.end())).ok(),+ "version 5 fixture is written");+ const auto five = store.Load();+ Check(five.status == playden::PreferencesLoadStatus::kLoaded && five.preferences.steam_sign_in_password &&+ five.preferences.downloads_slow_network && five.preferences.steam_stay_signed_in,+ "version 5 preferences load and stay signed in");+ playden::Preferences preferences;+ preferences.steam_stay_signed_in = false;+ Check(store.Save(preferences).ok(), "stay signed in off saves");+ const auto off = store.Load();+ Check(off.status == playden::PreferencesLoadStatus::kLoaded && !off.preferences.steam_stay_signed_in,+ "stay signed in off survives restart");+ const std::string bad = "version=6\nreduce_motion=0\ntitle_store_suffix=0\ncloud_saves_auto=0\nsteam_sign_in_password=0\n"+ "downloads_slow_network=0\nsteam_stay_signed_in=2\n";+ Check(storage.WriteAtomic("preferences.conf", playden::Bytes(bad.begin(), bad.end())).ok(), "bad fixture is written");+ const auto corrupt = store.Load();+ Check(corrupt.status == playden::PreferencesLoadStatus::kDefaultCorrupt && corrupt.preferences.steam_stay_signed_in,+ "a bad stay signed in value is corrupt and restores the default");+}+void CorruptPreferencesRestoreDefaultsWithVisibleDiagnostic() {TemporaryDirectory directory;playden::Storage storage(directory.path());@@ -261,6 +289,7 @@ int main() {CorruptPreferencesRestoreDefaultsWithVisibleDiagnostic();TitleStoreSuffixPersistsAndVersionOneStillLoads();SignInMethodPersistsAndVersionThreeOpensQr();+ StaySignedInDefaultsOnAndPersistsOff();if (failures != 0) {std::fprintf(stderr, "%d preference test assertion(s) failed\n", failures);