This commit is contained in:
MutantAura 2024-03-30 22:47:31 +00:00 committed by GitHub
commit e96b73554c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
using DiscordRPC;
using Ryujinx.Common;
using Ryujinx.UI.Common.Configuration;
using System.Text;
namespace Ryujinx.UI.Common
{
@ -9,6 +10,8 @@ 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 static DiscordRpcClient _discordClient;
private static RichPresence _discordPresenceMain;
@ -67,11 +70,11 @@ namespace Ryujinx.UI.Common
Assets = new Assets
{
LargeImageKey = "game",
LargeImageText = titleName,
LargeImageText = TruncateToByteLength(titleName, TitleByteLimit),
SmallImageKey = "ryujinx",
SmallImageText = Description,
},
Details = $"Playing {titleName}",
Details = TruncateToByteLength($"Playing {titleName}", TitleByteLimit),
State = (titleId == "0000000000000000") ? "Homebrew" : titleId.ToUpper(),
Timestamps = Timestamps.Now,
Buttons =
@ -90,6 +93,27 @@ 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();