Skip to content

Commit d6283e0

Browse files
CopilotYBTopaz8
andcommitted
Add Windows notifications and smart same-context detection
Co-authored-by: YBTopaz8 <41630728+YBTopaz8@users.noreply.github.com>
1 parent 40982a8 commit d6283e0

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

Dimmer/Dimmer.WinUI/Views/WinuiPages/AllSongsListPage.xaml.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,18 @@ protected override void OnNavigatedTo(Microsoft.UI.Xaml.Navigation.NavigationEve
531531

532532
MyViewModel.CurrentWinUIPage = this;
533533
MyViewModel.MySongsTableView = MySongsTableView;
534+
535+
// Subscribe to playback feedback events
536+
MyViewModel.OnSongAddedToQueue += (sender, message) =>
537+
{
538+
ShowNotification(message, Microsoft.UI.Xaml.Controls.InfoBarSeverity.Success);
539+
};
540+
541+
MyViewModel.OnSongPlayingNow += (sender, message) =>
542+
{
543+
ShowNotification(message, Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational);
544+
};
545+
534546
// Now that the ViewModel is set, you can set the DataContext.
535547
this.DataContext = MyViewModel;
536548
}
@@ -1383,4 +1395,39 @@ private void SelectedSongImg_Loaded(object sender, RoutedEventArgs e)
13831395
if(!string.IsNullOrEmpty(MyViewModel.SelectedSong.CoverImagePath))
13841396
SelectedSongImg.Source = new BitmapImage(new Uri(MyViewModel.SelectedSong.CoverImagePath));
13851397
}
1398+
1399+
private void ShowNotification(string message, Microsoft.UI.Xaml.Controls.InfoBarSeverity severity)
1400+
{
1401+
// Use a TeachingTip or create a temporary InfoBar for notifications
1402+
// For now, we'll use a simple ContentDialog approach or you can add an InfoBar to the XAML
1403+
DispatcherQueue.TryEnqueue(() =>
1404+
{
1405+
var infoBar = new Microsoft.UI.Xaml.Controls.InfoBar
1406+
{
1407+
Message = message,
1408+
Severity = severity,
1409+
IsOpen = true,
1410+
Margin = new Microsoft.UI.Xaml.Thickness(0, 0, 0, 10)
1411+
};
1412+
1413+
// Auto-close after 3 seconds
1414+
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3) };
1415+
timer.Tick += (s, args) =>
1416+
{
1417+
infoBar.IsOpen = false;
1418+
timer.Stop();
1419+
// Remove from visual tree after closing animation
1420+
var parentPanel = infoBar.Parent as Panel;
1421+
parentPanel?.Children.Remove(infoBar);
1422+
};
1423+
1424+
// Add to the page's main grid (assuming there's a Grid named MyPageGrid)
1425+
if (MyPageGrid is Grid grid && grid.Children.Count > 0)
1426+
{
1427+
// Insert at the top of the grid
1428+
grid.Children.Insert(0, infoBar);
1429+
timer.Start();
1430+
}
1431+
});
1432+
}
13861433
}

Dimmer/Dimmer/ViewModel/BaseViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3841,9 +3841,20 @@ public async Task PlaySongWithActionAsync(
38413841
/// <summary>
38423842
/// Adds a song to play immediately after the current song without interrupting playback.
38433843
/// If nothing is playing, starts playback with the song's context.
3844+
/// If the song is already in the queue, jumps to it instead.
38443845
/// </summary>
38453846
private async Task PlaySongNextAsync(SongModelView songToPlay)
38463847
{
3848+
// Check if the song is already in the current queue
3849+
int existingIndex = _playbackQueue.ToList().FindIndex(s => s.Id == songToPlay.Id);
3850+
if (existingIndex != -1 && _playbackQueue.Count > 0)
3851+
{
3852+
// Song is already in queue, jump to it instead of adding again
3853+
_logger.LogInformation("Song '{Title}' already in queue, jumping to position {Index}", songToPlay.Title, existingIndex);
3854+
await JumpToSongInQueueAsync(songToPlay);
3855+
return;
3856+
}
3857+
38473858
// Check if playback is active
38483859
if (!_audioService.IsPlaying || _playbackQueue.Count == 0)
38493860
{

0 commit comments

Comments
 (0)