2018-05-27 04:24:13 +00:00
|
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
|
|
#include "UICommon/DiscordPresence.h"
|
2018-06-08 20:56:11 +00:00
|
|
|
|
#include "Core/Config/UISettings.h"
|
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
|
|
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
2018-05-27 04:24:13 +00:00
|
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
|
#include <discord-rpc/include/discord_rpc.h>
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace Discord
|
|
|
|
|
{
|
|
|
|
|
void Init()
|
|
|
|
|
{
|
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
2018-06-08 20:56:11 +00:00
|
|
|
|
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
|
2018-05-30 03:44:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-05-27 04:24:13 +00:00
|
|
|
|
DiscordEventHandlers handlers = {};
|
|
|
|
|
// The number is the client ID for Dolphin, it's used for images and the appication name
|
2018-06-08 20:56:11 +00:00
|
|
|
|
Discord_Initialize("455712169795780630", &handlers, 1, nullptr);
|
2018-05-27 04:24:13 +00:00
|
|
|
|
UpdateDiscordPresence();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateDiscordPresence()
|
|
|
|
|
{
|
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
2018-06-08 20:56:11 +00:00
|
|
|
|
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
|
2018-05-30 03:44:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-05-27 04:24:13 +00:00
|
|
|
|
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
|
2018-06-08 20:56:11 +00:00
|
|
|
|
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
|
2018-05-30 03:44:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-06-01 02:54:15 +00:00
|
|
|
|
Discord_ClearPresence();
|
2018-05-27 04:24:13 +00:00
|
|
|
|
Discord_Shutdown();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2018-06-06 04:16:42 +00:00
|
|
|
|
|
|
|
|
|
void SetDiscordPresenceEnabled(bool enabled)
|
|
|
|
|
{
|
2018-06-08 20:56:11 +00:00
|
|
|
|
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE) == enabled)
|
2018-06-06 04:16:42 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-06-08 20:56:11 +00:00
|
|
|
|
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
|
2018-06-06 04:16:42 +00:00
|
|
|
|
Discord::Shutdown();
|
|
|
|
|
|
2018-06-08 20:56:11 +00:00
|
|
|
|
Config::SetBase(Config::MAIN_USE_DISCORD_PRESENCE, enabled);
|
2018-06-06 04:16:42 +00:00
|
|
|
|
|
2018-06-08 20:56:11 +00:00
|
|
|
|
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
|
2018-06-06 04:16:42 +00:00
|
|
|
|
Discord::Init();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-27 04:24:13 +00:00
|
|
|
|
} // namespace Discord
|