mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-22 04:24:44 +00:00
added discord rpc
This commit is contained in:
parent
afe32d1e03
commit
18df757380
8 changed files with 75 additions and 48 deletions
5
.gitmodules
vendored
5
.gitmodules
vendored
|
@ -94,4 +94,7 @@
|
|||
[submodule "externals/pugixml"]
|
||||
path = externals/pugixml
|
||||
url = https://github.com/zeux/pugixml.git
|
||||
shallow = true
|
||||
shallow = true
|
||||
[submodule "externals/discord-rpc"]
|
||||
path = externals/discord-rpc
|
||||
url = https://github.com/delledev/discord-rpc
|
||||
|
|
|
@ -659,6 +659,8 @@ set(QT_GUI src/qt_gui/about_dialog.cpp
|
|||
src/qt_gui/cheats_patches.h
|
||||
src/qt_gui/check_update.cpp
|
||||
src/qt_gui/check_update.h
|
||||
src/qt_gui/discord_rpc_handler.cpp
|
||||
src/qt_gui/discord_rpc_handler.h
|
||||
src/qt_gui/main_window_ui.h
|
||||
src/qt_gui/main_window.cpp
|
||||
src/qt_gui/main_window.h
|
||||
|
@ -838,4 +840,10 @@ if (UNIX AND NOT APPLE)
|
|||
find_package(OpenSSL REQUIRED)
|
||||
target_link_libraries(shadps4 PRIVATE ${OPENSSL_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ENABLE_QT_GUI)
|
||||
add_subdirectory(externals/discord-rpc)
|
||||
target_link_libraries(shadps4 PRIVATE discord-rpc)
|
||||
include_directories(externals/discord-rpc/include)
|
||||
endif()
|
1
externals/discord-rpc
vendored
Submodule
1
externals/discord-rpc
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 80d35b5f86adc6557d0384771119cf167495dbae
|
|
@ -1,43 +0,0 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include "common/discord.h"
|
||||
|
||||
namespace Discord {
|
||||
|
||||
void RPC::init() {
|
||||
DiscordEventHandlers handlers{};
|
||||
Discord_Initialize("1139939140494971051", &handlers, 1, nullptr);
|
||||
|
||||
startTimestamp = time(nullptr);
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void RPC::update(Discord::RPCStatus status, const std::string& game) {
|
||||
DiscordRichPresence rpc{};
|
||||
|
||||
if (status == Discord::RPCStatus::Playing) {
|
||||
rpc.details = "Playing a game";
|
||||
rpc.state = game.c_str();
|
||||
} else {
|
||||
rpc.details = "Idle";
|
||||
}
|
||||
|
||||
rpc.largeImageKey = "shadps4";
|
||||
rpc.largeImageText = "ShadPS4 is a PS4 emulator";
|
||||
rpc.startTimestamp = startTimestamp;
|
||||
|
||||
Discord_UpdatePresence(&rpc);
|
||||
}
|
||||
|
||||
void RPC::stop() {
|
||||
if (enabled) {
|
||||
enabled = false;
|
||||
Discord_ClearPresence();
|
||||
Discord_Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Discord
|
43
src/qt_gui/discord_rpc_handler.cpp
Normal file
43
src/qt_gui/discord_rpc_handler.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include "src/qt_gui/discord_rpc_handler.h"
|
||||
|
||||
namespace DiscordRPCHandler {
|
||||
|
||||
void RPC::init() {
|
||||
DiscordEventHandlers handlers{};
|
||||
std::string discordAppId = "1290207945476280360";
|
||||
Discord_Initialize(discordAppId.c_str(), &handlers, 1, nullptr);
|
||||
startTimestamp = time(nullptr);
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void RPC::setStatusIdling() {
|
||||
DiscordRichPresence rpc{};
|
||||
rpc.largeImageKey = "https://github.com/shadps4-emu/shadPS4/raw/main/.github/shadps4.png";
|
||||
rpc.largeImageText = "ShadPS4 is a PS4 emulator";
|
||||
rpc.startTimestamp = startTimestamp;
|
||||
rpc.details = "Idle";
|
||||
|
||||
Discord_UpdatePresence(&rpc);
|
||||
}
|
||||
|
||||
void RPC::setStatusPlaying(const std::string& game_name, const std::string& game_id) {
|
||||
DiscordRichPresence rpc{};
|
||||
|
||||
rpc.details = "Playing";
|
||||
rpc.state = game_name.c_str();
|
||||
std::string largeImageUrl =
|
||||
"https://store.playstation.com/store/api/chihiro/00_09_000/titlecontainer/US/en/999/" +
|
||||
game_id + "_00/image";
|
||||
rpc.largeImageKey = largeImageUrl.c_str();
|
||||
rpc.largeImageText = game_name.c_str();
|
||||
rpc.startTimestamp = startTimestamp;
|
||||
|
||||
Discord_UpdatePresence(&rpc);
|
||||
}
|
||||
|
||||
} // namespace DiscordRPCHandler
|
|
@ -7,7 +7,7 @@
|
|||
#include <string>
|
||||
#include <discord_rpc.h>
|
||||
|
||||
namespace Discord {
|
||||
namespace DiscordRPCHandler {
|
||||
|
||||
enum class RPCStatus {
|
||||
Idling,
|
||||
|
@ -20,8 +20,8 @@ class RPC {
|
|||
|
||||
public:
|
||||
void init();
|
||||
void update(RPCStatus status, const std::string& title);
|
||||
void stop();
|
||||
void setStatusIdling();
|
||||
void setStatusPlaying(const std::string& game_name, const std::string& game_id);
|
||||
};
|
||||
|
||||
} // namespace Discord
|
||||
} // namespace DiscordRPCHandler
|
|
@ -69,6 +69,11 @@ bool MainWindow::Init() {
|
|||
QString statusMessage =
|
||||
"Games: " + QString::number(numGames) + " (" + QString::number(duration.count()) + "ms)";
|
||||
statusBar->showMessage(statusMessage);
|
||||
|
||||
//Initialize Discord RPC
|
||||
discordRPC.init();
|
||||
discordRPC.setStatusIdling();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -527,17 +532,23 @@ void MainWindow::StartGame() {
|
|||
if (table_mode == 0) {
|
||||
if (m_game_list_frame->currentItem()) {
|
||||
int itemID = m_game_list_frame->currentItem()->row();
|
||||
discordRPC.setStatusPlaying(m_game_info->m_games[itemID].name,
|
||||
m_game_info->m_games[itemID].serial);
|
||||
Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin");
|
||||
}
|
||||
} else if (table_mode == 1) {
|
||||
if (m_game_grid_frame->cellClicked) {
|
||||
int itemID = (m_game_grid_frame->crtRow * m_game_grid_frame->columnCnt) +
|
||||
m_game_grid_frame->crtColumn;
|
||||
discordRPC.setStatusPlaying(m_game_info->m_games[itemID].name,
|
||||
m_game_info->m_games[itemID].serial);
|
||||
Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin");
|
||||
}
|
||||
} else {
|
||||
if (m_elf_viewer->currentItem()) {
|
||||
int itemID = m_elf_viewer->currentItem()->row();
|
||||
discordRPC.setStatusPlaying(m_game_info->m_games[itemID].name,
|
||||
m_game_info->m_games[itemID].serial);
|
||||
gamePath = m_elf_viewer->m_elf_list[itemID];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "common/path_util.h"
|
||||
#include "core/file_format/psf.h"
|
||||
#include "core/file_sys/fs.h"
|
||||
#include "qt_gui/discord_rpc_handler.h"
|
||||
#include "elf_viewer.h"
|
||||
#include "emulator.h"
|
||||
#include "game_grid_frame.h"
|
||||
|
@ -93,6 +94,9 @@ private:
|
|||
|
||||
QTranslator* translator;
|
||||
|
||||
DiscordRPCHandler::RPC discordRPC;
|
||||
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue