Skip to content

Conversation

@moooyo
Copy link
Contributor

@moooyo moooyo commented Oct 20, 2025

Summary of the Pull Request

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() 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

PR Checklist

  • Closes: #xxx
  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

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.
@moooyo
Copy link
Contributor Author

moooyo commented Nov 10, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@moooyo moooyo marked this pull request as ready for review November 10, 2025 05:55
@moooyo moooyo marked this pull request as draft November 10, 2025 06:47
Yu Leng added 2 commits November 10, 2025 15:29
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.
@moooyo moooyo marked this pull request as ready for review November 11, 2025 06:07
@moooyo
Copy link
Contributor Author

moooyo commented Nov 11, 2025

/azp run

@azure-pipelines
Copy link

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.
@moooyo moooyo requested a review from Copilot November 11, 2025 08:11
Copilot finished reviewing on behalf of moooyo November 11, 2025 08:14
Copy link
Contributor

Copilot AI left a 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 SettingsSerializationContext with 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 SunTimes and ConnectionRequest for 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

Copy link
Contributor

Copilot AI commented Nov 11, 2025

@moooyo I've opened a new pull request, #43458, to work on those changes. Once the pull request is ready, I'll request review from you.

moooyo and others added 2 commits November 11, 2025 16:31
…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]>
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.

2 participants