Toas will not show No title or artist flags

This commit is contained in:
minster586
2026-09-04 23:44:06 -04:00
parent 7b67c03270
commit 75a378e948
+67 -45
View File
@@ -25,6 +25,8 @@ namespace RadioDJViewer
{ {
private string _currentTrackKey = string.Empty; private string _currentTrackKey = string.Empty;
private string _playbackTrackKey = string.Empty; private string _playbackTrackKey = string.Empty;
private string _previousToastTitle = string.Empty;
private string _previousToastArtist = string.Empty;
private double _playbackElapsedSeconds = 0; private double _playbackElapsedSeconds = 0;
private double _playbackDurationSeconds = 0; private double _playbackDurationSeconds = 0;
private bool _playbackPaused = true; private bool _playbackPaused = true;
@@ -293,38 +295,6 @@ namespace RadioDJViewer
var xml = await response.Content.ReadAsStringAsync(); var xml = await response.Content.ReadAsStringAsync();
lastApiXml = xml; lastApiXml = xml;
ParseAndDisplaySongInfo(xml); ParseAndDisplaySongInfo(xml);
try
{
var newKey = $"{marqueeTextArtist}|{marqueeTextTitle}";
if (!string.Equals(newKey, _currentTrackKey, StringComparison.Ordinal))
{
_currentTrackKey = newKey;
ShowTemporaryStatus("Song Change Detected", 2000);
bool toastEnabled = IsToastEnabledForActiveProfile();
#if DEBUG
System.Diagnostics.Debug.WriteLine($"[Toast] Track changed. Enabled={toastEnabled}, Profile={loadedProfile?.Name ?? "(null)"}");
#endif
if (toastEnabled)
{
try
{
string outputImagePath = GetProfileOutputImagePath();
#if DEBUG
System.Diagnostics.Debug.WriteLine($"[Toast] Trigger with title='{marqueeTextTitle}', artist='{marqueeTextArtist}', imagePath='{outputImagePath}'");
#endif
ShowTrackChangeToast(marqueeTextTitle, marqueeTextArtist, outputImagePath);
}
catch (Exception ex)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine($"[Toast] Trigger error: {ex}");
MessageBox.Show($"Toast trigger failed: {ex.Message}", "Toast Debug", MessageBoxButtons.OK, MessageBoxIcon.Warning);
#endif
}
}
}
}
catch { }
} }
} }
catch { } catch { }
@@ -700,6 +670,8 @@ namespace RadioDJViewer
{ {
UpdateCurrentSongImage(null); UpdateCurrentSongImage(null);
} }
HandleToastForTrackChange(title, artist);
} }
catch catch
{ {
@@ -1009,6 +981,67 @@ namespace RadioDJViewer
return loadedProfile != null && loadedProfile.ToastNotificationsEnabled; return loadedProfile != null && loadedProfile.ToastNotificationsEnabled;
} }
private void HandleToastForTrackChange(string title, string artist)
{
string normalizedTitle = NormalizeTrackMetadata(title);
string normalizedArtist = NormalizeTrackMetadata(artist);
if (string.Equals(normalizedTitle, _previousToastTitle, StringComparison.OrdinalIgnoreCase) &&
string.Equals(normalizedArtist, _previousToastArtist, StringComparison.OrdinalIgnoreCase))
{
return;
}
_previousToastTitle = normalizedTitle;
_previousToastArtist = normalizedArtist;
if (!IsToastEnabledForActiveProfile())
return;
if (!HasValidTrackMetadata(normalizedTitle, normalizedArtist))
return;
try
{
string outputImagePath = GetProfileOutputImagePath();
#if DEBUG
System.Diagnostics.Debug.WriteLine($"[Toast] Track change accepted. title='{normalizedTitle}', artist='{normalizedArtist}', imagePath='{outputImagePath}'");
#endif
ShowTrackChangeToast(normalizedTitle, normalizedArtist, outputImagePath);
}
catch (Exception ex)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine($"[Toast] Trigger error: {ex}");
MessageBox.Show($"Toast trigger failed: {ex.Message}", "Toast Debug", MessageBoxButtons.OK, MessageBoxIcon.Warning);
#endif
}
}
private static string NormalizeTrackMetadata(string value)
{
return string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim();
}
private static bool HasValidTrackMetadata(string title, string artist)
{
return IsValidToastValue(title) && IsValidToastValue(artist);
}
private static bool IsValidToastValue(string value)
{
if (string.IsNullOrWhiteSpace(value))
return false;
string normalized = value.Trim();
return !normalized.Equals("No Title", StringComparison.OrdinalIgnoreCase)
&& !normalized.Equals("No Artist", StringComparison.OrdinalIgnoreCase)
&& !normalized.Equals("Unknown", StringComparison.OrdinalIgnoreCase)
&& !normalized.Equals("No title", StringComparison.OrdinalIgnoreCase)
&& !normalized.Equals("No artist", StringComparison.OrdinalIgnoreCase)
&& !normalized.Equals("unknown", StringComparison.OrdinalIgnoreCase);
}
private string GetProfileOutputImagePath() private string GetProfileOutputImagePath()
{ {
if (string.IsNullOrWhiteSpace(outputFolderPath) || string.IsNullOrWhiteSpace(loadedProfile?.OutputImageName)) if (string.IsNullOrWhiteSpace(outputFolderPath) || string.IsNullOrWhiteSpace(loadedProfile?.OutputImageName))
@@ -1017,8 +1050,7 @@ namespace RadioDJViewer
try try
{ {
string imageName = Path.ChangeExtension(loadedProfile.OutputImageName, ".png"); string imageName = Path.ChangeExtension(loadedProfile.OutputImageName, ".png");
string fullPath = Path.GetFullPath(Path.Combine(outputFolderPath, imageName)); return Path.GetFullPath(Path.Combine(outputFolderPath, imageName));
return fullPath;
} }
catch catch
{ {
@@ -1032,17 +1064,7 @@ namespace RadioDJViewer
string safeArtist = string.IsNullOrWhiteSpace(artist) ? "No artist" : artist; string safeArtist = string.IsNullOrWhiteSpace(artist) ? "No artist" : artist;
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
string attribution = $"Date: {now:MM/dd/yyyy} | Time: {now:hh:mm tt}"; string attribution = $"Date: {now:MM/dd/yyyy} | Time: {now:hh:mm tt}";
try ToastNotificationService.ShowTrackChangeToast(safeTitle, safeArtist, attribution, outputImagePath);
{
ToastNotificationService.ShowTrackChangeToast(safeTitle, safeArtist, attribution, outputImagePath);
}
catch (Exception ex)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine($"[Toast] ShowTrackChangeToast failed: {ex}");
MessageBox.Show($"Toast display failed: {ex.Message}", "Toast Debug", MessageBoxButtons.OK, MessageBoxIcon.Warning);
#endif
}
} }
} }