diff --git a/Screenbox.Core/Enums/SettingsOptions.cs b/Screenbox.Core/Enums/SettingsOptions.cs index c9f905afd..00263f0bf 100644 --- a/Screenbox.Core/Enums/SettingsOptions.cs +++ b/Screenbox.Core/Enums/SettingsOptions.cs @@ -20,3 +20,15 @@ public enum ThemeOption Light, Dark } + +public enum LaunchPageOption +{ + Home, + Songs, + Albums, + Artists, + VideoFolders, + AllVideos, + Network, + PlayQueue +} diff --git a/Screenbox.Core/Services/ISettingsService.cs b/Screenbox.Core/Services/ISettingsService.cs index cf456da4e..9c93a6d85 100644 --- a/Screenbox.Core/Services/ISettingsService.cs +++ b/Screenbox.Core/Services/ISettingsService.cs @@ -18,6 +18,7 @@ public interface ISettingsService ThemeOption Theme { get; set; } bool EnqueueAllFilesInFolder { get; set; } bool RestorePlaybackPosition { get; set; } + LaunchPageOption LaunchPage { get; set; } bool SearchRemovableStorage { get; set; } int MaxVolume { get; set; } string GlobalArguments { get; set; } diff --git a/Screenbox.Core/Services/SettingsService.cs b/Screenbox.Core/Services/SettingsService.cs index bfa8c45a6..83b7e6254 100644 --- a/Screenbox.Core/Services/SettingsService.cs +++ b/Screenbox.Core/Services/SettingsService.cs @@ -26,6 +26,7 @@ public sealed class SettingsService : ISettingsService private const string GeneralShowRecent = "General/ShowRecent"; private const string GeneralEnqueueAllInFolder = "General/EnqueueAllInFolder"; private const string GeneralRestorePlaybackPosition = "General/RestorePlaybackPosition"; + private const string GeneralLaunchPage = "General/LaunchPage"; private const string AdvancedModeKey = "Advanced/IsEnabled"; private const string AdvancedVideoUpscaleKey = "Advanced/VideoUpscale"; private const string AdvancedMultipleInstancesKey = "Advanced/MultipleInstances"; @@ -108,6 +109,12 @@ public bool RestorePlaybackPosition set => SetValue(GeneralRestorePlaybackPosition, value); } + public LaunchPageOption LaunchPage + { + get => (LaunchPageOption)GetValue(GeneralLaunchPage); + set => SetValue(GeneralLaunchPage, (int)value); + } + public bool PlayerShowControls { get => GetValue(PlayerShowControlsKey); @@ -174,6 +181,7 @@ public SettingsService() SetDefault(LibrariesUseIndexerKey, true); SetDefault(LibrariesSearchRemovableStorageKey, true); SetDefault(GeneralShowRecent, true); + SetDefault(GeneralLaunchPage, (int)LaunchPageOption.Home); SetDefault(PersistentRepeatModeKey, (int)MediaPlaybackAutoRepeatMode.None); SetDefault(AdvancedModeKey, false); SetDefault(AdvancedVideoUpscaleKey, (int)VideoUpscaleOption.Linear); diff --git a/Screenbox.Core/ViewModels/SettingsPageViewModel.cs b/Screenbox.Core/ViewModels/SettingsPageViewModel.cs index 839bda72f..8d99d1178 100644 --- a/Screenbox.Core/ViewModels/SettingsPageViewModel.cs +++ b/Screenbox.Core/ViewModels/SettingsPageViewModel.cs @@ -35,6 +35,7 @@ public sealed partial class SettingsPageViewModel : ObservableRecipient [ObservableProperty] private int _theme; [ObservableProperty] private bool _enqueueAllFilesInFolder; [ObservableProperty] private bool _restorePlaybackPosition; + [ObservableProperty] private int _launchPage; [ObservableProperty] private bool _searchRemovableStorage; [ObservableProperty] private bool _advancedMode; [ObservableProperty] private int _videoUpscaling; @@ -104,6 +105,7 @@ public SettingsPageViewModel(ISettingsService settingsService, ILibraryService l _theme = ((int)_settingsService.Theme + 2) % 3; _enqueueAllFilesInFolder = _settingsService.EnqueueAllFilesInFolder; _restorePlaybackPosition = _settingsService.RestorePlaybackPosition; + _launchPage = (int)_settingsService.LaunchPage; _searchRemovableStorage = _settingsService.SearchRemovableStorage; _advancedMode = _settingsService.AdvancedMode; _useMultipleInstances = _settingsService.UseMultipleInstances; @@ -211,6 +213,12 @@ partial void OnRestorePlaybackPositionChanged(bool value) Messenger.Send(new SettingsChangedMessage(nameof(RestorePlaybackPosition), typeof(SettingsPageViewModel))); } + partial void OnLaunchPageChanged(int value) + { + _settingsService.LaunchPage = (LaunchPageOption)value; + Messenger.Send(new SettingsChangedMessage(nameof(LaunchPage), typeof(SettingsPageViewModel))); + } + async partial void OnSearchRemovableStorageChanged(bool value) { _settingsService.SearchRemovableStorage = value; diff --git a/Screenbox/Helpers/EnumExtensions.cs b/Screenbox/Helpers/EnumExtensions.cs new file mode 100644 index 000000000..e895979c8 --- /dev/null +++ b/Screenbox/Helpers/EnumExtensions.cs @@ -0,0 +1,36 @@ +using Screenbox.Core.Enums; +using Screenbox.Pages; +using System; + +namespace Screenbox.Helpers; +public static class EnumExtensions +{ + public static string GetNavPageFirstLevel(this LaunchPageOption launchPageOption) + { + return launchPageOption switch + { + LaunchPageOption.Home => "home", + LaunchPageOption.Songs => "music", + LaunchPageOption.Albums => "music", + LaunchPageOption.Artists => "music", + LaunchPageOption.VideoFolders => "videos", + LaunchPageOption.AllVideos => "videos", + LaunchPageOption.Network => "network", + LaunchPageOption.PlayQueue => "queue", + _ => throw new ArgumentOutOfRangeException(nameof(launchPageOption), launchPageOption, null), + }; + } + + public static string GetNavPageSecondLevel(this LaunchPageOption launchPageOption) + { + return launchPageOption switch + { + LaunchPageOption.Songs => "songs", + LaunchPageOption.Albums => "albums", + LaunchPageOption.Artists => "artists", + LaunchPageOption.VideoFolders => "folders", + LaunchPageOption.AllVideos => "all", + _ => throw new ArgumentOutOfRangeException(nameof(launchPageOption), launchPageOption, null), + }; + } +} diff --git a/Screenbox/Pages/MainPage.xaml.cs b/Screenbox/Pages/MainPage.xaml.cs index a8dbae963..95b43ae54 100644 --- a/Screenbox/Pages/MainPage.xaml.cs +++ b/Screenbox/Pages/MainPage.xaml.cs @@ -7,7 +7,9 @@ using System.Numerics; using CommunityToolkit.Mvvm.DependencyInjection; using Screenbox.Core; +using Screenbox.Core.Services; using Screenbox.Core.ViewModels; +using Screenbox.Helpers; using Sentry; using Windows.ApplicationModel.Core; using Windows.ApplicationModel.DataTransfer; @@ -36,6 +38,8 @@ public sealed partial class MainPage : Page, IContentFrame private readonly Dictionary _pages; + private ISettingsService Settings => Ioc.Default.GetRequiredService(); + public MainPage() { InitializeComponent(); @@ -145,7 +149,12 @@ private void MainPage_Loaded(object sender, RoutedEventArgs e) if (!ViewModel.PlayerVisible) { SetTitleBar(); - NavView.SelectedItem = NavView.MenuItems[0]; + var launchPage = Settings.LaunchPage; + var launchPageTag = launchPage.GetNavPageFirstLevel(); + var navItem = NavView.MenuItems + .OfType() + .FirstOrDefault(item => item.Tag?.ToString() == launchPageTag); + NavView.SelectedItem = navItem ?? NavView.MenuItems[0]; _ = ViewModel.FetchLibraries(); } } diff --git a/Screenbox/Pages/MusicPage.xaml.cs b/Screenbox/Pages/MusicPage.xaml.cs index c33292a92..c8b6a2bee 100644 --- a/Screenbox/Pages/MusicPage.xaml.cs +++ b/Screenbox/Pages/MusicPage.xaml.cs @@ -1,16 +1,19 @@ #nullable enable -using CommunityToolkit.Mvvm.DependencyInjection; -using Screenbox.Core; -using Screenbox.Core.ViewModels; using System; using System.Collections.Generic; using System.Linq; +using CommunityToolkit.Mvvm.DependencyInjection; +using Screenbox.Core; +using Screenbox.Core.Services; +using Screenbox.Core.ViewModels; +using Screenbox.Helpers; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; using Windows.UI.Xaml.Navigation; using NavigationView = Microsoft.UI.Xaml.Controls.NavigationView; using NavigationViewSelectionChangedEventArgs = Microsoft.UI.Xaml.Controls.NavigationViewSelectionChangedEventArgs; +using muxc = Microsoft.UI.Xaml.Controls; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -31,6 +34,8 @@ public sealed partial class MusicPage : Page, IContentFrame private readonly Dictionary _pages; + private ISettingsService Settings => Ioc.Default.GetRequiredService(); + public MusicPage() { this.InitializeComponent(); @@ -55,7 +60,20 @@ protected override void OnNavigatedTo(NavigationEventArgs e) } else { - LibraryNavView.SelectedItem = LibraryNavView.MenuItems[0]; + muxc.NavigationViewItem? libraryNavItem = null; + var launchPage = Settings.LaunchPage; + if (launchPage.GetNavPageFirstLevel() != "music") + { + libraryNavItem = (muxc.NavigationViewItem?)LibraryNavView.MenuItems[0]; + } + else + { + var launchPageTag = launchPage.GetNavPageSecondLevel(); + libraryNavItem = LibraryNavView.MenuItems + .OfType() + .FirstOrDefault(item => item.Tag?.ToString() == launchPageTag); + } + LibraryNavView.SelectedItem = libraryNavItem ?? LibraryNavView.MenuItems[0]; } ViewModel.UpdateSongs(); diff --git a/Screenbox/Pages/SettingsPage.xaml b/Screenbox/Pages/SettingsPage.xaml index 2648555be..4b151d2da 100644 --- a/Screenbox/Pages/SettingsPage.xaml +++ b/Screenbox/Pages/SettingsPage.xaml @@ -355,6 +355,28 @@ + + + + + + + + Home + Songs + Albums + Artists + VideoFolders + AllVideos + Network + PlayQueue + + + diff --git a/Screenbox/Pages/VideosPage.xaml.cs b/Screenbox/Pages/VideosPage.xaml.cs index 960cafa26..d22afa5e4 100644 --- a/Screenbox/Pages/VideosPage.xaml.cs +++ b/Screenbox/Pages/VideosPage.xaml.cs @@ -1,16 +1,19 @@ #nullable enable -using CommunityToolkit.Mvvm.DependencyInjection; -using Screenbox.Core; -using Screenbox.Core.ViewModels; using System; using System.Collections.Generic; using System.Linq; +using CommunityToolkit.Mvvm.DependencyInjection; +using Screenbox.Core; +using Screenbox.Core.Services; +using Screenbox.Core.ViewModels; +using Screenbox.Helpers; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; using Windows.UI.Xaml.Navigation; using NavigationView = Microsoft.UI.Xaml.Controls.NavigationView; using NavigationViewSelectionChangedEventArgs = Microsoft.UI.Xaml.Controls.NavigationViewSelectionChangedEventArgs; +using muxc = Microsoft.UI.Xaml.Controls; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -33,6 +36,8 @@ public sealed partial class VideosPage : Page, IContentFrame private readonly Dictionary _pages; + private ISettingsService Settings => Ioc.Default.GetRequiredService(); + public VideosPage() { this.InitializeComponent(); @@ -56,7 +61,20 @@ protected override void OnNavigatedTo(NavigationEventArgs e) } else { - LibraryNavView.SelectedItem = LibraryNavView.MenuItems[0]; + muxc.NavigationViewItem? libraryNavItem = null; + var launchPage = Settings.LaunchPage; + if (launchPage.GetNavPageFirstLevel() != "videos") + { + libraryNavItem = (muxc.NavigationViewItem?)LibraryNavView.MenuItems[0]; + } + else + { + var launchPageTag = launchPage.GetNavPageSecondLevel(); + libraryNavItem = LibraryNavView.MenuItems + .OfType() + .FirstOrDefault(item => item.Tag?.ToString() == launchPageTag); + } + LibraryNavView.SelectedItem = libraryNavItem ?? LibraryNavView.MenuItems[0]; } ViewModel.UpdateVideos(); diff --git a/Screenbox/Screenbox.csproj b/Screenbox/Screenbox.csproj index 164a38e04..b98743866 100644 --- a/Screenbox/Screenbox.csproj +++ b/Screenbox/Screenbox.csproj @@ -239,6 +239,7 @@ + diff --git a/Screenbox/Strings/en-US/Resources.resw b/Screenbox/Strings/en-US/Resources.resw index 38e172989..742392483 100644 --- a/Screenbox/Strings/en-US/Resources.resw +++ b/Screenbox/Strings/en-US/Resources.resw @@ -947,4 +947,10 @@ Use system language + + Select what to show at launch + + + This page will be shown when the app is launched + \ No newline at end of file