Skip to content

Commit 5722e33

Browse files
committed
Add playback format logos
like Dolby and Lossless
1 parent 802eab9 commit 5722e33

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

AMDiscordRPC/AMDiscordRPC.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ static void AMEvent()
4444
var playingStatus = false;
4545
AutomationElement parent = null;
4646
AutomationElement[] listeningInfo = null;
47+
AutomationElement LCDInf = null;
48+
AutomationElement audioBadge = null;
4749
AutomationElement playButton = null;
4850
AutomationElement slider = null;
4951

@@ -81,8 +83,9 @@ static void AMEvent()
8183
}
8284
parent = window.FindFirstChild(cf => cf.ByClassName("Microsoft.UI.Content.DesktopChildSiteBridge")).FindFirstChild().FindFirstChild().FindFirstChild(cf => cf.ByAutomationId("TransportBar"));
8385
playButton = parent.FindFirstChild(cf => cf.ByAutomationId("TransportControl_PlayPauseStop"));
84-
listeningInfo = parent.FindFirstChild(cf => cf.ByAutomationId("LCD")).FindAllChildren().Where(x => (x.ControlType == ControlType.Pane)).ToArray();
85-
slider = parent.FindFirstChild(cf => cf.ByAutomationId("LCD")).FindFirstChild(cf => cf.ByAutomationId("LCDScrubber"));
86+
LCDInf = parent.FindFirstChild(cf => cf.ByAutomationId("LCD"));
87+
listeningInfo = LCDInf.FindAllChildren().Where(x => (x.ControlType == ControlType.Pane)).ToArray();
88+
slider = LCDInf.FindFirstChild(cf => cf.ByAutomationId("LCDScrubber"));
8689
if (slider == null) throw new FieldAccessException("Slider not found");
8790
playingStatus = true;
8891
}
@@ -109,6 +112,7 @@ static void AMEvent()
109112
{
110113
string previousSong = string.Empty;
111114
string previousArtistAlbum = string.Empty;
115+
int audioStatus = 3;
112116
bool resetStatus = false;
113117
double oldValue = 0;
114118

@@ -126,6 +130,7 @@ static void AMEvent()
126130
DateTime startTime = currentTime.Subtract(TimeSpan.FromSeconds(slider.AsSlider().Value + 1));
127131
DateTime endTime = currentTime.AddSeconds(slider.AsSlider().Maximum).Subtract(TimeSpan.FromSeconds(slider.AsSlider().Value + 1));
128132
bool isSingle = dashSplit[dashSplit.Length - 1].Contains("Single");
133+
audioBadge = LCDInf.FindFirstChild(cf => cf.ByAutomationId("AudioBadgeButton"));
129134

130135
if (!playButton.IsEnabled && playButton?.Name != null && localizedPlay == null)
131136
{
@@ -153,8 +158,24 @@ static void AMEvent()
153158
// sometimes discord doesn't register rich presence idk why i tried everything...
154159
previousArtistAlbum = currentArtistAlbum;
155160
previousSong = currentSong;
161+
if (audioBadge != null)
162+
{
163+
switch (audioBadge?.Name)
164+
{
165+
case "Lossless":
166+
audioStatus = 0;
167+
break;
168+
case "Dolby Atmos":
169+
audioStatus = 1;
170+
break;
171+
default:
172+
audioStatus = 3;
173+
break;
174+
}
175+
}
176+
else audioStatus = 3;
156177
oldValue = 0;
157-
AMSongDataEvent.SongChange(new SongData(currentSong, (isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : currentArtistAlbum, currentArtistAlbum.Split('—').Length <= 1, startTime, endTime));
178+
AMSongDataEvent.SongChange(new SongData(currentSong, (isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : currentArtistAlbum, currentArtistAlbum.Split('—').Length <= 1, startTime, endTime, audioStatus));
158179
}
159180

160181
if (playButton?.Name != null && (localizedPlay != null && localizedPlay == playButton?.Name || localizedStop != null && localizedStop != playButton?.Name))

AMDiscordRPC/Discord.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public static void SetPresence(SongData x, string[] resp)
7070
{
7171
LargeImageKey = (resp.Length > 0) ? resp[0] : "",
7272
LargeImageText = (x.isMV) ? resp[2] : ConvertToValidString(x.ArtistandAlbumName.Split('—')[1]),
73+
SmallImageKey = (x.audioDetail == 0) ? "lossless" : (x.audioDetail == 1) ? "dolbysimplified" : null,
74+
SmallImageText = (x.audioDetail == 0) ? "Lossless" : (x.audioDetail == 1) ? "Dolby Atmos" : null,
7375
},
7476
Buttons = new Button[]
7577
{

AMDiscordRPC/Globals.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ public class SongData : EventArgs
5858
public bool isMV { get; set;}
5959
public DateTime startTime { get; set; }
6060
public DateTime endTime { get; set; }
61+
public int audioDetail { get; set; }
6162

62-
public SongData(string songName, string artistandAlbumName, bool isMVl, DateTime startTime, DateTime endTime)
63+
public SongData(string songName, string artistandAlbumName, bool isMVl, DateTime startTime, DateTime endTime, int audioDetail)
6364
{
6465
SongName = songName;
6566
ArtistandAlbumName = artistandAlbumName;
6667
isMV = isMVl;
6768
this.startTime = startTime;
6869
this.endTime = endTime;
70+
this.audioDetail = audioDetail;
6971
}
7072
}
7173
}

0 commit comments

Comments
 (0)