Fix up Discord status

This commit is contained in:
wheremyfoodat 2023-08-07 22:48:26 +03:00
commit 7a52883c63
4 changed files with 23 additions and 14 deletions

View file

@ -4,6 +4,7 @@
#include <discord_rpc.h>
#include <cstdint>
#include <string>
namespace Discord {
enum class RPCStatus { Idling, Playing };
@ -14,7 +15,7 @@ namespace Discord {
public:
void init();
void update(RPCStatus status);
void update(RPCStatus status, const std::string& title);
void stop();
};
} // namespace Discord

View file

@ -67,8 +67,8 @@ class Emulator {
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
Discord::RPC discordRpc;
void updateDiscord();
#endif
void updateDiscord();
// Keep the handle for the ROM here to reload when necessary and to prevent deleting it
// This is currently only used for ELFs, NCSDs use the IOFile API instead

View file

@ -13,11 +13,15 @@ void Discord::RPC::init() {
enabled = true;
}
void Discord::RPC::update(Discord::RPCStatus status) {
void Discord::RPC::update(Discord::RPCStatus status, const std::string& game) {
DiscordRichPresence rpc{};
rpc.details = "Panda";
rpc.state = "Petting a panda";
if (status == Discord::RPCStatus::Playing) {
rpc.details = "Playing a game";
rpc.state = game.c_str();
} else {
rpc.details = "Idle";
}
rpc.largeImageKey = "pand";
rpc.largeImageText = "Panda3DS is a 3DS emulator for Windows, MacOS and Linux";

View file

@ -13,7 +13,7 @@ __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1;
Emulator::Emulator()
: config(std::filesystem::current_path() / "config.toml"), kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory, config),
memory(cpu.getTicksRef()), cheats(memory, kernel.getServiceManager().getHID())
memory(cpu.getTicksRef()), cheats(memory, kernel.getServiceManager().getHID()), running(false), programRunning(false)
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
, httpServer(this)
#endif
@ -37,6 +37,7 @@ Emulator::Emulator()
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
if (config.discordRpcEnabled) {
discordRpc.init();
updateDiscord();
}
#endif
@ -81,8 +82,6 @@ Emulator::Emulator()
}
}
running = false;
programRunning = false;
reset(ReloadOption::NoReload);
}
@ -444,11 +443,8 @@ bool Emulator::loadROM(const std::filesystem::path& path) {
if (success) {
romPath = path;
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
if (config.discordRpcEnabled) {
updateDiscord();
}
#endif
} else {
romPath = std::nullopt;
@ -509,7 +505,15 @@ void Emulator::initGraphicsContext() { gpu.initGraphicsContext(window); }
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
void Emulator::updateDiscord() {
auto status = running ? Discord::RPCStatus::Playing : Discord::RPCStatus::Idling;
discordRpc.update(status);
if (config.discordRpcEnabled) {
if (romType != ROMType::None) {
const auto name = romPath.value().stem();
discordRpc.update(Discord::RPCStatus::Playing, name.string());
} else {
discordRpc.update(Discord::RPCStatus::Idling, "");
}
}
}
#else
void Emulator::updateDiscord() {}
#endif