Skip to content

Commit

Permalink
UI: RPC: show game version when hovering large image asset.
Browse files Browse the repository at this point in the history
  • Loading branch information
GreemDev committed Oct 12, 2024
1 parent 5b6e352 commit 4d311df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
18 changes: 11 additions & 7 deletions src/Ryujinx.UI.Common/DiscordIntegrationModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using DiscordRPC;
using Humanizer;
using LibHac.Bcat;
using Ryujinx.Common;
using Ryujinx.HLE.Loaders.Processes;
using Ryujinx.UI.App.Common;
using Ryujinx.UI.Common.Configuration;
using System.Collections.Generic;
Expand All @@ -13,7 +15,7 @@ public static class DiscordIntegrationModule
{
public static Timestamps StartedAt { get; set; }

private const string Description = "A simple, experimental Nintendo Switch emulator.";
private static readonly string _description = $"{ReleaseInformation.ReleaseChannelOwner}/{ReleaseInformation.ReleaseChannelRepo} {ReleaseInformation.Version}";
private const string ApplicationId = "1293250299716173864";

private const int ApplicationByteLimit = 128;
Expand All @@ -29,7 +31,7 @@ public static void Initialize()
Assets = new Assets
{
LargeImageKey = "ryujinx",
LargeImageText = Description
LargeImageText = TruncateToByteLength(_description)
},
Details = "Main Menu",
State = "Idling",
Expand Down Expand Up @@ -62,19 +64,21 @@ private static void Update(object sender, ReactiveEventArgs<bool> evnt)
}
}

public static void SwitchToPlayingState(string titleId, ApplicationMetadata appMeta)
public static void SwitchToPlayingState(ApplicationMetadata appMeta, ProcessResult procRes)
{
_discordClient?.SetPresence(new RichPresence
{
Assets = new Assets
{
LargeImageKey = _discordGameAssets.Contains(titleId.ToLower()) ? titleId : "game",
LargeImageText = TruncateToByteLength(appMeta.Title),
LargeImageKey = _discordGameAssets.Contains(procRes.ProgramIdText.ToLower()) ? procRes.ProgramIdText : "game",
LargeImageText = TruncateToByteLength($"{appMeta.Title} | {procRes.DisplayVersion}"),
SmallImageKey = "ryujinx",
SmallImageText = Description
SmallImageText = TruncateToByteLength(_description)
},
Details = TruncateToByteLength($"Playing {appMeta.Title}"),
State = $"Total play time: {appMeta.TimePlayed.Humanize(2, false)}",
State = appMeta.LastPlayed.HasValue
? $"Total play time: {appMeta.TimePlayed.Humanize(2, false)}"
: "Never played",
Timestamps = Timestamps.Now
});
}
Expand Down
9 changes: 4 additions & 5 deletions src/Ryujinx/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,12 +785,11 @@ await ContentDialogHelper.CreateInfoDialog(
return false;
}

ApplicationMetadata appMeta = ApplicationLibrary.LoadAndSaveMetaData(Device.Processes.ActiveApplication.ProgramIdText, appMetadata =>
{
appMetadata.UpdatePreGame();
});
ApplicationMetadata appMeta = ApplicationLibrary.LoadAndSaveMetaData(Device.Processes.ActiveApplication.ProgramIdText,
appMetadata => appMetadata.UpdatePreGame()
);

DiscordIntegrationModule.SwitchToPlayingState(Device.Processes.ActiveApplication.ProgramIdText, appMeta);
DiscordIntegrationModule.SwitchToPlayingState(appMeta, Device.Processes.ActiveApplication);

return true;
}
Expand Down

0 comments on commit 4d311df

Please sign in to comment.