Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Screenbox.Core/Models/LivelyWallpaperModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public record LivelyWallpaperModel
public bool IsAudio { get; set; }
public bool IsPauseNotify { get; set; }
public Uri AuthorUrl { get; set; }

public override string ToString()
{
return Model.Author != null ? $"{Model.Title}; {Model.Author}" : $"{Model.Title}";
Copy link
Preview

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference exception if Model.Title is null. The method should handle the case where Model.Title might be null to prevent runtime exceptions.

Suggested change
return Model.Author != null ? $"{Model.Title}; {Model.Author}" : $"{Model.Title}";
var title = Model?.Title ?? string.Empty;
var author = Model?.Author;
return !string.IsNullOrEmpty(author) ? $"{title}; {author}" : $"{title}";

Copilot uses AI. Check for mistakes.

}
}
2 changes: 2 additions & 0 deletions Screenbox/Controls/MediaListViewItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
Grid.Column="3"
Margin="2,0"
Padding="{StaticResource HyperlinkButtonUniformPadding}"
contract14Present:AutomationProperties.AutomationControlType="Button"
Command="{x:Bind Common.OpenArtistCommand}"
CommandParameter="{Binding MainArtist, FallbackValue={x:Null}}"
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
Expand All @@ -122,6 +123,7 @@
Grid.Column="4"
Margin="2,0"
Padding="{StaticResource HyperlinkButtonUniformPadding}"
contract14Present:AutomationProperties.AutomationControlType="Button"
Command="{x:Bind Common.OpenAlbumCommand}"
CommandParameter="{Binding Album}"
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
Expand Down
26 changes: 21 additions & 5 deletions Screenbox/Controls/MediaListViewItem.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#nullable enable

using System;
using System.Windows.Input;
using CommunityToolkit.Mvvm.DependencyInjection;
using Screenbox.Core.Enums;
using Screenbox.Core.ViewModels;
using System;
using System.Windows.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Controls;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace Screenbox.Controls;

