From 43783d2cffdeade0707374927795428926108a9c Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 24 Mar 2025 05:43:47 -0500 Subject: [PATCH] Use Shmueli's COM server to fix ARM (#38090) More than a couple people hit mYsTeRiOuS iSsUeS on ARM. Extensions would load the first time, but never again. Their processes would start, but the objects would fail to load. Fortunately, @azchohfi discovered that using `Shmuelie.WinRTServer`, rather than the one pilfered from devhome, doesn't have this problem. I don't have an ARM machine to validate the changes, but @lauren-ciha thankfully did the groundwork to get this validated in their extension, so I think this should work. Closes https://github.com/zadjii-msft/PowerToys/issues/97 --- .github/actions/spell-check/allow/names.txt | 1 + .../Directory.Packages.props | 1 + .../TemplateCmdPalExtension/Program.cs | 20 +++++++++++------- .../TemplateCmdPalExtension.cs | 2 -- .../TemplateCmdPalExtension.csproj | 1 + .../Pages/SampleListPage.cs | 5 +++++ .../Assets/template.zip | Bin 18639 -> 18690 bytes 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/actions/spell-check/allow/names.txt b/.github/actions/spell-check/allow/names.txt index fc153dd632..84884b819c 100644 --- a/.github/actions/spell-check/allow/names.txt +++ b/.github/actions/spell-check/allow/names.txt @@ -154,6 +154,7 @@ Santossio Schoen Sekan Seraphima +Shmuelie skttl somil Soref diff --git a/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/Directory.Packages.props b/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/Directory.Packages.props index 4e4102de90..782ec68bf5 100644 --- a/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/Directory.Packages.props +++ b/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/Directory.Packages.props @@ -10,6 +10,7 @@ + diff --git a/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/Program.cs b/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/Program.cs index 7325c7c960..200ac6e71e 100644 --- a/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/Program.cs +++ b/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/Program.cs @@ -2,28 +2,32 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.CommandPalette.Extensions; +using Shmuelie.WinRTServer; +using Shmuelie.WinRTServer.CsWinRT; using System; using System.Threading; -using Microsoft.CommandPalette.Extensions; +using System.Threading.Tasks; namespace TemplateCmdPalExtension; public class Program { [MTAThread] - public static void Main(string[] args) + public static async Task Main(string[] args) { if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer") { - using ExtensionServer server = new(); - var extensionDisposedEvent = new ManualResetEvent(false); - var extensionInstance = new TemplateCmdPalExtension(extensionDisposedEvent); - + await using global::Shmuelie.WinRTServer.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. - server.RegisterExtension(() => extensionInstance); - + TemplateCmdPalExtension extensionInstance = new(extensionDisposedEvent); + server.RegisterClass(() => extensionInstance); + server.Start(); + // 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(); diff --git a/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.cs b/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.cs index ac6659e3b4..c05b361b76 100644 --- a/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.cs +++ b/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.cs @@ -9,9 +9,7 @@ using Microsoft.CommandPalette.Extensions; namespace TemplateCmdPalExtension; -[ComVisible(true)] [Guid("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")] -[ComDefaultInterface(typeof(IExtension))] public sealed partial class TemplateCmdPalExtension : IExtension, IDisposable { private readonly ManualResetEvent _extensionDisposedEvent; diff --git a/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.csproj b/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.csproj index 6b58eb0e05..72e6d7400b 100644 --- a/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.csproj +++ b/src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.csproj @@ -43,6 +43,7 @@ +