mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
This is a commit that both arm64 and x64 work, a checkpoint here
This commit is contained in:
@@ -67,8 +67,6 @@
|
||||
<ProjectReference Include="..\..\..\Workspaces\Workspaces.ModuleServices\Workspaces.ModuleServices.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Exclude legacy Helper folder in favor of Helpers -->
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Always build/publish AOT so the extension ships as native code -->
|
||||
<SelfContained>true</SelfContained>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,28 +33,36 @@ 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);
|
||||
|
||||
// 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.
|
||||
try
|
||||
{
|
||||
PowerToysExtension extensionInstance = new(extensionDisposedEvent);
|
||||
server.RegisterExtension(() => extensionInstance);
|
||||
Logger.LogInfo("Registering extension via Shmuelie.WinRTServer.");
|
||||
server.RegisterClass<PowerToysExtension, IExtension>(() => extensionInstance);
|
||||
server.Start();
|
||||
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.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
server.Stop();
|
||||
server.UnsafeDispose();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Not being launched as a Extension... exiting.");
|
||||
Logger.LogInfo("Exited: not launched with -RegisterProcessAsComServer.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Unhandled exception in PowerToysExtension.Main", ex);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user