Skip to content

Refactor Application Settings and Support for Packaged/Unpackaged Mode #1924 #2014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ghost1372
Copy link
Contributor

This PR replaces the legacy ApplicationData-based settings system with a new SettingsHelper class. It adds support for both packaged and unpackaged app scenarios.

Closes #1924.

Old Settings System:

appData.LocalSettings.Values[SettingsKeys.IsLeftMode] = true;
New Settings System:

SettingsHelper.Current.IsLeftMode = true;

Note

Settings are automatically saved when changed.

Important Note on List Types:

Direct modification of list items won't persist changes:

SettingsHelper.Current.myList.Add(item); // ❌ This won't work

var list = SettingsHelper.Current.myList;
list.Add(item);
SettingsHelper.Current.myList = list; // ✅ This works

SettingsHelper Architecture:

Uses an ISettingsProvider abstraction.
In packaged mode: uses ApplicationDataContainer.
In unpackaged mode: uses JsonSettingsProvider.

Adding a New Setting:

public bool IsEnabled
{
    get => GetOrCreateDefault<bool>(true);
    set => Set(value);
}

Supported Types:

In unpackaged mode (JSON), you can serialize most types easily.

In packaged mode, ApplicationDataContainer supports only limited types directly:

  • Primitives
  • string
  • DateTimeOffset
  • TimeSpan
  • Guid
  • Windows.Foundation.Point
  • Windows.Foundation.Size
  • Windows.Foundation.Rect

Other types (e.g., decimal, List) are serialized to JSON before being stored.

Vector Types:

Types like Vector2, Vector3, and Vector4 do not work in regular mode. Instead, use wrapper classes like Vector2Data, Vector3Data, and Vector4Data:

public System.Numerics.Vector2 Position2D
{
    get => GetOrCreateDefault<Vector2Data>(new Vector2Data { X = 0, Y = 0 });
    set => Set((Vector2Data)value);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnPackaged Mode is Broken
1 participant