discord_impl.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-FileCopyrightText: 2018 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <chrono>
  4. #include <string>
  5. #include <discord_rpc.h>
  6. #include "common/common_types.h"
  7. #include "core/core.h"
  8. #include "core/loader/loader.h"
  9. #include "yuzu/discord_impl.h"
  10. #include "yuzu/uisettings.h"
  11. namespace DiscordRPC {
  12. DiscordImpl::DiscordImpl(Core::System& system_) : system{system_} {
  13. DiscordEventHandlers handlers{};
  14. // The number is the client ID for yuzu, it's used for images and the
  15. // application name
  16. Discord_Initialize("712465656758665259", &handlers, 1, nullptr);
  17. }
  18. DiscordImpl::~DiscordImpl() {
  19. Discord_ClearPresence();
  20. Discord_Shutdown();
  21. }
  22. void DiscordImpl::Pause() {
  23. Discord_ClearPresence();
  24. }
  25. void DiscordImpl::Update() {
  26. s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(
  27. std::chrono::system_clock::now().time_since_epoch())
  28. .count();
  29. std::string title;
  30. if (system.IsPoweredOn()) {
  31. system.GetAppLoader().ReadTitle(title);
  32. }
  33. DiscordRichPresence presence{};
  34. presence.largeImageKey = "yuzu_logo";
  35. presence.largeImageText = "yuzu is an emulator for the Nintendo Switch";
  36. if (system.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