From 8417c78b7a0015ae8252fe0841c9e98e38f5745c Mon Sep 17 00:00:00 2001 From: David Korth Date: Wed, 13 Feb 2019 21:31:31 -0500 Subject: [PATCH] Update Discord rich presence when the title changes This allows us to update the rich presence description if a channel is launched from the Wii Menu. It also handles other PPC title launches, e.g. Smash Bros. Masterpieces. Host.h: Added Host_TitleChanged(). DolphinNoGUI/MainNoGUI.cpp: Implemented Host_TitleChanged(). DolphinQt/Host.cpp: Implemented Host_TitleChanged(). Android/jni/MainAndroid.cpp: Stubbed Host_TitleChanged(). DSPTool/StubHost.cpp: Stubbed Host_TitleChanged(). UnitTests/StubHost.cpp: Stubbed Host_TitleChanged(). --- Source/Android/jni/MainAndroid.cpp | 4 ++++ Source/Core/Core/ConfigManager.cpp | 1 + Source/Core/Core/Host.h | 1 + Source/Core/DolphinNoGUI/MainNoGUI.cpp | 7 +++++++ Source/Core/DolphinQt/Host.cpp | 12 ++++++++++++ Source/DSPTool/StubHost.cpp | 3 +++ Source/UnitTests/StubHost.cpp | 3 +++ 7 files changed, 31 insertions(+) diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index ebb062ee8ea7..c297d5e54151 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -155,6 +155,10 @@ void Host_UpdateProgressDialog(const char* caption, int position, int total) { } +void Host_TitleChanged() +{ +} + static bool MsgAlert(const char* caption, const char* text, bool yes_no, MsgType /*style*/) { __android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "%s:%s", caption, text); diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 4e5bc4a4d0be..fa5db12061ad 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -725,6 +725,7 @@ void SConfig::SetRunningGameMetadata(const std::string& game_id, const std::stri GetCurrentLanguage(bWii); m_title_description = title_database.Describe(m_gametdb_id, language); NOTICE_LOG(CORE, "Active title: %s", m_title_description.c_str()); + Host_TitleChanged(); Config::AddLayer(ConfigLoaders::GenerateGlobalGameConfigLoader(game_id, revision)); Config::AddLayer(ConfigLoaders::GenerateLocalGameConfigLoader(game_id, revision)); diff --git a/Source/Core/Core/Host.h b/Source/Core/Core/Host.h index 0bea7769d518..99c0c6170880 100644 --- a/Source/Core/Core/Host.h +++ b/Source/Core/Core/Host.h @@ -45,3 +45,4 @@ void Host_UpdateMainFrame(); void Host_UpdateTitle(const std::string& title); void Host_YieldToUI(); void Host_UpdateProgressDialog(const char* caption, int position, int total); +void Host_TitleChanged(); diff --git a/Source/Core/DolphinNoGUI/MainNoGUI.cpp b/Source/Core/DolphinNoGUI/MainNoGUI.cpp index e4096d850109..1b35ac880998 100644 --- a/Source/Core/DolphinNoGUI/MainNoGUI.cpp +++ b/Source/Core/DolphinNoGUI/MainNoGUI.cpp @@ -105,6 +105,13 @@ void Host_UpdateProgressDialog(const char* caption, int position, int total) { } +void Host_TitleChanged() +{ +#ifdef USE_DISCORD_PRESENCE + Discord::UpdateDiscordPresence(); +#endif +} + static std::unique_ptr GetPlatform(const optparse::Values& options) { std::string platform_name = static_cast(options.get("platform")); diff --git a/Source/Core/DolphinQt/Host.cpp b/Source/Core/DolphinQt/Host.cpp index be0c8744b450..ac9c91942f04 100644 --- a/Source/Core/DolphinQt/Host.cpp +++ b/Source/Core/DolphinQt/Host.cpp @@ -17,6 +17,7 @@ #include "Core/Core.h" #include "Core/Debugger/PPCDebugInterface.h" #include "Core/Host.h" +#include "Core/NetPlayProto.h" #include "Core/PowerPC/PowerPC.h" #include "DolphinQt/QtUtils/QueueOnObject.h" @@ -24,6 +25,8 @@ #include "InputCommon/ControllerInterface/ControllerInterface.h" +#include "UICommon/DiscordPresence.h" + #include "VideoCommon/RenderBase.h" #include "VideoCommon/VideoConfig.h" @@ -164,3 +167,12 @@ bool Host_UIBlocksControllerState() void Host_RefreshDSPDebuggerWindow() { } + +void Host_TitleChanged() +{ +#ifdef USE_DISCORD_PRESENCE + // TODO: Not sure if the NetPlay check is needed. + if (!NetPlay::IsNetPlayRunning()) + Discord::UpdateDiscordPresence(); +#endif +} diff --git a/Source/DSPTool/StubHost.cpp b/Source/DSPTool/StubHost.cpp index ce7243e26504..ac6ef92e52bd 100644 --- a/Source/DSPTool/StubHost.cpp +++ b/Source/DSPTool/StubHost.cpp @@ -52,3 +52,6 @@ void Host_YieldToUI() void Host_UpdateProgressDialog(const char* caption, int position, int total) { } +void Host_TitleChanged() +{ +} diff --git a/Source/UnitTests/StubHost.cpp b/Source/UnitTests/StubHost.cpp index fd062be7323d..440ecd336a8e 100644 --- a/Source/UnitTests/StubHost.cpp +++ b/Source/UnitTests/StubHost.cpp @@ -53,3 +53,6 @@ void Host_YieldToUI() void Host_UpdateProgressDialog(const char* caption, int position, int total) { } +void Host_TitleChanged() +{ +}