mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
Add Discord Rich Presence support
This commit is contained in:
@ -2,6 +2,7 @@ add_library(uicommon
|
||||
AutoUpdate.cpp
|
||||
CommandLineParse.cpp
|
||||
Disassembler.cpp
|
||||
DiscordPresence.cpp
|
||||
GameFile.cpp
|
||||
GameFileCache.cpp
|
||||
UICommon.cpp
|
||||
|
48
Source/Core/UICommon/DiscordPresence.cpp
Normal file
48
Source/Core/UICommon/DiscordPresence.cpp
Normal file
@ -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
|
12
Source/Core/UICommon/DiscordPresence.h
Normal file
12
Source/Core/UICommon/DiscordPresence.h
Normal file
@ -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
|
@ -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();
|
||||
}
|
||||
|
@ -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" />
|
||||
|
Reference in New Issue
Block a user