Files
PowerToys/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Program.cs

52 lines
1.9 KiB
C#
Raw Normal View History

2025-11-19 19:16:38 +08:00
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
2025-11-25 10:10:53 +08:00
using System.Diagnostics;
2025-11-25 15:49:50 +08:00
using System.Runtime.InteropServices.Marshalling;
2025-11-19 19:16:38 +08:00
using System.Threading;
2025-11-25 10:10:53 +08:00
using ManagedCommon;
using Microsoft.CmdPal.Ext.PowerToys.ComServer;
2025-11-19 19:16:38 +08:00
using Microsoft.CommandPalette.Extensions;
2025-11-25 15:49:50 +08:00
using WinRT;
2025-11-19 19:16:38 +08:00
namespace Microsoft.CmdPal.Ext.PowerToys;
public static class Program
{
[MTAThread]
public static int Main(string[] args)
{
2025-11-25 10:10:53 +08:00
try
{
Logger.InitializeLogger("\\CmdPal\\PowerToysExtension\\Logs");
}
catch
{
// If logging fails we still continue; CmdPal host will surface failures.
}
var exePath = Process.GetCurrentProcess().MainModule?.FileName ?? "unknown";
Logger.LogInfo($"PowerToys CmdPal extension entry point. exe={exePath}, args=\"{string.Join(' ', args)}\"");
2025-11-19 19:16:38 +08:00
if (args.Length > 0 && args[0].Equals("-RegisterProcessAsComServer", StringComparison.OrdinalIgnoreCase))
{
2025-11-25 15:49:50 +08:00
// Ensure cswinrt uses our StrategyBasedComWrappers so the IExtension WinRT interface marshals correctly cross-process.
ComWrappersSupport.InitializeComWrappers(new StrategyBasedComWrappers());
2025-11-25 10:10:53 +08:00
using PowerToysExtensionServer server = new();
2025-11-19 19:16:38 +08:00
using ManualResetEvent extensionDisposed = new(false);
var extensionInstance = new PowerToysExtension(extensionDisposed);
server.RegisterExtension(() => extensionInstance);
2025-11-25 10:10:53 +08:00
Logger.LogInfo("Registered PowerToys CmdPal extension COM server. Waiting for dispose signal.");
2025-11-19 19:16:38 +08:00
extensionDisposed.WaitOne();
return 0;
}
2025-11-25 10:10:53 +08:00
Logger.LogWarning("PowerToys CmdPal extension launched without COM registration arguments. Exiting.");
2025-11-19 19:16:38 +08:00
return 0;
}
}