From 57bd13a0ced5694cbeae24413bb5d9fe421a817a Mon Sep 17 00:00:00 2001 From: Sleepy Flower Girl Date: Wed, 6 Jun 2018 00:16:42 -0400 Subject: [PATCH] Use new config system for Discord Rich Presence option This doesn't feel like a mirror change to me. --- .../Core/ConfigLoaders/IsSettingSaveable.cpp | 5 ++++ Source/Core/Core/ConfigManager.cpp | 7 ------ Source/Core/Core/ConfigManager.h | 3 --- Source/Core/DolphinQt2/Settings.cpp | 16 ------------- Source/Core/DolphinQt2/Settings.h | 3 --- .../Core/DolphinQt2/Settings/GeneralPane.cpp | 9 ++++--- .../DolphinWX/Config/GeneralConfigPane.cpp | 17 ++++--------- Source/Core/UICommon/DiscordPresence.cpp | 24 ++++++++++++++++--- Source/Core/UICommon/DiscordPresence.h | 5 ++++ 9 files changed, 42 insertions(+), 47 deletions(-) diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 56b3ec8c74..5dd5fcf326 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -9,6 +9,7 @@ #include "Common/Config/Config.h" #include "Core/Config/GraphicsSettings.h" +#include "UICommon/DiscordPresence.h" namespace ConfigLoaders { @@ -115,6 +116,10 @@ bool IsSettingSaveable(const Config::ConfigLocation& config_location) Config::GFX_PERF_QUERIES_ENABLE.location, + // Main.General + + MAIN_USE_DISCORD_PRESENCE.location, + }; return std::find(s_setting_saveable.begin(), s_setting_saveable.end(), config_location) != diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index f6c657a20c..a88e6bc7fa 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -131,10 +131,6 @@ 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) @@ -420,9 +416,6 @@ 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 5c4f064307..8c2ae27461 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -71,9 +71,6 @@ 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/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index 9da03cbc2f..bd4a858365 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -480,19 +480,3 @@ void Settings::SetBatchModeEnabled(bool batch) { m_batch = batch; } - -#ifdef USE_DISCORD_PRESENCE -void Settings::SetDiscordPresenceEnabled(bool enabled) -{ - if (SConfig::GetInstance().bUseDiscordPresence == enabled) - return; - - if (SConfig::GetInstance().bUseDiscordPresence) - Discord::Shutdown(); - - SConfig::GetInstance().bUseDiscordPresence = enabled; - - if (SConfig::GetInstance().bUseDiscordPresence) - Discord::Init(); -} -#endif diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index d8c833e105..606f4ba9b6 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -127,9 +127,6 @@ public: // Other GameListModel* GetGameListModel() const; -#ifdef USE_DISCORD_PRESENCE - void SetDiscordPresenceEnabled(bool enabled); -#endif signals: void ConfigChanged(); void EmulationStateChanged(Core::State new_state); diff --git a/Source/Core/DolphinQt2/Settings/GeneralPane.cpp b/Source/Core/DolphinQt2/Settings/GeneralPane.cpp index 273859af7a..b5dbf0fe99 100644 --- a/Source/Core/DolphinQt2/Settings/GeneralPane.cpp +++ b/Source/Core/DolphinQt2/Settings/GeneralPane.cpp @@ -24,6 +24,9 @@ #include "Core/PowerPC/PowerPC.h" #include "DolphinQt2/Settings.h" #include "UICommon/AutoUpdate.h" +#ifdef USE_DISCORD_PRESENCE +#include "UICommon/DiscordPresence.h" +#endif constexpr int AUTO_UPDATE_DISABLE_INDEX = 0; constexpr int AUTO_UPDATE_STABLE_INDEX = 1; @@ -127,7 +130,7 @@ void GeneralPane::CreateBasic() basic_group_layout->addWidget(m_checkbox_cheats); #ifdef USE_DISCORD_PRESENCE - m_checkbox_discord_presence = new QCheckBox(tr("Show Activity in Your Discord Status")); + m_checkbox_discord_presence = new QCheckBox(tr("Show Current Game on Discord")); basic_group_layout->addWidget(m_checkbox_discord_presence); #endif @@ -224,7 +227,7 @@ void GeneralPane::LoadConfig() m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled()); #ifdef USE_DISCORD_PRESENCE - m_checkbox_discord_presence->setChecked(SConfig::GetInstance().bUseDiscordPresence); + m_checkbox_discord_presence->setChecked(Config::Get(MAIN_USE_DISCORD_PRESENCE)); #endif int selection = qRound(SConfig::GetInstance().m_EmulationSpeed * 10); if (selection < m_combobox_speedlimit->count()) @@ -272,7 +275,7 @@ void GeneralPane::OnSaveConfig() } #ifdef USE_DISCORD_PRESENCE - Settings::Instance().SetDiscordPresenceEnabled(m_checkbox_discord_presence->isChecked()); + Discord::SetDiscordPresenceEnabled(m_checkbox_discord_presence->isChecked()); #endif #if defined(USE_ANALYTICS) && USE_ANALYTICS diff --git a/Source/Core/DolphinWX/Config/GeneralConfigPane.cpp b/Source/Core/DolphinWX/Config/GeneralConfigPane.cpp index bd7d164582..e742e4588d 100644 --- a/Source/Core/DolphinWX/Config/GeneralConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/GeneralConfigPane.cpp @@ -59,8 +59,7 @@ void GeneralConfigPane::InitializeGUI() m_dual_core_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Dual Core (speedup)")); m_cheats_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Cheats")); #ifdef USE_DISCORD_PRESENCE - m_discord_presence_checkbox = - new wxCheckBox(this, wxID_ANY, _("Show Activity in Your Discord Status")); + m_discord_presence_checkbox = new wxCheckBox(this, wxID_ANY, _("Show Current Game on Discord")); #endif #if defined(USE_ANALYTICS) && USE_ANALYTICS m_analytics_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Usage Statistics Reporting")); @@ -83,8 +82,8 @@ void GeneralConfigPane::InitializeGUI() m_cheats_checkbox->SetToolTip(_("Enables the use of Action Replay and Gecko cheats.")); #ifdef USE_DISCORD_PRESENCE m_discord_presence_checkbox->SetToolTip( - _("Allow other people on Discord to see your current activity in Dolphin. Activities such as " - "games you are playing, and how long you've been doing something in Dolphin")); + _("Allow other people on Discord to see the current activity in Dolphin. Activities such as " + "the game being played, and for how long")); #endif #if defined(USE_ANALYTICS) && USE_ANALYTICS m_analytics_checkbox->SetToolTip( @@ -162,7 +161,7 @@ void GeneralConfigPane::LoadGUIValues() m_cheats_checkbox->SetValue(startup_params.bEnableCheats); #ifdef USE_DISCORD_PRESENCE - m_discord_presence_checkbox->SetValue(startup_params.bUseDiscordPresence); + m_discord_presence_checkbox->SetValue(Config::Get(MAIN_USE_DISCORD_PRESENCE)); #endif #if defined(USE_ANALYTICS) && USE_ANALYTICS @@ -222,13 +221,7 @@ void GeneralConfigPane::OnCheatCheckBoxChanged(wxCommandEvent& event) #ifdef USE_DISCORD_PRESENCE void GeneralConfigPane::OnDiscordPresenceCheckBoxChanged(wxCommandEvent& event) { - if (SConfig::GetInstance().bUseDiscordPresence) - Discord::Shutdown(); - - SConfig::GetInstance().bUseDiscordPresence = m_discord_presence_checkbox->IsChecked(); - - if (SConfig::GetInstance().bUseDiscordPresence) - Discord::Init(); + Discord::SetDiscordPresenceEnabled(m_discord_presence_checkbox->IsChecked()); } #endif diff --git a/Source/Core/UICommon/DiscordPresence.cpp b/Source/Core/UICommon/DiscordPresence.cpp index 4a8280ed7a..13fcab69bc 100644 --- a/Source/Core/UICommon/DiscordPresence.cpp +++ b/Source/Core/UICommon/DiscordPresence.cpp @@ -13,12 +13,15 @@ #endif +const Config::ConfigInfo MAIN_USE_DISCORD_PRESENCE{ + {Config::System::Main, "General", "UseDiscordPresence"}, true}; + namespace Discord { void Init() { #ifdef USE_DISCORD_PRESENCE - if (!SConfig::GetInstance().bUseDiscordPresence) + if (!Config::Get(MAIN_USE_DISCORD_PRESENCE)) return; DiscordEventHandlers handlers = {}; @@ -31,7 +34,7 @@ void Init() void UpdateDiscordPresence() { #ifdef USE_DISCORD_PRESENCE - if (!SConfig::GetInstance().bUseDiscordPresence) + if (!Config::Get(MAIN_USE_DISCORD_PRESENCE)) return; const std::string& title = SConfig::GetInstance().GetTitleDescription(); @@ -48,11 +51,26 @@ void UpdateDiscordPresence() void Shutdown() { #ifdef USE_DISCORD_PRESENCE - if (!SConfig::GetInstance().bUseDiscordPresence) + if (!Config::Get(MAIN_USE_DISCORD_PRESENCE)) return; Discord_ClearPresence(); Discord_Shutdown(); #endif } + +void SetDiscordPresenceEnabled(bool enabled) +{ + if (Config::Get(MAIN_USE_DISCORD_PRESENCE) == enabled) + return; + + if (Config::Get(MAIN_USE_DISCORD_PRESENCE)) + Discord::Shutdown(); + + Config::SetBase(MAIN_USE_DISCORD_PRESENCE, enabled); + + if (Config::Get(MAIN_USE_DISCORD_PRESENCE)) + Discord::Init(); +} + } // namespace Discord diff --git a/Source/Core/UICommon/DiscordPresence.h b/Source/Core/UICommon/DiscordPresence.h index dc516fd655..ca27698b53 100644 --- a/Source/Core/UICommon/DiscordPresence.h +++ b/Source/Core/UICommon/DiscordPresence.h @@ -4,9 +4,14 @@ #pragma once +#include "Common/Config/Config.h" + namespace Discord { void Init(); void UpdateDiscordPresence(); void Shutdown(); +void SetDiscordPresenceEnabled(bool enabled); } // namespace Discord + +extern const Config::ConfigInfo MAIN_USE_DISCORD_PRESENCE;