Skip to content

Commit 84e11ae

Browse files
authored
#41 Support Selecting custom page to be shown on startup (#42)
- Fixed FrameworkVersion warnings - NavigationItemKey ordered alphabetically
1 parent 79b8a2c commit 84e11ae

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

WingetGUIInstaller/Constants/ConfigurationPropertyKeys.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace WingetGUIInstaller.Constants
1+
using WingetGUIInstaller.Enums;
2+
3+
namespace WingetGUIInstaller.Constants
24
{
35
public static class ConfigurationPropertyKeys
46
{
@@ -8,12 +10,14 @@ public static class ConfigurationPropertyKeys
810
public const string DisabledPackageSources = "disabledPackageSources";
911
public const string IgnoreEmptyPackageSources = "ignoreEmptyPackageSources";
1012
public const string AutomaticUpdates = "AutomaticUpdates";
13+
public const string SelectedPage = "SelectedPage";
1114

1215
public const bool ConsoleEnabledDefaultValue = true;
1316
public const bool NotificationsEnabledDefaultValue = true;
1417
public const bool PackageSourceFilteringEnabledDefaultValue = false;
1518
public const string DisabledPackageSourcesDefaultValue = "";
1619
public const bool IgnoreEmptyPackageSourcesDefaultValue = true;
1720
public const bool AutomaticUpdatesDefaultValue = false;
21+
public const int SelectedPageDefaultValue = (int)NavigationItemKey.Recommendations;
1822
}
1923
}

WingetGUIInstaller/Enums/NavigationItemKey.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ public enum NavigationItemKey
55
About,
66
Console,
77
Home,
8+
ImportExport,
89
InstalledPackages,
10+
PackageDetails,
11+
PackageSources,
912
Recommendations,
1013
Search,
1114
Settings,
1215
Upgrades,
13-
PackageDetails,
14-
ImportExport,
15-
PackageSources,
1616
}
1717
}

