Merge pull request #6983 from yourWaifu/add-discord-rpc-support

Add Discord Rich Presence support
This commit is contained in:
Pierre Bourdon
2018-06-25 00:06:27 +02:00
committed by GitHub
84 changed files with 18060 additions and 4 deletions

View File

@ -2,6 +2,7 @@ add_library(uicommon
AutoUpdate.cpp
CommandLineParse.cpp
Disassembler.cpp
DiscordPresence.cpp
GameFile.cpp
GameFileCache.cpp
UICommon.cpp
@ -36,3 +37,8 @@ if(ENABLE_LLVM)
target_include_directories(uicommon PRIVATE ${LLVM_INCLUDE_DIRS})
endif()
endif()
if(USE_DISCORD_PRESENCE)
target_compile_definitions(uicommon PRIVATE -DUSE_DISCORD_PRESENCE)
target_link_libraries(uicommon PRIVATE discord-rpc)
endif()

View File

@ -0,0 +1,73 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "UICommon/DiscordPresence.h"
#include "Core/Config/UISettings.h"
#include "Core/ConfigManager.h"
#ifdef USE_DISCORD_PRESENCE
#include <ctime>
#include <discord-rpc/include/discord_rpc.h>
#endif
namespace Discord
{
void Init()
{
#ifdef USE_DISCORD_PRESENCE
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
return;
DiscordEventHandlers handlers = {};
// The number is the client ID for Dolphin, it's used for images and the appication name
Discord_Initialize("455712169795780630", &handlers, 1, nullptr);
UpdateDiscordPresence();
#endif
}
void UpdateDiscordPresence()
{
#ifdef USE_DISCORD_PRESENCE
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
return;
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
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
return;
Discord_ClearPresence();
Discord_Shutdown();
#endif
}
void SetDiscordPresenceEnabled(bool enabled)
{
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE) == enabled)
return;
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
Discord::Shutdown();
Config::SetBase(Config::MAIN_USE_DISCORD_PRESENCE, enabled);
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
Discord::Init();
}
} // namespace Discord

View File

@ -0,0 +1,13 @@
// 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();
void SetDiscordPresenceEnabled(bool enabled);
} // namespace Discord

View File

@ -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();
}

View File

@ -45,10 +45,14 @@
<ProjectReference Include="..\..\..\Externals\picojson\picojson.vcxproj">
<Project>{2c0d058e-de35-4471-ad99-e68a2caf9e18}</Project>
</ProjectReference>
<ProjectReference Include="$(ExternalsDir)discord-rpc\src\discord-rpc.vcxproj">
<Project>{4482FD2A-EC43-3FFB-AC20-2E5C54B05EAD}</Project>
</ProjectReference>
</ItemGroup>
<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 +65,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" />