This is a commit that both arm64 and x64 work, a checkpoint here

This commit is contained in:
vanzue
2025-12-10 18:20:25 +08:00
parent 67a41f7441
commit 45a506092c
3 changed files with 26 additions and 17 deletions

View File

@@ -67,8 +67,6 @@
<ProjectReference Include="..\..\..\Workspaces\Workspaces.ModuleServices\Workspaces.ModuleServices.csproj" /> <ProjectReference Include="..\..\..\Workspaces\Workspaces.ModuleServices\Workspaces.ModuleServices.csproj" />
</ItemGroup> </ItemGroup>
<!-- Exclude legacy Helper folder in favor of Helpers -->
<PropertyGroup> <PropertyGroup>
<!-- Always build/publish AOT so the extension ships as native code --> <!-- Always build/publish AOT so the extension ships as native code -->
<SelfContained>true</SelfContained> <SelfContained>true</SelfContained>

View File

@@ -20,7 +20,7 @@ public sealed partial class PowerToysExtension : IExtension, IDisposable
public PowerToysExtension(ManualResetEvent extensionDisposedEvent) public PowerToysExtension(ManualResetEvent extensionDisposedEvent)
{ {
this._extensionDisposedEvent = 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) public object? GetProvider(ProviderType providerType)

View File

@@ -3,9 +3,12 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using ManagedCommon; using ManagedCommon;
using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions;
using Shmuelie.WinRTServer;
using Shmuelie.WinRTServer.CsWinRT;
namespace PowerToysExtension; namespace PowerToysExtension;
@@ -18,7 +21,7 @@ public class Program
{ {
// Initialize per-extension log under CmdPal/PowerToysExtension. // Initialize per-extension log under CmdPal/PowerToysExtension.
Logger.InitializeLogger("\\CmdPal\\PowerToysExtension\\Logs"); 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 catch
{ {
@@ -30,21 +33,24 @@ public class Program
if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer") if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer")
{ {
Logger.LogInfo("RegisterProcessAsComServer mode detected."); Logger.LogInfo("RegisterProcessAsComServer mode detected.");
using ExtensionServer server = new(); ComServer server = new();
ManualResetEvent extensionDisposedEvent = new(false); ManualResetEvent extensionDisposedEvent = new(false);
try
{
PowerToysExtension extensionInstance = new(extensionDisposedEvent);
Logger.LogInfo("Registering extension via Shmuelie.WinRTServer.");
server.RegisterClass<PowerToysExtension, IExtension>(() => 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. extensionDisposedEvent.WaitOne();
// This makes sure that only one instance of SampleExtension is alive, which is returned every time the host asks for the IExtension object. Logger.LogInfo("Extension disposed signal received; exiting server loop.");
// If you want to instantiate a new instance each time the host asks, create the new instance inside the delegate. }
PowerToysExtension extensionInstance = new(extensionDisposedEvent); finally
server.RegisterExtension(() => extensionInstance); {
Logger.LogInfo("Extension instance registered; waiting for disposal signal."); server.Stop();
server.UnsafeDispose();
// 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.");
} }
else else
{ {
@@ -52,6 +58,11 @@ public class Program
Logger.LogInfo("Exited: not launched with -RegisterProcessAsComServer."); Logger.LogInfo("Exited: not launched with -RegisterProcessAsComServer.");
} }
} }
catch (Exception ex)
{
Logger.LogError("Unhandled exception in PowerToysExtension.Main", ex);
throw;
}
finally finally
{ {
} }