discord_impl.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2018 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <chrono>
  5. #include <string>
  6. #include <discord_rpc.h>
  7. #include "common/common_types.h"
  8. #include "core/core.h"
  9. #include "core/loader/loader.h"
  10. #include "yuzu/discord_impl.h"
  11. #include "yuzu/ui_settings.h"
  12. namespace DiscordRPC {
  13. DiscordImpl::DiscordImpl() {
  14. DiscordEventHandlers handlers{};
  15. // The number is the client ID for yuzu, it's used for images and the
  16. // application name
  17. Discord_Initialize("471872241299226636", &handlers, 1, nullptr);
  18. }
  19. DiscordImpl::~DiscordImpl() {
  20. Discord_ClearPresence();
  21. Discord_Shutdown();
  22. }
  23. void DiscordImpl::Pause() {
  24. Discord_ClearPresence();
  25. }
  26. void DiscordImpl::Update() {
  27. s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(
  28. std::chrono::system_clock::now().time_since_epoch())
  29. .count();
  30. std::string title;
  31. if (Core::System::GetInstance().IsPoweredOn())
  32. Core::System::GetInstance().GetAppLoader().ReadTitle(title);
  33. DiscordRichPresence presence{};
  34. presence.largeImageKey = "yuzu_logo";
  35. presence.largeImageText = "yuzu is an emulator for the Nintendo Switch";
  36. if (Core::System::GetInstance().IsPoweredOn()) {
  37. presence.state = title.c_str();
  38. presence.details = "Currently in game";
  39. } else {
  40. presence.details = "Not in game";
  41. }
  42. presence.startTimestamp = start_time;
  43. Discord_UpdatePresence(&presence);
  44. }
  45. } // namespace DiscordRPC