7
7
******************************************************************************
8
8
*/
9
9
10
+ #include " xenia/app/discord/discord_presence.h"
10
11
#include " xenia/app/emulator_window.h"
11
12
#include " xenia/base/cvar.h"
12
13
#include " xenia/base/debugging.h"
@@ -56,6 +57,8 @@ DEFINE_bool(mount_cache, false, "Enable cache mount", "General");
56
57
CmdVar (target, " " , " Specifies the target .xex or .iso to execute." );
57
58
DECLARE_bool (debug);
58
59
60
+ DEFINE_bool (discord, true , " Enable Discord rich presence" , " General" );
61
+
59
62
namespace xe {
60
63
namespace app {
61
64
@@ -145,6 +148,11 @@ int xenia_main(const std::vector<std::wstring>& args) {
145
148
Profiler::Initialize ();
146
149
Profiler::ThreadEnter (" main" );
147
150
151
+ if (cvars::discord) {
152
+ discord::DiscordPresence::Initialize ();
153
+ discord::DiscordPresence::NotPlaying ();
154
+ }
155
+
148
156
// Figure out where content should go.
149
157
std::wstring content_root = xe::to_wstring (cvars::content_root);
150
158
std::wstring config_folder;
@@ -256,11 +264,21 @@ int xenia_main(const std::vector<std::wstring>& args) {
256
264
}
257
265
258
266
auto evt = xe::threading::Event::CreateAutoResetEvent (false );
259
- emulator->on_launch .AddListener ([&]() {
267
+ emulator->on_launch .AddListener ([&](auto title_id, const auto & game_title) {
268
+ if (cvars::discord) {
269
+ discord::DiscordPresence::PlayingTitle (
270
+ game_title.empty () ? L" Unknown Title" : game_title);
271
+ }
260
272
emulator_window->UpdateTitle ();
261
273
evt->Set ();
262
274
});
263
275
276
+ emulator->on_terminate .AddListener ([&]() {
277
+ if (cvars::discord) {
278
+ discord::DiscordPresence::NotPlaying ();
279
+ }
280
+ });
281
+
264
282
emulator_window->window ()->on_closing .AddListener ([&](ui::UIEvent* e) {
265
283
// This needs to shut down before the graphics context.
266
284
Profiler::Shutdown ();
@@ -271,6 +289,10 @@ int xenia_main(const std::vector<std::wstring>& args) {
271
289
exiting = true ;
272
290
evt->Set ();
273
291
292
+ if (cvars::discord) {
293
+ discord::DiscordPresence::Shutdown ();
294
+ }
295
+
274
296
// TODO(DrChat): Remove this code and do a proper exit.
275
297
XELOGI (" Cheap-skate exit!" );
276
298
exit (0 );
@@ -318,6 +340,10 @@ int xenia_main(const std::vector<std::wstring>& args) {
318
340
debug_window.reset ();
319
341
emulator.reset ();
320
342
343
+ if (cvars::discord) {
344
+ discord::DiscordPresence::Shutdown ();
345
+ }
346
+
321
347
Profiler::Dump ();
322
348
Profiler::Shutdown ();
323
349
emulator_window.reset ();
0 commit comments