summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorSleepy Flower Girl <wuhao64@gmail.com>2018-05-27 00:24:13 -0400
committerSleepy Flower Girl <wuhao64@gmail.com>2018-06-03 15:27:20 -0400
commitd5303ddf0ba893d31f7e464aab3e36bc179e200e (patch)
treec5824203b5e1de1a5f5682a2c231803ecbbf8b3f /Source/Core
parentf568e41fac4832b427b0ce290e65a485a790db40 (diff)
Add Discord Rich Presence support
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Core.vcxproj2
-rw-r--r--Source/Core/Core/Core.vcxproj.filters2
-rw-r--r--Source/Core/DolphinQt2/DolphinQt2.vcxproj4
-rw-r--r--Source/Core/DolphinQt2/MainWindow.cpp3
-rw-r--r--Source/Core/DolphinWX/DolphinWX.vcxproj4
-rw-r--r--Source/Core/DolphinWX/FrameTools.cpp3
-rw-r--r--Source/Core/UICommon/CMakeLists.txt1
-rw-r--r--Source/Core/UICommon/DiscordPresence.cpp48
-rw-r--r--Source/Core/UICommon/DiscordPresence.h12
-rw-r--r--Source/Core/UICommon/UICommon.cpp3
-rw-r--r--Source/Core/UICommon/UICommon.vcxproj12
11 files changed, 88 insertions, 6 deletions
diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj
index ae841ca4d1..b84e98dd70 100644
--- a/Source/Core/Core/Core.vcxproj
+++ b/Source/Core/Core/Core.vcxproj
@@ -592,4 +592,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project> \ No newline at end of file
diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters
index 944dfc1436..1dad1f08f2 100644
--- a/Source/Core/Core/Core.vcxproj.filters
+++ b/Source/Core/Core/Core.vcxproj.filters
@@ -1584,4 +1584,4 @@
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
-</Project>
+</Project> \ No newline at end of file
diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj
index decbae647a..2b0698682a 100644
--- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj
+++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj
@@ -40,8 +40,8 @@
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
- <AdditionalLibraryDirectories>$(ExternalsDir)ffmpeg\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <AdditionalDependencies>avrt.lib;iphlpapi.lib;winmm.lib;setupapi.lib;opengl32.lib;glu32.lib;rpcrt4.lib;comctl32.lib;avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>$(ExternalsDir)ffmpeg\lib;$(ExternalsDir)discord-rpc\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>avrt.lib;iphlpapi.lib;winmm.lib;setupapi.lib;opengl32.lib;glu32.lib;rpcrt4.lib;comctl32.lib;avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;Shlwapi.lib;discord-rpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)VideoInterface;$(ProjectDir)GameList;$(ProjectDir)Debugger;$(ProjectDir)Settings;$(ProjectDir)Config;$(ProjectDir)Config\Mapping;$(ProjectDir)Config\Graphics;$(ProjectDir)NetPlay;$(ProjectDir)QtUtils;$(ProjectDir)TAS;$(ProjectDir)FIFO;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp
index 524ec9114b..edd4bb199a 100644
--- a/Source/Core/DolphinQt2/MainWindow.cpp
+++ b/Source/Core/DolphinQt2/MainWindow.cpp
@@ -79,6 +79,7 @@
#include "InputCommon/ControllerInterface/ControllerInterface.h"
+#include "UICommon/DiscordPresence.h"
#include "UICommon/UICommon.h"
#if defined(HAVE_XRANDR) && HAVE_XRANDR
@@ -569,6 +570,7 @@ void MainWindow::OnStopComplete()
m_stop_requested = false;
HideRenderWidget();
EnableScreenSaver(true);
+ Discord::UpdateDiscordPresence();
SetFullScreenResolution(false);
@@ -719,6 +721,7 @@ void MainWindow::StartGame(std::unique_ptr<BootParameters>&& parameters)
return;
}
ShowRenderWidget();
+ Discord::UpdateDiscordPresence();
#ifdef Q_OS_WIN
// Prevents Windows from sleeping, turning off the display, or idling
diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj b/Source/Core/DolphinWX/DolphinWX.vcxproj
index d7d7519f16..1aabf572a2 100644
--- a/Source/Core/DolphinWX/DolphinWX.vcxproj
+++ b/Source/Core/DolphinWX/DolphinWX.vcxproj
@@ -38,8 +38,8 @@
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<Link>
- <AdditionalLibraryDirectories>$(ExternalsDir)ffmpeg\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <AdditionalDependencies>avrt.lib;iphlpapi.lib;winmm.lib;setupapi.lib;opengl32.lib;glu32.lib;rpcrt4.lib;comctl32.lib;avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>$(ExternalsDir)ffmpeg\lib;$(ExternalsDir)discord-rpc\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>avrt.lib;iphlpapi.lib;winmm.lib;setupapi.lib;opengl32.lib;glu32.lib;rpcrt4.lib;comctl32.lib;avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;Shlwapi.lib;discord-rpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>$(ExternalsDir)wxWidgets3\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp
index ea6f504e7c..63dcdc16c5 100644
--- a/Source/Core/DolphinWX/FrameTools.cpp
+++ b/Source/Core/DolphinWX/FrameTools.cpp
@@ -91,6 +91,7 @@
#include "InputCommon/ControllerInterface/ControllerInterface.h"
+#include "UICommon/DiscordPresence.h"
#include "UICommon/GameFile.h"
#include "UICommon/UICommon.h"
@@ -744,6 +745,7 @@ void CFrame::StartGame(std::unique_ptr<BootParameters> boot)
else
{
EnableScreenSaver(false);
+ Discord::UpdateDiscordPresence();
// We need this specifically to support setting the focus properly when using
// the 'render to main window' feature on Windows
@@ -930,6 +932,7 @@ void CFrame::OnStopped()
wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM});
EnableScreenSaver(true);
+ Discord::UpdateDiscordPresence();
m_render_frame->SetTitle(StrToWxStr(Common::scm_rev_str));
diff --git a/Source/Core/UICommon/CMakeLists.txt b/Source/Core/UICommon/CMakeLists.txt
index ed94341182..8b3976fb0c 100644
--- a/Source/Core/UICommon/CMakeLists.txt
+++ b/Source/Core/UICommon/CMakeLists.txt
@@ -2,6 +2,7 @@ add_library(uicommon
AutoUpdate.cpp
CommandLineParse.cpp
Disassembler.cpp
+ DiscordPresence.cpp
GameFile.cpp
GameFileCache.cpp
UICommon.cpp
diff --git a/Source/Core/UICommon/DiscordPresence.cpp b/Source/Core/UICommon/DiscordPresence.cpp
new file mode 100644
index 0000000000..0ec4cdb5b8
--- /dev/null
+++ b/Source/Core/UICommon/DiscordPresence.cpp
@@ -0,0 +1,48 @@
+// Copyright 2018 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#ifdef USE_DISCORD_PRESENCE
+
+#include "UICommon/DiscordPresence.h"
+
+#include <ctime>
+#include <discord-rpc/include/discord_rpc.h>
+
+#include "Core/ConfigManager.h"
+
+#endif
+
+namespace Discord
+{
+void Init()
+{
+#ifdef USE_DISCORD_PRESENCE
+ 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);
+ UpdateDiscordPresence();
+#endif
+}
+
+void UpdateDiscordPresence()
+{
+#ifdef USE_DISCORD_PRESENCE
+ const std::string& title = SConfig::GetInstance().GetTitleDescription();
+
+ DiscordRichPresence discord_presence = {};
+ discord_presence.largeImageKey = "dolphin_logo";
+ discord_presence.largeImageText = "Dolphin is an emulator for the GameCube and the Wii.";
+ discord_presence.details = title.empty() ? "Not in-game" : title.c_str();
+ discord_presence.startTimestamp = std::time(nullptr);
+ Discord_UpdatePresence(&discord_presence);
+#endif
+}
+
+void Shutdown()
+{
+#ifdef USE_DISCORD_PRESENCE
+ Discord_Shutdown();
+#endif
+}
+} // namespace Discord
diff --git a/Source/Core/UICommon/DiscordPresence.h b/Source/Core/UICommon/DiscordPresence.h
new file mode 100644
index 0000000000..dc516fd655
--- /dev/null
+++ b/Source/Core/UICommon/DiscordPresence.h
@@ -0,0 +1,12 @@
+// Copyright 2018 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+namespace Discord
+{
+void Init();
+void UpdateDiscordPresence();
+void Shutdown();
+} // namespace Discord
diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp
index 16fd08bad0..24a60b27a8 100644
--- a/Source/Core/UICommon/UICommon.cpp
+++ b/Source/Core/UICommon/UICommon.cpp
@@ -33,6 +33,7 @@
#include "InputCommon/GCAdapter.h"
+#include "UICommon/DiscordPresence.h"
#include "UICommon/UICommon.h"
#include "UICommon/USBUtils.h"
@@ -75,6 +76,7 @@ void Init()
Config::AddConfigChangedCallback(InitCustomPaths);
Config::AddLayer(ConfigLoaders::GenerateBaseConfigLoader());
SConfig::Init();
+ Discord::Init();
LogManager::Init();
VideoBackendBase::PopulateList();
WiimoteReal::LoadSettings();
@@ -90,6 +92,7 @@ void Shutdown()
WiimoteReal::Shutdown();
VideoBackendBase::ClearList();
LogManager::Shutdown();
+ Discord::Shutdown();
SConfig::Shutdown();
Config::Shutdown();
}
diff --git a/Source/Core/UICommon/UICommon.vcxproj b/Source/Core/UICommon/UICommon.vcxproj
index 4ee5a357c0..1a650b3a0c 100644
--- a/Source/Core/UICommon/UICommon.vcxproj
+++ b/Source/Core/UICommon/UICommon.vcxproj
@@ -35,6 +35,16 @@
<Import Project="..\..\VSProps\PCHUse.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PreprocessorDefinitions>USE_DISCORD_PRESENCE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <PreprocessorDefinitions>USE_DISCORD_PRESENCE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ </ItemDefinitionGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
@@ -49,6 +59,7 @@
<ItemGroup>
<ClCompile Include="AutoUpdate.cpp" />
<ClCompile Include="CommandLineParse.cpp" />
+ <ClCompile Include="DiscordPresence.cpp" />
<ClCompile Include="UICommon.cpp" />
<ClCompile Include="Disassembler.cpp" />
<ClCompile Include="USBUtils.cpp">
@@ -61,6 +72,7 @@
<ItemGroup>
<ClInclude Include="AutoUpdate.h" />
<ClInclude Include="CommandLineParse.h" />
+ <ClInclude Include="DiscordPresence.h" />
<ClInclude Include="UICommon.h" />
<ClInclude Include="Disassembler.h" />
<ClInclude Include="USBUtils.h" />