diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj
index f0139341a3..59ef3600b2 100644
--- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj
@@ -67,8 +67,6 @@
-
-
true
diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/PowerToysExtension.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/PowerToysExtension.cs
index 4059b09cfc..f4100db51a 100644
--- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/PowerToysExtension.cs
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/PowerToysExtension.cs
@@ -20,7 +20,7 @@ public sealed partial class PowerToysExtension : IExtension, IDisposable
public PowerToysExtension(ManualResetEvent extensionDisposedEvent)
{
this._extensionDisposedEvent = extensionDisposedEvent;
- Logger.LogInfo("PowerToysExtension constructed.");
+ Logger.LogInfo($"PowerToysExtension constructed. ProcArch={RuntimeInformation.ProcessArchitecture} OSArch={RuntimeInformation.OSArchitecture} BaseDir={AppContext.BaseDirectory}");
}
public object? GetProvider(ProviderType providerType)
diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Program.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Program.cs
index e03cfe2329..2706f50f90 100644
--- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Program.cs
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Program.cs
@@ -3,9 +3,12 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Runtime.InteropServices;
using System.Threading;
using ManagedCommon;
using Microsoft.CommandPalette.Extensions;
+using Shmuelie.WinRTServer;
+using Shmuelie.WinRTServer.CsWinRT;
namespace PowerToysExtension;
@@ -18,7 +21,7 @@ public class Program
{
// Initialize per-extension log under CmdPal/PowerToysExtension.
Logger.InitializeLogger("\\CmdPal\\PowerToysExtension\\Logs");
- Logger.LogInfo("PowerToysExtension starting (args: " + string.Join(' ', args) + ")");
+ Logger.LogInfo($"PowerToysExtension starting. Args=\"{string.Join(' ', args)}\" ProcArch={RuntimeInformation.ProcessArchitecture} OSArch={RuntimeInformation.OSArchitecture} BaseDir={AppContext.BaseDirectory}");
}
catch
{
@@ -30,21 +33,24 @@ public class Program
if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer")
{
Logger.LogInfo("RegisterProcessAsComServer mode detected.");
- using ExtensionServer server = new();
-
+ ComServer server = new();
ManualResetEvent extensionDisposedEvent = new(false);
+ try
+ {
+ PowerToysExtension extensionInstance = new(extensionDisposedEvent);
+ Logger.LogInfo("Registering extension via Shmuelie.WinRTServer.");
+ server.RegisterClass(() => extensionInstance);
+ server.Start();
+ Logger.LogInfo("Extension instance registered; waiting for disposal signal.");
- // We are instantiating an extension instance once above, and returning it every time the callback in RegisterExtension below is called.
- // This makes sure that only one instance of SampleExtension is alive, which is returned every time the host asks for the IExtension object.
- // If you want to instantiate a new instance each time the host asks, create the new instance inside the delegate.
- PowerToysExtension extensionInstance = new(extensionDisposedEvent);
- server.RegisterExtension(() => extensionInstance);
- Logger.LogInfo("Extension instance registered; waiting for disposal signal.");
-
- // This will make the main thread wait until the event is signalled by the extension class.
- // Since we have single instance of the extension object, we exit as soon as it is disposed.
- extensionDisposedEvent.WaitOne();
- Logger.LogInfo("Extension disposed signal received; exiting server loop.");
+ extensionDisposedEvent.WaitOne();
+ Logger.LogInfo("Extension disposed signal received; exiting server loop.");
+ }
+ finally
+ {
+ server.Stop();
+ server.UnsafeDispose();
+ }
}
else
{
@@ -52,6 +58,11 @@ public class Program
Logger.LogInfo("Exited: not launched with -RegisterProcessAsComServer.");
}
}
+ catch (Exception ex)
+ {
+ Logger.LogError("Unhandled exception in PowerToysExtension.Main", ex);
+ throw;
+ }
finally
{
}