Skip to content

Commit

Permalink
System: Fix Discord Rich Presence
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Oct 29, 2023
1 parent 6ca098d commit 538266a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ void System::Internal::ProcessStartup()
#endif
if (g_settings.achievements_enabled)
Achievements::Initialize();

if (g_settings.enable_discord_presence)
InitializeDiscordPresence();
}

void System::Internal::ProcessShutdown()
Expand Down Expand Up @@ -322,6 +325,11 @@ bool System::IsValid()
return s_state == State::Running || s_state == State::Paused;
}

bool System::IsValidOrInitializing()
{
return s_state == State::Starting || s_state == State::Running || s_state == State::Paused;
}

bool System::IsExecuting()
{
DebugAssert(s_state != State::Shutdown);
Expand Down Expand Up @@ -4722,7 +4730,20 @@ void System::UpdateDiscordPresence()
rp.largeImageKey = "duckstation_logo";
rp.largeImageText = "DuckStation PS1/PSX Emulator";
rp.startTimestamp = std::time(nullptr);
rp.details = System::IsValid() ? System::GetGameTitle().c_str() : "No Game Running";
rp.details = "No Game Running";
if (IsValidOrInitializing())
{
// Use disc set name if it's not a custom title.
if (s_running_game_entry && !s_running_game_entry->disc_set_name.empty() &&
s_running_game_title == s_running_game_entry->title)
{
rp.details = s_running_game_entry->disc_set_name.c_str();
}
else
{
rp.details = s_running_game_title.empty() ? "Unknown Game" : s_running_game_title.c_str();
}
}

std::string state_string;
if (Achievements::HasRichPresence())
Expand Down
1 change: 1 addition & 0 deletions src/core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ bool IsExecutionInterrupted();
bool IsPaused();
bool IsShutdown();
bool IsValid();
bool IsValidOrInitializing();
bool IsExecuting();

bool IsStartupCancelled();
Expand Down

0 comments on commit 538266a

Please sign in to comment.