Skip to content

Commit 43783d2

Browse files
authored
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 zadjii-msft#97
1 parent 79bd825 commit 43783d2

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

.github/actions/spell-check/allow/names.txt

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Santossio
154154
Schoen
155155
Sekan
156156
Seraphima
157+
Shmuelie
157158
skttl
158159
somil
159160
Soref

src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageVersion Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
1111
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
1212
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.6.250205002" />
13+
<PackageVersion Include="Shmuelie.WinRTServer" Version="2.1.1" />
1314
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
1415
<PackageVersion Include="System.Text.Json" Version="9.0.3" />
1516
</ItemGroup>

src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/Program.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,32 @@
22
// The Microsoft Corporation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Microsoft.CommandPalette.Extensions;
6+
using Shmuelie.WinRTServer;
7+
using Shmuelie.WinRTServer.CsWinRT;
58
using System;
69
using System.Threading;
7-
using Microsoft.CommandPalette.Extensions;
10+
using System.Threading.Tasks;
811

912
namespace TemplateCmdPalExtension;
1013

1114
public class Program
1215
{
1316
[MTAThread]
14-
public static void Main(string[] args)
17+
public static async Task Main(string[] args)
1518
{
1619
if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer")
1720
{
18-
using ExtensionServer server = new();
19-
var extensionDisposedEvent = new ManualResetEvent(false);
20-
var extensionInstance = new TemplateCmdPalExtension(extensionDisposedEvent);
21-
21+
await using global::Shmuelie.WinRTServer.ComServer server = new();
22+
ManualResetEvent extensionDisposedEvent = new(false);
23+
2224
// We are instantiating an extension instance once above, and returning it every time the callback in RegisterExtension below is called.
2325
// This makes sure that only one instance of SampleExtension is alive, which is returned every time the host asks for the IExtension object.
2426
// If you want to instantiate a new instance each time the host asks, create the new instance inside the delegate.
25-
server.RegisterExtension(() => extensionInstance);
26-
27+
TemplateCmdPalExtension extensionInstance = new(extensionDisposedEvent);
28+
server.RegisterClass<TemplateCmdPalExtension, IExtension>(() => extensionInstance);
29+
server.Start();
30+
2731
// This will make the main thread wait until the event is signalled by the extension class.
2832
// Since we have single instance of the extension object, we exit as soon as it is disposed.
2933
extensionDisposedEvent.WaitOne();

src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.cs

-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace TemplateCmdPalExtension;
1111

12-
[ComVisible(true)]
1312
[Guid("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")]
14-
[ComDefaultInterface(typeof(IExtension))]
1513
public sealed partial class TemplateCmdPalExtension : IExtension, IDisposable
1614
{
1715
private readonly ManualResetEvent _extensionDisposedEvent;

src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtension.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<PackageReference Include="Microsoft.WindowsAppSDK" />
4444
<PackageReference Include="Microsoft.Web.WebView2" />
4545
<PackageReference Include="System.Text.Json" />
46+
<PackageReference Include="Shmuelie.WinRTServer" />
4647
</ItemGroup>
4748

4849
<!--

src/modules/cmdpal/Exts/SamplePagesExtension/Pages/SampleListPage.cs

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public override IListItem[] GetItems()
5454
Title = "This item will take you to another page",
5555
Subtitle = "This allows for nested lists of items",
5656
},
57+
new ListItem(new OpenUrlCommand("https://github.com/microsoft/powertoys"))
58+
{
59+
Title = "Or you can go to links",
60+
Subtitle = "This takes you to the PowerToys repo on GitHub",
61+
},
5762
new ListItem(new SampleMarkdownPage())
5863
{
5964
Title = "Items can have tags",
Binary file not shown.

0 commit comments

Comments
 (0)