WingetGUIInstaller/Pages/MainPage.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using CommunityToolkit.Mvvm.DependencyInjection;
22
using CommunityToolkit.Mvvm.Messaging;
3+
using CommunityToolkit.WinUI.Helpers;
34
using Microsoft.UI.Xaml.Controls;
45
using Microsoft.UI.Xaml.Navigation;
56
using System;
67
using System.Linq;
78
using Windows.System;
9+
using WingetGUIInstaller.Constants;
810
using WingetGUIInstaller.Enums;
911
using WingetGUIInstaller.Messages;
1012
using WingetGUIInstaller.Services;
@@ -16,6 +18,7 @@ namespace WingetGUIInstaller.Pages
1618
[PageKey(NavigationItemKey.Home)]
1719
public sealed partial class MainPage : Page
1820
{
21+
private readonly ApplicationDataStorageHelper _applicationSettings;
1922
private NavigationItemKey _defaultPage = NavigationItemKey.Recommendations;
2023
private bool _pageLoaded = false;
2124
private readonly IMultiLevelNavigationService<NavigationItemKey> _navigationService;
@@ -26,10 +29,16 @@ public MainPage()
2629
InitializeComponent();
2730
Loaded += MainPage_Loaded;
2831
Unloaded += MainPage_Unloaded;
32+
2933
_navigationService = Ioc.Default.GetRequiredService<IMultiLevelNavigationService<NavigationItemKey>>();
3034
_navigationService.AddNavigationLevel(ContentFrame);
35+
_applicationSettings = Ioc.Default.GetRequiredService<ApplicationDataStorageHelper>();
36+
_defaultPage = (NavigationItemKey)_applicationSettings
37+
.Read(ConfigurationPropertyKeys.SelectedPage, ConfigurationPropertyKeys.SelectedPageDefaultValue);
38+
3139
DataContext = ViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
3240
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
41+
3342
WeakReferenceMessenger.Default.Register(this, (MessageHandler<object, NavigationRequestedMessage>)((r, m) =>
3443
{
3544
DispatcherQueue.TryEnqueue(() =>

WingetGUIInstaller/Pages/SettingsPage.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
IsOn="{x:Bind ViewModel.ConsoleTabEnabled, Mode=TwoWay}"
4141
PrimaryText="Show Console output"
4242
SecondaryText="Enables the ability to view raw command ouput for actions" />
43+
<customControls:CustomContentSettingsControl Margin="0,1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PrimaryText="Default Page"
44+
SecondaryText="Change the page that is shown when the application starts up">
45+
<customControls:CustomContentSettingsControl.CustomContent>
46+
<ComboBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
47+
ItemsSource="{x:Bind ViewModel.AvailablePages, Mode=OneTime}"
48+
SelectedItem="{x:Bind ViewModel.SelectedPage, Mode=TwoWay}" />
49+
</customControls:CustomContentSettingsControl.CustomContent>
50+
</customControls:CustomContentSettingsControl>
4351
</StackPanel>
4452
</Expander>
4553

WingetGUIInstaller/ViewModels/SettingsPageViewModel.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,30 @@
44
using CommunityToolkit.WinUI.Helpers;
55
using GithubPackageUpdater.Services;
66
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
79
using System.Threading.Tasks;
810
using System.Windows.Input;
911
using Windows.ApplicationModel;
1012
using WingetGUIInstaller.Constants;
13+
using WingetGUIInstaller.Enums;
1114
using WingetGUIInstaller.Messages;
1215

1316
namespace WingetGUIInstaller.ViewModels
1417
{
1518
public class SettingsPageViewModel : ObservableObject
1619
{
20+
private readonly NavigationItemKey[] _disallowedKeys = new NavigationItemKey[] {
21+
NavigationItemKey.Settings, NavigationItemKey.About, NavigationItemKey.Console, NavigationItemKey.Home };
1722
private readonly ApplicationDataStorageHelper _configurationStore;
1823
private readonly GithubPackageUpdaterSerivce _updaterSerivce;
1924
private bool? _consoleTabEnabled;
2025
private bool? _notificationsEnabled;
2126
private bool? _packageSourceFilteringEnabled;
2227
private bool? _ignoreEmptyPackageSourceEnabled;
2328
private bool? _automaticUpdatesEnabled;
29+
private NavigationItemKey? _selectedPage;
30+
2431

2532
public SettingsPageViewModel(ApplicationDataStorageHelper configurationStore,
2633
GithubPackageUpdaterSerivce updaterSerivce)
@@ -129,7 +136,30 @@ public bool AutomaticUpdatesEnabled
129136
_configurationStore.Save(ConfigurationPropertyKeys.AutomaticUpdates, value);
130137
}
131138
}
132-
}
139+
}
140+
141+
public NavigationItemKey SelectedPage
142+
{
143+
get
144+
{
145+
if (_selectedPage == null)
146+
{
147+
_selectedPage = (NavigationItemKey)_configurationStore
148+
.Read(ConfigurationPropertyKeys.SelectedPage, ConfigurationPropertyKeys.SelectedPageDefaultValue);
149+
}
150+
return _selectedPage.Value;
151+
}
152+
set
153+
{
154+
if (SetProperty(ref _selectedPage, value))
155+
{
156+
_configurationStore.Save(ConfigurationPropertyKeys.SelectedPage, (int)value);
157+
}
158+
}
159+
}
160+
161+
public IReadOnlyList<NavigationItemKey> AvailablePages => Enum.GetValues<NavigationItemKey>().Cast<NavigationItemKey>()
162+
.Where(key => !_disallowedKeys.Contains(key)).ToList();
133163

134164
public ICommand CheckForUpdatesCommand => new AsyncRelayCommand(CheckForUpdatesAsync);
135165

WingetGUIInstaller/WingetGUIInstaller.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
44
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
5-
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
5+
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
66
<RootNamespace>WingetGUIInstaller</RootNamespace>
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<Platforms>x86;x64;arm64</Platforms>

0 commit comments

Comments
 (0)