Skip to content

Commit

Permalink
fix: Show the Steam UI after all plugins are finished loading instead…
Browse files Browse the repository at this point in the history
… of when the SharedJSContext connects
  • Loading branch information
shdwmtr committed Mar 8, 2025
1 parent 44f8b58 commit b5730a3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
35 changes: 35 additions & 0 deletions src/core/co_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,40 @@ const std::string ConstructOnLoadModule(uint16_t ftpPort, uint16_t ipcPort)
return GetBootstrapModule(scriptImportTable, ipcPort);
}

/**
* Restores the original `SharedJSContext` by renaming the backup file to the original file.
* It reverses the patches done in the preloader module
*
* @note this function is only applicable to Windows
*/
const void UnPatchSharedJSContext()
{
#ifdef _WIN32
Logger.Log("Restoring SharedJSContext...");

const auto SteamUIModulePath = SystemIO::GetSteamPath() / "steamui" / "index.html";
const auto SteamUIModulePathBackup = SystemIO::GetSteamPath() / "steamui" / "orig.html";

try
{
if (std::filesystem::exists(SteamUIModulePathBackup) && std::filesystem::is_regular_file(SteamUIModulePathBackup))
{
std::filesystem::remove(SteamUIModulePath);
}

std::filesystem::rename(SteamUIModulePathBackup, SteamUIModulePath);
}
catch (const std::exception& e)
{
Logger.Warn("Failed to restore SharedJSContext: {}", e.what());
}

Logger.Log("Restored SharedJSContext...");
#endif
Sockets::PostShared({ { "id", 9773 }, { "method", "Page.reload" } });
}


/**
* Notifies the frontend of the backend load and handles script injection and state updates.
*
Expand All @@ -418,6 +452,7 @@ const std::string ConstructOnLoadModule(uint16_t ftpPort, uint16_t ipcPort)
*/
void OnBackendLoad(uint16_t ftpPort, uint16_t ipcPort)
{
UnPatchSharedJSContext(); // Restore the original SharedJSContext
Logger.Log("Notifying frontend of backend load...");

static uint16_t m_ftpPort = ftpPort;
Expand Down
29 changes: 0 additions & 29 deletions src/core/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ class CEFBrowser
{
sharedJsContextSessionId = json["params"]["sessionId"];
Sockets::PostShared({ {"id", 9494 }, {"method", "Log.enable"}, {"sessionId", sharedJsContextSessionId} });

this->UnPatchSharedJSContext();
}
else if (json.value("id", -1) == 9773)
{
Expand All @@ -157,33 +155,6 @@ class CEFBrowser
Sockets::PostGlobal({ { "id", 0 }, { "method", "Target.getTargets" } });
}

const void UnPatchSharedJSContext()
{
#ifdef _WIN32
Logger.Log("Restoring SharedJSContext...");

const auto SteamUIModulePath = SystemIO::GetSteamPath() / "steamui" / "index.html";
const auto SteamUIModulePathBackup = SystemIO::GetSteamPath() / "steamui" / "orig.html";

try
{
if (std::filesystem::exists(SteamUIModulePathBackup) && std::filesystem::is_regular_file(SteamUIModulePathBackup))
{
std::filesystem::remove(SteamUIModulePath);
}

std::filesystem::rename(SteamUIModulePathBackup, SteamUIModulePath);
}
catch (const std::exception& e)
{
Logger.Warn("Failed to restore SharedJSContext: {}", e.what());
}

Logger.Log("Restored SharedJSContext...");
#endif
Sockets::PostShared({ { "id", 9773 }, { "method", "Page.reload" } });
}

const void onSharedJsConnect()
{
std::thread([this]() {
Expand Down

0 comments on commit b5730a3

Please sign in to comment.