mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-07-02 23:49:29 +00:00
Merge a1646ff551
into 7124d679fd
This commit is contained in:
commit
e96b73554c
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue