Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9a9ae94
Implemented new settings system
ghost1372 Aug 7, 2025
d5b5b9c
Replace Old Settings with New Settings
ghost1372 Aug 7, 2025
8def68c
Remove Old Settings
ghost1372 Aug 7, 2025
c42d4d0
Rename Settings to SettingsHelper
ghost1372 Aug 7, 2025
ec0bacf
Remove unused codes
ghost1372 Aug 7, 2025
51c3447
Fix ScratchPadPage
ghost1372 Aug 7, 2025
b3da70f
Update MainWindow.xaml.cs
ghost1372 Aug 7, 2025
5bf1266
use Try/Catch in Get methods
ghost1372 Aug 7, 2025
181fc43
Make ListExtensions More Generic
ghost1372 Aug 10, 2025
40e76e0
Add Common Methods for Favorites and RecentlyVisited to Simplify Thei…
ghost1372 Aug 11, 2025
7f04f89
Remove Unsued Vector Wrapper
ghost1372 Aug 11, 2025
d8c7891
Remove ScratchPadXaml Setting
ghost1372 Aug 15, 2025
9bcced4
Update WinUIGallery/Helpers/SettingsHelper/Providers/JsonSettingsProv…
ghost1372 Aug 30, 2025
b14fbb0
Update WinUIGallery/Helpers/SettingsHelper/Providers/ApplicationDataS…
ghost1372 Aug 30, 2025
b5a7e56
Merge branch 'main' into AppSettings
niels9001 Sep 9, 2025
0e36b3f
Merge branch 'main' into AppSettings
ghost1372 Sep 28, 2025
e523217
Rename ListExtensions methods for clarity
ghost1372 Sep 28, 2025
425e96e
Use product name for settings folder path
ghost1372 Sep 28, 2025
0361951
Refactor Get<T>: restrict try/catch to JSON deserialization only
ghost1372 Sep 28, 2025
1982f07
Add one-time migration for Favorites and RecentlyVisited from old Set…
ghost1372 Sep 28, 2025
90a12b8
Merge branch 'main' into AppSettings
ghost1372 Sep 28, 2025
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
7 changes: 7 additions & 0 deletions WinUIGallery/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar

EnsureWindow();

if (SettingsHelper.Current.IsFirstRun)
{
SettingsMigration.MigrateRecentlyVisited();
SettingsMigration.MigrateFavorites();
SettingsHelper.Current.IsFirstRun = false;
}

MainWindow.Closed += (s, e) =>
{
if (IsAppPackaged)
Expand Down
6 changes: 3 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.Current.Favorites.Contains(Item.UniqueId);
}
}

Expand All @@ -121,11 +121,11 @@ private void FavoriteButton_Click(object sender, RoutedEventArgs e)
{
if (toggleButton.IsChecked == true)
{
SettingsHelper.TryAddItem(SettingsKeys.Favorites, Item.UniqueId, InsertPosition.Last);
SettingsHelper.Current.UpdateFavorites(items => items.AddAsLast(Item.UniqueId));
}
else
{
SettingsHelper.TryRemoveItem(SettingsKeys.Favorites, Item.UniqueId);
SettingsHelper.Current.UpdateFavorites(items => items.Remove(Item.UniqueId));
}
}
}
Expand Down
27 changes: 2 additions & 25 deletions WinUIGallery/Helpers/NavigationOrientationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,20 @@
// Licensed under the MIT License.

using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.Storage;

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.Current.IsLeftMode;
}

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

public static void UpdateNavigationViewForElement(bool isLeftMode)
Expand Down
28 changes: 2 additions & 26 deletions WinUIGallery/Helpers/ProtocolActivationClipboardHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,16 @@ 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.Current.IsShowCopyLinkTeachingTip;
}

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

}
else
{
_showCopyLinkTeachingTip = value;
}
SettingsHelper.Current.IsShowCopyLinkTeachingTip = value;
}
}

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

This file was deleted.

34 changes: 34 additions & 0 deletions WinUIGallery/Helpers/SettingsHelper/Internals/ListExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;

namespace WinUIGallery.Helpers;

internal static class ListExtensions
{
public static void AddAsFirst<T>(this List<T> list, T item, int? maxSize = null)
{
if (item == null || (item is string data && string.IsNullOrWhiteSpace(data)))
return;

list.Remove(item);
list.Insert(0, item);

if (maxSize.HasValue && maxSize.Value > 0 && list.Count > maxSize.Value)
{
list.RemoveRange(maxSize.Value, list.Count - maxSize.Value);
}
}

public static void AddAsLast<T>(this List<T> list, T item, int? maxSize = null)
{
if (item == null || (item is string data && string.IsNullOrWhiteSpace(data)))
return;

list.Remove(item);
list.Add(item);

if (maxSize.HasValue && maxSize.Value > 0 && list.Count > maxSize.Value)
{
list.RemoveRange(0, list.Count - maxSize.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace WinUIGallery.Helpers;

[JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata)]
[JsonSerializable(typeof(Dictionary<string, System.Text.Json.JsonElement>))]
[JsonSerializable(typeof(SettingsHelper))]
internal partial class SettingsJsonContext : JsonSerializerContext
{
}
Loading