mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
[AOT][CmdPal] Enable NativeAOT Compatibility for CmdPal Apps Extension (#39678)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This PR introduces necessary changes to make the CmdPal.Apps extension compatible with NativeAOT publishing. The main updates include: 1. Project configuration updates: Added NativeAOT-related properties to the .csproj. 2. Native interop adjustments: > - Introduced NativeMethods.json and used [CsWin32](https://github.com/microsoft/cswin32) to generate P/Invoke bindings. > - Replaced some DllImport declarations with source-generated [LibraryImport] for improved AOT support.
This commit is contained in:
@@ -8,7 +8,12 @@ using System.Threading.Tasks;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.Apps.Programs;
|
||||
using Microsoft.CmdPal.Ext.Apps.Properties;
|
||||
using Microsoft.CmdPal.Ext.Apps.Utils;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.Services.Maps;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.System.Com;
|
||||
using Windows.Win32.UI.Shell;
|
||||
using WyHash;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Apps;
|
||||
@@ -27,26 +32,31 @@ internal sealed partial class AppCommand : InvokableCommand
|
||||
|
||||
internal static async Task StartApp(string aumid)
|
||||
{
|
||||
var appManager = new ApplicationActivationManager();
|
||||
const ActivateOptions noFlags = ActivateOptions.None;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
unsafe
|
||||
{
|
||||
appManager.ActivateApplication(aumid, /*queryArguments*/ string.Empty, noFlags, out var unusedPid);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Logger.LogError(ex.Message);
|
||||
IApplicationActivationManager* appManager = null;
|
||||
try
|
||||
{
|
||||
PInvoke.CoCreateInstance(typeof(ApplicationActivationManager).GUID, null, CLSCTX.CLSCTX_INPROC_SERVER, out appManager).ThrowOnFailure();
|
||||
using var handle = new SafeComHandle((IntPtr)appManager);
|
||||
appManager->ActivateApplication(
|
||||
aumid,
|
||||
string.Empty,
|
||||
ACTIVATEOPTIONS.AO_NONE,
|
||||
out var unusedPid);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Logger.LogError(ex.Message);
|
||||
}
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static async Task StartExe(string path)
|
||||
{
|
||||
var appManager = new ApplicationActivationManager();
|
||||
|
||||
// const ActivateOptions noFlags = ActivateOptions.None;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user