From d9351a5b45c181eb6503391f9c3ba486a62de8e2 Mon Sep 17 00:00:00 2001 From: Sleepy Flower Girl Date: Tue, 29 May 2018 23:44:20 -0400 Subject: [PATCH] Added INI setting for Discord Rich Presence --- Source/Core/Core/ConfigManager.cpp | 7 +++++++ Source/Core/Core/ConfigManager.h | 3 +++ Source/Core/DolphinQt2/MainWindow.cpp | 4 ++++ Source/Core/DolphinWX/FrameTools.cpp | 4 ++++ Source/Core/UICommon/DiscordPresence.cpp | 9 +++++++++ 5 files changed, 27 insertions(+) diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index a88e6bc7fa..f6c657a20c 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -131,6 +131,10 @@ void SConfig::SaveGeneralSettings(IniFile& ini) #endif general->Set("GDBPort", iGDBPort); #endif + +#ifdef USE_DISCORD_PRESENCE + general->Set("UseDiscordPresence", bUseDiscordPresence); +#endif } void SConfig::SaveInterfaceSettings(IniFile& ini) @@ -416,6 +420,9 @@ void SConfig::LoadGeneralSettings(IniFile& ini) general->Get("RecursiveISOPaths", &m_RecursiveISOFolder, false); general->Get("WirelessMac", &m_WirelessMac); +#ifdef USE_DISCORD_PRESENCE + general->Get("UseDiscordPresence", &bUseDiscordPresence, true); +#endif } void SConfig::LoadInterfaceSettings(IniFile& ini) diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 8c2ae27461..5c4f064307 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -71,6 +71,9 @@ struct SConfig #ifndef _WIN32 std::string gdb_socket; #endif +#endif +#ifdef USE_DISCORD_PRESENCE + bool bUseDiscordPresence; #endif bool bAutomaticStart = false; bool bBootToPause = false; diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index edd4bb199a..32ba5cadd1 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -570,7 +570,9 @@ void MainWindow::OnStopComplete() m_stop_requested = false; HideRenderWidget(); EnableScreenSaver(true); +#ifdef USE_DISCORD_PRESENCE Discord::UpdateDiscordPresence(); +#endif SetFullScreenResolution(false); @@ -721,7 +723,9 @@ void MainWindow::StartGame(std::unique_ptr&& parameters) return; } ShowRenderWidget(); +#ifdef USE_DISCORD_PRESENCE Discord::UpdateDiscordPresence(); +#endif #ifdef Q_OS_WIN // Prevents Windows from sleeping, turning off the display, or idling diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 63dcdc16c5..de404a05c9 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -745,7 +745,9 @@ void CFrame::StartGame(std::unique_ptr boot) else { EnableScreenSaver(false); +#ifdef USE_DISCORD_PRESENCE Discord::UpdateDiscordPresence(); +#endif // We need this specifically to support setting the focus properly when using // the 'render to main window' feature on Windows @@ -932,7 +934,9 @@ void CFrame::OnStopped() wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM}); EnableScreenSaver(true); +#ifdef USE_DISCORD_PRESENCE Discord::UpdateDiscordPresence(); +#endif m_render_frame->SetTitle(StrToWxStr(Common::scm_rev_str)); diff --git a/Source/Core/UICommon/DiscordPresence.cpp b/Source/Core/UICommon/DiscordPresence.cpp index 0ec4cdb5b8..a7bc6f7209 100644 --- a/Source/Core/UICommon/DiscordPresence.cpp +++ b/Source/Core/UICommon/DiscordPresence.cpp @@ -18,6 +18,9 @@ namespace Discord void Init() { #ifdef USE_DISCORD_PRESENCE + if (!SConfig::GetInstance().bUseDiscordPresence) + return; + DiscordEventHandlers handlers = {}; // The number is the client ID for Dolphin, it's used for images and the appication name Discord_Initialize("450033159212630028", &handlers, 1, nullptr); @@ -28,6 +31,9 @@ void Init() void UpdateDiscordPresence() { #ifdef USE_DISCORD_PRESENCE + if (!SConfig::GetInstance().bUseDiscordPresence) + return; + const std::string& title = SConfig::GetInstance().GetTitleDescription(); DiscordRichPresence discord_presence = {}; @@ -42,6 +48,9 @@ void UpdateDiscordPresence() void Shutdown() { #ifdef USE_DISCORD_PRESENCE + if (!SConfig::GetInstance().bUseDiscordPresence) + return; + Discord_Shutdown(); #endif }