mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 23:25:41 +00:00
Merge pull request #3076 from CookiePLMonster/discord-rpc
DiscordRPC: Show session time in Discord Rich Presence
This commit is contained in:
commit
00d6faac83
|
@ -795,7 +795,7 @@ void Achievements::UpdateRichPresence(std::unique_lock<std::recursive_mutex>& lo
|
||||||
|
|
||||||
#ifdef ENABLE_DISCORD_PRESENCE
|
#ifdef ENABLE_DISCORD_PRESENCE
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
System::UpdateDiscordPresence();
|
System::UpdateDiscordPresence(false);
|
||||||
lock.lock();
|
lock.lock();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,6 +234,7 @@ static u64 s_session_start_time = 0;
|
||||||
|
|
||||||
#ifdef ENABLE_DISCORD_PRESENCE
|
#ifdef ENABLE_DISCORD_PRESENCE
|
||||||
static bool s_discord_presence_active = false;
|
static bool s_discord_presence_active = false;
|
||||||
|
static time_t s_discord_presence_time_epoch;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static TinyString GetTimestampStringForFileName()
|
static TinyString GetTimestampStringForFileName()
|
||||||
|
@ -1691,7 +1692,7 @@ void System::ClearRunningGame()
|
||||||
Achievements::GameChanged(s_running_game_path, nullptr);
|
Achievements::GameChanged(s_running_game_path, nullptr);
|
||||||
|
|
||||||
#ifdef ENABLE_DISCORD_PRESENCE
|
#ifdef ENABLE_DISCORD_PRESENCE
|
||||||
UpdateDiscordPresence();
|
UpdateDiscordPresence(true);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3372,7 +3373,7 @@ void System::UpdateRunningGame(const char* path, CDImage* image, bool booting)
|
||||||
SaveStateSelectorUI::ClearList();
|
SaveStateSelectorUI::ClearList();
|
||||||
|
|
||||||
#ifdef ENABLE_DISCORD_PRESENCE
|
#ifdef ENABLE_DISCORD_PRESENCE
|
||||||
UpdateDiscordPresence();
|
UpdateDiscordPresence(booting);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Host::OnGameChanged(s_running_game_path, s_running_game_serial, s_running_game_title);
|
Host::OnGameChanged(s_running_game_path, s_running_game_serial, s_running_game_title);
|
||||||
|
@ -4137,9 +4138,8 @@ void System::ShutdownSystem(bool save_resume_state)
|
||||||
if (save_resume_state)
|
if (save_resume_state)
|
||||||
SaveResumeState();
|
SaveResumeState();
|
||||||
|
|
||||||
if (s_system_executing)
|
s_state = State::Stopping;
|
||||||
s_state = State::Stopping;
|
if (!s_system_executing)
|
||||||
else
|
|
||||||
DestroySystem();
|
DestroySystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4834,7 +4834,7 @@ void System::InitializeDiscordPresence()
|
||||||
Discord_Initialize("705325712680288296", &handlers, 0, nullptr);
|
Discord_Initialize("705325712680288296", &handlers, 0, nullptr);
|
||||||
s_discord_presence_active = true;
|
s_discord_presence_active = true;
|
||||||
|
|
||||||
UpdateDiscordPresence();
|
UpdateDiscordPresence(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::ShutdownDiscordPresence()
|
void System::ShutdownDiscordPresence()
|
||||||
|
@ -4847,16 +4847,19 @@ void System::ShutdownDiscordPresence()
|
||||||
s_discord_presence_active = false;
|
s_discord_presence_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::UpdateDiscordPresence()
|
void System::UpdateDiscordPresence(bool update_session_time)
|
||||||
{
|
{
|
||||||
if (!s_discord_presence_active)
|
if (!s_discord_presence_active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (update_session_time)
|
||||||
|
s_discord_presence_time_epoch = std::time(nullptr);
|
||||||
|
|
||||||
// https://discord.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields
|
// https://discord.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields
|
||||||
DiscordRichPresence rp = {};
|
DiscordRichPresence rp = {};
|
||||||
rp.largeImageKey = "duckstation_logo";
|
rp.largeImageKey = "duckstation_logo";
|
||||||
rp.largeImageText = "DuckStation PS1/PSX Emulator";
|
rp.largeImageText = "DuckStation PS1/PSX Emulator";
|
||||||
rp.startTimestamp = std::time(nullptr);
|
rp.startTimestamp = s_discord_presence_time_epoch;
|
||||||
rp.details = "No Game Running";
|
rp.details = "No Game Running";
|
||||||
if (IsValidOrInitializing())
|
if (IsValidOrInitializing())
|
||||||
{
|
{
|
||||||
|
|
|
@ -480,7 +480,7 @@ void SetRunaheadReplayFlag();
|
||||||
|
|
||||||
#ifdef ENABLE_DISCORD_PRESENCE
|
#ifdef ENABLE_DISCORD_PRESENCE
|
||||||
/// Called when rich presence changes.
|
/// Called when rich presence changes.
|
||||||
void UpdateDiscordPresence();
|
void UpdateDiscordPresence(bool update_session_time);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
Loading…
Reference in a new issue