-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[AOT] Refactor SettingsLib/SettingsUI for Native AOT compatibility #42644
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
base: main
Are you sure you want to change the base?
Conversation
This commit refactors the PowerToys Settings UI Library and Settings UI to be compatible with Native AOT compilation by implementing source-generated JSON serialization. Key Changes: 1. Settings.UI.Library: - Added SettingsSerializationContext.cs with comprehensive JsonSerializable attributes for all settings types - Updated BasePTModuleSettings.ToJsonString() to use AOT-compatible serialization - Updated SettingsUtils.GetFile<T>() to use AOT-compatible deserialization - Modified all ToString() methods in Properties classes to use SettingsSerializationContext - Converted struct fields to properties in SunTimes and MouseWithoutBordersProperties for serialization compatibility 2. Settings.UI: - Fixed namespace alias in SourceGenerationContextContext.cs to avoid conflicts 3. Documentation: - Added detailed XML documentation explaining AOT requirements and registration steps - Included clear error messages for unregistered types These changes ensure Settings can be compiled with Native AOT while maintaining backward compatibility with the existing codebase.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Transitioned to source-generated JSON serialization using `JsonSerializerContext` for improved performance, maintainability, and type safety. Introduced `SettingsSerializationContext` for production and `TestSettingsSerializationContext` for unit tests. - Updated `AdvancedPasteCustomActions` to use a custom serialization context with `TypeInfoResolver`. - Refactored `ToJsonString` and `ToString` methods in various classes (e.g., `ImageResizerProperties`, `PasteAIConfiguration`) to use context-specific serialization. - Added new types to `SettingsSerializationContext` for advanced serialization support, including `CursorWrapSettings`, `AdvancedPaste`-related types, and IPC message wrapper classes. - Introduced serialization support for generic IPC wrapper types (e.g., `SndModuleSettings<T>`). - Added `TestSettingsSerializationContext` for unit tests with test-specific serialization options. - Updated `BasePTSettingsTest` to override `ToJsonString` for test-specific serialization. - Added necessary `using` directives to support the new serialization contexts. These changes enhance scalability, maintainability, and compatibility with new features and test scenarios.
Added `BasePTModuleSettingsSerializationTests` to validate the registration of `BasePTModuleSettings` derived classes in `SettingsSerializationContext` for Native AOT compatibility. - Implemented `AllBasePTModuleSettingsClasses_ShouldBeRegisteredInSerializationContext` to ensure all derived classes are registered and provide detailed error messages for missing registrations. - Added `ToJsonString_UnregisteredType_ShouldThrowInvalidOperationException` to verify unregistered types throw `InvalidOperationException`. - Added `ToJsonString_UnregisteredType_ShouldHaveHelpfulErrorMessage` to ensure error messages for unregistered types are informative. - Introduced `UnregisteredTestSettings` as a test class to simulate unregistered types. - Enhanced test clarity with comments, assertions, and success messages.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Enabled nullable reference types in SettingsUtils.cs to improve null safety. Refactored the `SettingsUtils` constructor to accept optional `JsonSerializerOptions`, replacing static serializer options with instance-level options for better modularity. Updated method signatures to use nullable reference types and added null-conditional operators where applicable. Enhanced the `GetSettingsOrDefault` method to handle nullable `settingsUpgrader` parameters. Updated test cases to align with the new constructor signature and introduced `TestSettingsSerializationContext` for test-specific configurations. Added `[TestCleanup]` logic in FancyZones tests to reset singleton instances, ensuring test isolation. Made minor namespace and import adjustments to support these changes. Overall, these updates improve code flexibility, modularity, and testability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the Settings.UI.Library and Settings.UI projects to support Native AOT compilation by introducing source-generated JSON serialization. The refactoring ensures all settings types are registered for ahead-of-time compilation while maintaining backward compatibility.
Key changes:
- Introduces
SettingsSerializationContextwith comprehensive[JsonSerializable]attributes for all settings types - Updates all serialization/deserialization methods to use AOT-compatible JSON type information
- Converts struct fields to properties in
SunTimesandConnectionRequestfor serialization compatibility
Reviewed Changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| SettingsSerializationContext.cs | New file defining the source-generated JSON serialization context with 169 registered types |
| BasePTModuleSettings.cs | Updated ToJsonString() to use type-safe AOT serialization with runtime type validation |
| SettingsUtils.cs | Modified GetFile<T>() to use AOT-compatible deserialization with helpful error messages |
| SourceGenerationContextContext.cs | Fixed namespace alias to avoid naming conflicts |
| Various Properties classes | Updated ToString() methods to use context-specific serialization |
| SunTimes.cs, MouseWithoutBordersProperties.cs | Converted struct fields to properties for JSON serialization |
| Test files | Added comprehensive tests for type registration validation and test-specific serialization context |
src/settings-ui/Settings.UI.Library/AdvancedPasteCustomActions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…ls (#43458) Addresses feedback from #42644 to remove an unused namespace import. ## Changes - Removed unused `System.Diagnostics.CodeAnalysis` import from `SettingsUtils.cs` (line 8) The namespace was imported but no attributes from it (`[SuppressMessage]`, `[DynamicallyAccessedMembers]`, etc.) were used in the file. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: moooyo <[email protected]>
Summary of the Pull Request
Key Changes:
Settings.UI.Library:
Settings.UI:
Documentation:
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed