Skip to content

[cmdpal][AOT] fix some cmdpal aot issue #40301

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[cmdpal][AOT] fix some cmdpal aot issue #40301

wants to merge 1 commit into from

Conversation

moooyo
Copy link
Contributor

@moooyo moooyo commented Jun 30, 2025

Summary of the Pull Request

Most of them are safe change but only one line may break something is in TrayIconService.cs

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

- Changed `Logger.LogDebug` to `Logger.LogError` in `ExtensionWrapper.cs` for better error handling.
- Modified `HotkeySettingsControlHook` to be a partial class for improved organization.
- Updated `NativeKeyboardHelper` class and structures for clarity, including using `Marshal.SizeOf<INPUT>()`.
- Converted `NativeMethods` to a partial class and updated PInvoke declarations to use `LibraryImport`.
- Improved type safety in `TrayIconService.cs` by updating size calculations and adjusted executable path for compatibility.
- Cleaned up `NativeMethods.txt` by removing unused function references.
@moooyo moooyo requested a review from Copilot June 30, 2025 09:37
Copy link
Contributor

@Copilot 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 addresses AOT issues in the cmdpal module by adjusting interop declarations and updating certain API usages. Key changes include:

  • Updates to interop method declarations (using LibraryImport and generic Marshal.SizeOf).
  • Modification of the tray icon’s executable path resolution in TrayIconService.
  • Change of log level in ExtensionWrapper from Debug to Error.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt Removal of unused native method references
src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/TrayIconService.cs Updated exe path resolution and generic size calculation
src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeMethods.cs Converted to partial class with LibraryImport attributes
src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeKeyboardHelper.cs Updated file-scoped namespace and generic Marshal.SizeOf
src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/HotkeySettingsControlHook.cs Made the hook class partial
src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionWrapper.cs Changed logging from Debug to Error
Comments suppressed due to low confidence (2)

src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/TrayIconService.cs:136

  • Using a hard-coded executable name may lead to issues if the application name changes or if the expected file is not present in the base directory. Consider adding validation or a fallback mechanism to ensure this path resolves correctly.
        var exePath = Path.Combine(AppContext.BaseDirectory, "Microsoft.CmdPal.UI.exe");

src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionWrapper.cs:124

  • Changing the log level from Debug to Error could increase noise if the missing extension is a normal scenario. Please verify that this condition truly warrants an error level log.
                                Logger.LogError($"Failed to find {ExtensionDisplayName}: {hr}. It may have been uninstalled or deleted.");

@@ -5,82 +5,81 @@
using System;
using System.Runtime.InteropServices;

namespace Microsoft.PowerToys.Settings.UI.Helpers
Copy link
Member

Choose a reason for hiding this comment

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

protip: suppress whitespace on this file

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