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