self com server

This commit is contained in:
vanzue
2025-11-25 10:10:53 +08:00
parent 12b150bcc8
commit fac448a3a9
10 changed files with 376 additions and 763 deletions

View File

@@ -3,7 +3,10 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Threading;
using ManagedCommon;
using Microsoft.CmdPal.Ext.PowerToys.ComServer;
using Microsoft.CommandPalette.Extensions;
namespace Microsoft.CmdPal.Ext.PowerToys;
@@ -13,18 +16,31 @@ public static class Program
[MTAThread]
public static int Main(string[] args)
{
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)}\"");
if (args.Length > 0 && args[0].Equals("-RegisterProcessAsComServer", StringComparison.OrdinalIgnoreCase))
{
using ExtensionServer server = new();
using PowerToysExtensionServer server = new();
using ManualResetEvent extensionDisposed = new(false);
var extensionInstance = new PowerToysExtension(extensionDisposed);
server.RegisterExtension(() => extensionInstance);
Logger.LogInfo("Registered PowerToys CmdPal extension COM server. Waiting for dispose signal.");
extensionDisposed.WaitOne();
return 0;
}
Logger.LogWarning("PowerToys CmdPal extension launched without COM registration arguments. Exiting.");
Console.WriteLine("Microsoft.CmdPal.Ext.PowerToys launched without COM registration arguments. Exiting.");
return 0;
}