public sealed partial class MediaListViewItem : UserControl
{
public static readonly DependencyProperty PlayCommandProperty = DependencyProperty.Register(
Expand Down Expand Up @@ -42,16 +44,30 @@ public MediaListViewItem()
private GridLength BoolToGridLength(bool visibility) =>
visibility ? new GridLength(1, GridUnitType.Star) : new GridLength(0);

private void UpdatePlayButtonsAutomationName(bool isPlaying)
{
var media = DataContext as MediaViewModel;
string playPauseText = isPlaying ? Strings.Resources.Pause : Strings.Resources.Play;

AutomationProperties.SetName(PlayButton, $"{playPauseText} {media?.Name}");
Copy link
Preview

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference exception if media?.Name is null. The string interpolation will display an empty string, but it would be clearer to provide a fallback value or guard against null media names.

Suggested change
AutomationProperties.SetName(PlayButton, $"{playPauseText} {media?.Name}");
AutomationProperties.SetName(PlayButton, $"{playPauseText} {(string.IsNullOrEmpty(media?.Name) ? Strings.Resources.Unknown : media.Name)}");

Copilot uses AI. Check for mistakes.

}

private void OnDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
{
_firstPlay = true;
AdaptiveLayoutBehavior.Override =
(DataContext as MediaViewModel)?.MediaType != MediaPlaybackType.Music ? 0 : -1;
var media = DataContext as MediaViewModel;
AdaptiveLayoutBehavior.Override = media?.MediaType != MediaPlaybackType.Music ? 0 : -1;

UpdatePlayButtonsAutomationName(media?.IsPlaying ?? false);
AutomationProperties.SetName(ArtistButton, $"{Strings.Resources.Artist}: {media?.MainArtist?.Name}");
AutomationProperties.SetName(AlbumButton, $"{Strings.Resources.Albums}: {media?.Album?.Name}");
Comment on lines +62 to +63
Copy link
Preview

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If media?.MainArtist?.Name or media?.Album?.Name are null, the automation names will end with ': ' followed by empty text. Consider providing fallback text or checking for null values before setting the automation properties.

Suggested change
AutomationProperties.SetName(ArtistButton, $"{Strings.Resources.Artist}: {media?.MainArtist?.Name}");
AutomationProperties.SetName(AlbumButton, $"{Strings.Resources.Albums}: {media?.Album?.Name}");
var artistName = string.IsNullOrWhiteSpace(media?.MainArtist?.Name) ? Strings.Resources.UnknownArtist : media.MainArtist.Name;
var albumName = string.IsNullOrWhiteSpace(media?.Album?.Name) ? Strings.Resources.UnknownAlbum : media.Album.Name;
AutomationProperties.SetName(ArtistButton, $"{Strings.Resources.Artist}: {artistName}");
AutomationProperties.SetName(AlbumButton, $"{Strings.Resources.Albums}: {albumName}");

Copilot uses AI. Check for mistakes.

}

private async void PlayingStatesOnCurrentStateChanged(object sender, VisualStateChangedEventArgs e)
{
if (_firstPlay && e.NewState?.Name == nameof(Playing))
bool isPlaying = e.NewState?.Name == nameof(Playing);
UpdatePlayButtonsAutomationName(isPlaying); // TODO: Use MediaViewModel PropertyChanged (IsPlaying) event.
if (_firstPlay && isPlaying)
{
_firstPlay = false;
await PlayingIndicator.PlayAsync(0, 1, true);
Expand Down
2 changes: 1 addition & 1 deletion Screenbox/Pages/AlbumsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
Margin="{StaticResource ContentPagePadding}"
HorizontalAlignment="Right"
AccessKey="{strings:KeyboardResources Key=CommandSortByKey}"
AutomationProperties.Name="{x:Bind SortByText.Text}"
AutomationProperties.Name="{x:Bind GetSortByButtonAutomationName(ViewModel.SortBy), Mode=OneWay}"
Background="Transparent"
BorderBrush="Transparent">
<muxc:DropDownButton.Flyout>
Expand Down
6 changes: 6 additions & 0 deletions Screenbox/Pages/AlbumsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ private string GetSortByText(string tag)
return (item as MenuFlyoutItem)?.Text ?? string.Empty;
}

private string GetSortByButtonAutomationName(string value)
{
var optionText = GetSortByText(value);
return Strings.Resources.SortByAutomationName(optionText);
}

private void UpdateSortByFlyout()
{
if ((SortByFlyout.Items?.FirstOrDefault(x => x.Tag as string == ViewModel.SortBy) ??
Expand Down
2 changes: 1 addition & 1 deletion Screenbox/Pages/SongsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
Margin="{StaticResource ContentPagePadding}"
HorizontalAlignment="Right"
AccessKey="{strings:KeyboardResources Key=CommandSortByKey}"
AutomationProperties.Name="{x:Bind SortByText.Text}"
AutomationProperties.Name="{x:Bind GetSortByButtonAutomationName(ViewModel.SortBy), Mode=OneWay}"
Background="Transparent"
BorderBrush="Transparent">
<muxc:DropDownButton.Flyout>
Expand Down
6 changes: 6 additions & 0 deletions Screenbox/Pages/SongsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ private string GetSortByText(string tag)
return (item as MenuFlyoutItem)?.Text ?? string.Empty;
}

private string GetSortByButtonAutomationName(string value)
{
var optionText = GetSortByText(value);
return Strings.Resources.SortByAutomationName(optionText);
}

private void UpdateSortByFlyout()
{
if ((SortByFlyout.Items?.FirstOrDefault(x => x.Tag as string == ViewModel.SortBy) ??
Expand Down
4 changes: 4 additions & 0 deletions Screenbox/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@
<data name="SortBy" xml:space="preserve">
<value>Sort by</value>
</data>
<data name="SortByAutomationName" xml:space="preserve">
<value>Sort by {0} option selected</value>
<comment>#Format[String sortBy]</comment>
</data>
<data name="Artist" xml:space="preserve">
<value>Artist</value>
</data>
Expand Down
Loading