[App/Discord] Rework how rich presence is managed.
Updating rich presence state every time the window title changes is a bad idea(tm).
This commit is contained in:
parent
763274654d
commit
c16ef67ff9
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
|
@ -20,7 +20,7 @@ void HandleDiscordJoinGame(const char* joinSecret) {}
|
|||
void HandleDiscordJoinRequest(const DiscordUser* request) {}
|
||||
void HandleDiscordSpectateGame(const char* spectateSecret) {}
|
||||
|
||||
void DiscordPresence::InitializeDiscord() {
|
||||
void DiscordPresence::Initialize() {
|
||||
DiscordEventHandlers handlers = {};
|
||||
handlers.ready = &HandleDiscordReady;
|
||||
handlers.errored = &HandleDiscordError;
|
||||
|
@ -39,7 +39,7 @@ void DiscordPresence::NotPlaying() {
|
|||
Discord_UpdatePresence(&discordPresence);
|
||||
}
|
||||
|
||||
void DiscordPresence::PlayingTitle(std::wstring game_title) {
|
||||
void DiscordPresence::PlayingTitle(const std::wstring& game_title) {
|
||||
auto discord_game_title = xe::to_string(game_title);
|
||||
DiscordRichPresence discordPresence = {};
|
||||
discordPresence.state = "In Game";
|
||||
|
@ -50,7 +50,7 @@ void DiscordPresence::PlayingTitle(std::wstring game_title) {
|
|||
Discord_UpdatePresence(&discordPresence);
|
||||
}
|
||||
|
||||
void DiscordPresence::ShutdownDiscord() { Discord_Shutdown(); }
|
||||
void DiscordPresence::Shutdown() { Discord_Shutdown(); }
|
||||
|
||||
} // namespace discord
|
||||
} // namespace xe
|
||||
|
|
|
@ -17,10 +17,10 @@ namespace discord {
|
|||
|
||||
class DiscordPresence {
|
||||
public:
|
||||
static void InitializeDiscord();
|
||||
static void Initialize();
|
||||
static void NotPlaying();
|
||||
static void PlayingTitle(std::wstring game_title);
|
||||
static void ShutdownDiscord();
|
||||
static void PlayingTitle(const std::wstring& game_title);
|
||||
static void Shutdown();
|
||||
};
|
||||
|
||||
} // namespace discord
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "build/version.h"
|
||||
|
||||
#include "third_party/imgui/imgui.h"
|
||||
#include "xenia/app/discord/discord_presence.h"
|
||||
#include "xenia/base/clock.h"
|
||||
#include "xenia/base/cvar.h"
|
||||
#include "xenia/base/debugging.h"
|
||||
|
@ -29,7 +28,6 @@
|
|||
#include "xenia/ui/imgui_drawer.h"
|
||||
|
||||
DECLARE_bool(debug);
|
||||
DEFINE_bool(discord, false, "Enable Discord rich presence", "General");
|
||||
|
||||
namespace xe {
|
||||
namespace app {
|
||||
|
@ -85,11 +83,6 @@ bool EmulatorWindow::Initialize() {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (cvars::discord) {
|
||||
discord::DiscordPresence::InitializeDiscord();
|
||||
discord::DiscordPresence::NotPlaying();
|
||||
}
|
||||
|
||||
UpdateTitle();
|
||||
|
||||
window_->on_closed.AddListener([this](UIEvent* e) { loop_->Quit(); });
|
||||
|
@ -344,9 +337,6 @@ void EmulatorWindow::FileOpen() {
|
|||
void EmulatorWindow::FileClose() {
|
||||
if (emulator_->is_title_open()) {
|
||||
emulator_->TerminateTitle();
|
||||
if (cvars::discord) {
|
||||
discord::DiscordPresence::NotPlaying();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,9 +434,6 @@ void EmulatorWindow::UpdateTitle() {
|
|||
auto game_title = emulator()->game_title();
|
||||
title += xe::format_string(L" | [%.8X] %s", emulator()->title_id(),
|
||||
game_title.c_str());
|
||||
if (cvars::discord) {
|
||||
discord::DiscordPresence::PlayingTitle(game_title);
|
||||
}
|
||||
}
|
||||
|
||||
auto graphics_system = emulator()->graphics_system();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "xenia/app/discord/discord_presence.h"
|
||||
#include "xenia/app/emulator_window.h"
|
||||
#include "xenia/base/cvar.h"
|
||||
#include "xenia/base/debugging.h"
|
||||
|
@ -56,6 +57,8 @@ DEFINE_bool(mount_cache, false, "Enable cache mount", "General");
|
|||
CmdVar(target, "", "Specifies the target .xex or .iso to execute.");
|
||||
DECLARE_bool(debug);
|
||||
|
||||
DEFINE_bool(discord, true, "Enable Discord rich presence", "General");
|
||||
|
||||
namespace xe {
|
||||
namespace app {
|
||||
|
||||
|
@ -145,6 +148,11 @@ int xenia_main(const std::vector<std::wstring>& args) {
|
|||
Profiler::Initialize();
|
||||
Profiler::ThreadEnter("main");
|
||||
|
||||
if (cvars::discord) {
|
||||
discord::DiscordPresence::Initialize();
|
||||
discord::DiscordPresence::NotPlaying();
|
||||
}
|
||||
|
||||
// Figure out where content should go.
|
||||
std::wstring content_root = xe::to_wstring(cvars::content_root);
|
||||
std::wstring config_folder;
|
||||
|
@ -256,11 +264,21 @@ int xenia_main(const std::vector<std::wstring>& args) {
|
|||
}
|
||||
|
||||
auto evt = xe::threading::Event::CreateAutoResetEvent(false);
|
||||
emulator->on_launch.AddListener([&]() {
|
||||
emulator->on_launch.AddListener([&](auto title_id, const auto& game_title) {
|
||||
if (cvars::discord) {
|
||||
discord::DiscordPresence::PlayingTitle(
|
||||
game_title.empty() ? L"Unknown Title" : game_title);
|
||||
}
|
||||
emulator_window->UpdateTitle();
|
||||
evt->Set();
|
||||
});
|
||||
|
||||
emulator->on_terminate.AddListener([&]() {
|
||||
if (cvars::discord) {
|
||||
discord::DiscordPresence::NotPlaying();
|
||||
}
|
||||
});
|
||||
|
||||
emulator_window->window()->on_closing.AddListener([&](ui::UIEvent* e) {
|
||||
// This needs to shut down before the graphics context.
|
||||
Profiler::Shutdown();
|
||||
|
@ -271,6 +289,10 @@ int xenia_main(const std::vector<std::wstring>& args) {
|
|||
exiting = true;
|
||||
evt->Set();
|
||||
|
||||
if (cvars::discord) {
|
||||
discord::DiscordPresence::Shutdown();
|
||||
}
|
||||
|
||||
// TODO(DrChat): Remove this code and do a proper exit.
|
||||
XELOGI("Cheap-skate exit!");
|
||||
exit(0);
|
||||
|
@ -318,6 +340,10 @@ int xenia_main(const std::vector<std::wstring>& args) {
|
|||
debug_window.reset();
|
||||
emulator.reset();
|
||||
|
||||
if (cvars::discord) {
|
||||
discord::DiscordPresence::Shutdown();
|
||||
}
|
||||
|
||||
Profiler::Dump();
|
||||
Profiler::Shutdown();
|
||||
emulator_window.reset();
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace xe {
|
|||
Emulator::Emulator(const std::wstring& command_line,
|
||||
const std::wstring& content_root)
|
||||
: on_launch(),
|
||||
on_terminate(),
|
||||
on_exit(),
|
||||
command_line_(command_line),
|
||||
content_root_(content_root),
|
||||
|
@ -233,6 +234,7 @@ X_STATUS Emulator::TerminateTitle() {
|
|||
kernel_state_->TerminateTitle();
|
||||
title_id_ = 0;
|
||||
game_title_ = L"";
|
||||
on_terminate();
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -671,7 +673,7 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
|
|||
}
|
||||
|
||||
main_thread_ = main_thread;
|
||||
on_launch();
|
||||
on_launch(title_id_, game_title_);
|
||||
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -145,7 +145,8 @@ class Emulator {
|
|||
void WaitUntilExit();
|
||||
|
||||
public:
|
||||
xe::Delegate<> on_launch;
|
||||
xe::Delegate<uint32_t, const std::wstring&> on_launch;
|
||||
xe::Delegate<> on_terminate;
|
||||
xe::Delegate<> on_exit;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue