Skip to content
Closed
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
1 change: 1 addition & 0 deletions WinUIGallery/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sealed partial class App : Application
public App()
{
InitializeComponent();
SettingsHelper.Init();
UnhandledException += HandleExceptions;
}

Expand Down
8 changes: 5 additions & 3 deletions WinUIGallery/Controls/PageHeader.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void UserControl_Loaded(object sender, RoutedEventArgs e)
}
if (Item != null)
{
FavoriteButton.IsChecked = SettingsHelper.Contains(SettingsKeys.Favorites, Item.UniqueId);
FavoriteButton.IsChecked = SettingsHelper.Config.Favorites.Contains(Item.UniqueId);
}
}

Expand All @@ -121,11 +121,13 @@ private void FavoriteButton_Click(object sender, RoutedEventArgs e)
{
if (toggleButton.IsChecked == true)
{
SettingsHelper.TryAddItem(SettingsKeys.Favorites, Item.UniqueId, InsertPosition.Last);
SettingsHelper.Config.Favorites.AddLastFavoriteOrRecentlyVisited(Item.UniqueId, true);
SettingsHelper.Save();
}
else
{
SettingsHelper.TryRemoveItem(SettingsKeys.Favorites, Item.UniqueId);
SettingsHelper.Config.Favorites.Remove(Item.UniqueId);
SettingsHelper.Save();
}
}
}
Expand Down
27 changes: 3 additions & 24 deletions WinUIGallery/Helpers/NavigationOrientationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,16 @@ namespace WinUIGallery.Helpers;

public static partial class NavigationOrientationHelper
{
private static bool _isLeftMode = true;
private static ApplicationData appData = ApplicationData.GetDefault();
public static bool IsLeftMode()
{
if (NativeMethods.IsAppPackaged)
{
var valueFromSettings = appData.LocalSettings.Values[SettingsKeys.IsLeftMode];
if (valueFromSettings == null)
{
appData.LocalSettings.Values[SettingsKeys.IsLeftMode] = true;
valueFromSettings = true;
}
return (bool)valueFromSettings;
}
else
{
return _isLeftMode;
}
return SettingsHelper.Config.IsLeftMode;
}

public static void IsLeftModeForElement(bool isLeftMode)
{
UpdateNavigationViewForElement(isLeftMode);
if (NativeMethods.IsAppPackaged)
{
appData.LocalSettings.Values[SettingsKeys.IsLeftMode] = isLeftMode;
}
else
{
_isLeftMode = isLeftMode;
}
SettingsHelper.Config.IsLeftMode = isLeftMode;
SettingsHelper.Save();
}

public static void UpdateNavigationViewForElement(bool isLeftMode)
Expand Down
29 changes: 3 additions & 26 deletions WinUIGallery/Helpers/ProtocolActivationClipboardHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,17 @@ namespace WinUIGallery.Helpers;
/// </summary>
public static partial class ProtocolActivationClipboardHelper
{
private static bool _showCopyLinkTeachingTip = true;
private static ApplicationData appData = ApplicationData.GetDefault();

public static bool ShowCopyLinkTeachingTip
{
get
{
if (NativeMethods.IsAppPackaged)
{
object valueFromSettings = appData.LocalSettings.Values[SettingsKeys.ShowCopyLinkTeachingTip];
if (valueFromSettings == null)
{
appData.LocalSettings.Values[SettingsKeys.ShowCopyLinkTeachingTip] = true;
valueFromSettings = true;
}
return (bool)valueFromSettings;
}
else
{
return _showCopyLinkTeachingTip;
}
return SettingsHelper.Config.IsShowCopyLinkTeachingTip;
}

set
{
if (NativeMethods.IsAppPackaged)
{
appData.LocalSettings.Values[SettingsKeys.ShowCopyLinkTeachingTip] = value;

}
else
{
_showCopyLinkTeachingTip = value;
}
SettingsHelper.Config.IsShowCopyLinkTeachingTip = value;
SettingsHelper.Save();
}
}

Expand Down
192 changes: 0 additions & 192 deletions WinUIGallery/Helpers/SettingsHelper.cs

This file was deleted.

53 changes: 53 additions & 0 deletions WinUIGallery/Helpers/SettingsHelper/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.IO;

namespace WinUIGallery.Helpers;

public partial class AppConfig
{
internal static readonly string RootDirectoryPath = Path.Combine(GetAppDataFolderPath(), ProcessInfoHelper.ProductNameAndVersion);
internal static readonly string AppConfigPath = Path.Combine(RootDirectoryPath, "AppConfig.json");
private static string GetAppDataFolderPath()
{
// This can be replaced with Microsoft.Windows.Storage.ApplicationData.GetForUnPackaged(), once it is available in the WASDK.
var unpackaged = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
return NativeMethods.IsAppPackaged ? Microsoft.Windows.Storage.ApplicationData.GetDefault().LocalFolder.Path : unpackaged;
}

/// <summary>
/// Gets or sets the currently selected application theme.
/// </summary>
public ElementTheme SelectedAppTheme { get; set; } = ElementTheme.Default;

/// <summary>
/// Gets or sets a value indicating whether the navigation is in left mode.
/// </summary>
public bool IsLeftMode { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether the teaching tip for copying links is shown.
/// </summary>
public bool IsShowCopyLinkTeachingTip { get; set; }

/// <summary>
/// Gets or sets the list of favorite items.
/// </summary>
public List<string> Favorites { get; set; } = new();

/// <summary>
/// Gets or sets the list of recently visited items.
/// </summary>
public List<string> RecentlyVisited { get; set; } = new();

/// <summary>
/// Represents the maximum number of recently visited samples to retain.
/// </summary>
public int MaxRecentlyVisitedSamples { get; set; } = 7;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public int MaxRecentlyVisitedSamples { get; set; } = 7;
public const int MaxRecentlyVisitedSamples { get; set; } = 7;

This is supposed to be a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Zakariathr22
If we decide to exclude the max properties from the JSON file, we should move those properties out of AppConfig.cs and into the SettingsHelper.cs class.
so this suggestion can not be commited here.


/// <summary>
/// Gets or sets the maximum number of favorite samples allowed.
/// </summary>
public int MaxFavoriteSamples { get; set; } = 0;
Comment on lines +49 to +52
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no maximum for the favorite samples. The old logic assumed that if the maximum was set to 0, it meant there was no limit. Since that logic has been removed, we no longer need this.

}
9 changes: 9 additions & 0 deletions WinUIGallery/Helpers/SettingsHelper/AppConfigJsonContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace WinUIGallery.Helpers;

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(AppConfig))]
internal partial class AppConfigJsonContext : JsonSerializerContext
{
}
Loading