CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/UI/DiscordIntegration.cpp
Views: 1401
1#include <ctime>2#include <string>34#include "ppsspp_config.h"5#include "Common/Log.h"6#include "Core/Config.h"7#include "DiscordIntegration.h"8#include "Common/Data/Text/I18n.h"910#if (PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(LINUX)) && !PPSSPP_PLATFORM(ANDROID) && !PPSSPP_PLATFORM(UWP)1112#ifdef _MSC_VER13#define ENABLE_DISCORD14#elif USE_DISCORD15#define ENABLE_DISCORD16#endif1718#else1920// TODO2122#endif2324#ifdef ENABLE_DISCORD25#include "ext/discord-rpc/include/discord_rpc.h"26#endif2728// TODO: Enable on more platforms. Make optional.2930Discord g_Discord;3132static const char *ppsspp_app_id = "423397985041383434";3334#ifdef ENABLE_DISCORD35// No context argument? What?36static void handleDiscordError(int errCode, const char *message) {37ERROR_LOG(Log::System, "Discord error code %d: '%s'", errCode, message);38}39#endif4041Discord::~Discord() {42if (initialized_) {43ERROR_LOG(Log::System, "Discord destructor running though g_Discord.Shutdown() has not been called.");44}45}4647bool Discord::IsEnabled() const {48return g_Config.bDiscordPresence;49}5051void Discord::Init() {52_assert_(IsEnabled());53_assert_(!initialized_);5455#ifdef ENABLE_DISCORD56DiscordEventHandlers eventHandlers{};57eventHandlers.errored = &handleDiscordError;58Discord_Initialize(ppsspp_app_id, &eventHandlers, 0, nullptr);59INFO_LOG(Log::System, "Discord connection initialized");60#endif6162initialized_ = true;63}6465void Discord::Shutdown() {66if (initialized_) {67#ifdef ENABLE_DISCORD68Discord_Shutdown();69#endif70initialized_ = false;71}72}7374void Discord::Update() {75if (!IsEnabled()) {76if (initialized_) {77Shutdown();78}79return;80} else {81if (!initialized_) {82Init();83}84}8586#ifdef ENABLE_DISCORD87#ifdef DISCORD_DISABLE_IO_THREAD88Discord_UpdateConnection();89#endif90Discord_RunCallbacks();91#endif92}9394void Discord::SetPresenceGame(std::string_view gameTitle) {95if (!IsEnabled())96return;9798if (!initialized_) {99Init();100}101102#ifdef ENABLE_DISCORD103auto sc = GetI18NCategory(I18NCat::SCREEN);104std::string title(gameTitle);105DiscordRichPresence discordPresence{};106discordPresence.state = title.c_str();107discordPresence.details = sc->T_cstr("Playing");108discordPresence.startTimestamp = time(0);109discordPresence.largeImageText = "PPSSPP is the best PlayStation Portable emulator around!";110#ifdef GOLD111discordPresence.largeImageKey = "icon_gold_png";112#else113discordPresence.largeImageKey = "icon_regular_png";114#endif115Discord_UpdatePresence(&discordPresence);116#endif117}118119void Discord::SetPresenceMenu() {120if (!IsEnabled())121return;122123if (!initialized_) {124Init();125}126127#ifdef ENABLE_DISCORD128auto sc = GetI18NCategory(I18NCat::SCREEN);129130DiscordRichPresence discordPresence{};131discordPresence.state = sc->T_cstr("In menu");132discordPresence.details = "";133discordPresence.startTimestamp = time(0);134discordPresence.largeImageText = "PPSSPP is the best PlayStation Portable emulator around!";135#ifdef GOLD136discordPresence.largeImageKey = "icon_gold_png";137#else138discordPresence.largeImageKey = "icon_regular_png";139#endif140Discord_UpdatePresence(&discordPresence);141#endif142}143144void Discord::ClearPresence() {145if (!IsEnabled() || !initialized_)146return;147148#ifdef ENABLE_DISCORD149Discord_ClearPresence();150#endif151}152153154