2024-02-23 21:32:32 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2023-08-11 17:22:26 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <ctime>
|
2024-02-23 21:32:32 +00:00
|
|
|
#include "common/discord.h"
|
2023-08-11 17:22:26 +00:00
|
|
|
|
2024-02-23 21:32:32 +00:00
|
|
|
namespace Discord {
|
|
|
|
|
|
|
|
void RPC::init() {
|
2024-02-23 20:57:57 +00:00
|
|
|
DiscordEventHandlers handlers{};
|
|
|
|
Discord_Initialize("1139939140494971051", &handlers, 1, nullptr);
|
2023-08-11 17:22:26 +00:00
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
startTimestamp = time(nullptr);
|
|
|
|
enabled = true;
|
2023-08-11 17:22:26 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 21:32:32 +00:00
|
|
|
void RPC::update(Discord::RPCStatus status, const std::string& game) {
|
2024-02-23 20:57:57 +00:00
|
|
|
DiscordRichPresence rpc{};
|
2023-08-11 17:22:26 +00:00
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
if (status == Discord::RPCStatus::Playing) {
|
|
|
|
rpc.details = "Playing a game";
|
|
|
|
rpc.state = game.c_str();
|
|
|
|
} else {
|
|
|
|
rpc.details = "Idle";
|
|
|
|
}
|
2023-08-11 17:22:26 +00:00
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
rpc.largeImageKey = "shadps4";
|
|
|
|
rpc.largeImageText = "ShadPS4 is a PS4 emulator";
|
|
|
|
rpc.startTimestamp = startTimestamp;
|
2023-08-11 17:22:26 +00:00
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
Discord_UpdatePresence(&rpc);
|
2023-08-11 17:22:26 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 21:32:32 +00:00
|
|
|
void RPC::stop() {
|
2024-02-23 20:57:57 +00:00
|
|
|
if (enabled) {
|
|
|
|
enabled = false;
|
|
|
|
Discord_ClearPresence();
|
|
|
|
Discord_Shutdown();
|
|
|
|
}
|
2023-08-11 17:22:26 +00:00
|
|
|
}
|
2024-02-23 21:32:32 +00:00
|
|
|
|
|
|
|
} // namespace Discord
|