Compare commits

..

1 commit

Author SHA1 Message Date
MutantAura 618734dd78
Merge 55b8cf6e3c into 7124d679fd 2024-03-30 17:42:22 +00:00

View file

@ -1,7 +1,6 @@
using DiscordRPC;
using Ryujinx.Common;
using Ryujinx.UI.Common.Configuration;
using System.Text;
namespace Ryujinx.UI.Common
{
@ -10,7 +9,7 @@ namespace Ryujinx.UI.Common
private const string Description = "A simple, experimental Nintendo Switch emulator.";
private const string ApplicationId = "1216775165866807456";
private const int TitleByteLimit = 128;
private const int TitleCharLimit = 128;
private static DiscordRpcClient _discordClient;
private static RichPresence _discordPresenceMain;
@ -65,16 +64,20 @@ namespace Ryujinx.UI.Common
public static void SwitchToPlayingState(string titleId, string titleName)
{
// LargeImageText and Details must be 128 characters or less.
titleName = titleName.Length > TitleCharLimit ? titleName[..TitleCharLimit] : titleName;
string details = titleName.Length > TitleCharLimit - 8 ? titleName[..(TitleCharLimit - 8)] : titleName;
_discordClient?.SetPresence(new RichPresence
{
Assets = new Assets
{
LargeImageKey = "game",
LargeImageText = TruncateToByteLength(titleName, TitleByteLimit),
LargeImageText = titleName,
SmallImageKey = "ryujinx",
SmallImageText = Description,
},
Details = TruncateToByteLength($"Playing {titleName}", TitleByteLimit),
Details = $"Playing {details}",
State = (titleId == "0000000000000000") ? "Homebrew" : titleId.ToUpper(),
Timestamps = Timestamps.Now,
Buttons =
@ -93,27 +96,6 @@ namespace Ryujinx.UI.Common
_discordClient?.SetPresence(_discordPresenceMain);
}
private static string TruncateToByteLength(string input, int byteLimit)
{
if (Encoding.UTF8.GetByteCount(input) <= byteLimit)
{
return input;
}
string trimmed = input;
while (Encoding.UTF8.GetByteCount(trimmed) > byteLimit)
{
// Remove one character from the end of the string at a time.
trimmed = trimmed[..^1];
}
// Remove another 3 characters to make sure we have room for "…".
trimmed = trimmed[..^3].TrimEnd() + "…";
return trimmed;
}
public static void Exit()
{
_discordClient?.Dispose();