Revert "more updates"

This reverts commit b1432c7f54.
This commit is contained in:
Mike Griese
2025-08-13 08:42:11 -05:00
parent b1432c7f54
commit a78ce3843a
9 changed files with 30 additions and 82 deletions

View File

@@ -29,14 +29,7 @@ public partial class CommandViewModel : ExtensionObjectViewModel
public IconInfoViewModel Icon { get; private set; }
// UNDER NO CIRCUMSTANCES MAY SOMEONE WRITE TO THIS DICTIONARY.
// This is oour copy of the data from the extension.
// Adding values to it does not add to the extension.
// Modifying it will not modify the extension
// (except it might, if the dictionary was passed by ref)
private Dictionary<string, ExtensionObject<object>>? _properties;
public IReadOnlyDictionary<string, ExtensionObject<object>>? Properties => _properties?.AsReadOnly();
public IDictionary<string, object>? Properties { get; private set; }
public CommandViewModel(ICommand? command, WeakReference<IPageContext> pageContext)
: base(pageContext)
@@ -91,7 +84,7 @@ public partial class CommandViewModel : ExtensionObjectViewModel
if (model is IExtendedAttributesProvider command2)
{
UpdatePropertiesFromExtension(command2);
Properties = command2.Properties;
}
model.PropChanged += Model_PropChanged;
@@ -127,8 +120,15 @@ public partial class CommandViewModel : ExtensionObjectViewModel
Icon = new(iconInfo);
Icon.InitializeProperties();
break;
case nameof(_properties):
UpdatePropertiesFromExtension(model as IExtendedAttributesProvider);
case nameof(IExtendedAttributesProvider.Properties):
if (model is IExtendedAttributesProvider command2)
{
Properties = command2.Properties;
}
else
{
Properties = null;
}
break;
}
@@ -148,26 +148,4 @@ public partial class CommandViewModel : ExtensionObjectViewModel
model.PropChanged -= Model_PropChanged;
}
}
private void UpdatePropertiesFromExtension(IExtendedAttributesProvider? model)
{
var propertiesFromExtension = model?.GetProperties();
if (propertiesFromExtension == null)
{
_properties = null;
return;
}
_properties = [];
// COPY the properties into us.
// The IDictionary that was passed to us may be marshalled by-ref or by-value, we _don't know_.
//
// If it's by-ref, the values are arbitrary objects that are out-of-proc.
// If it's bu-value, then everything is in-proc, and we can't mutate the data.
foreach (var property in propertiesFromExtension)
{
_properties.Add(property.Key, new(property.Value));
}
}
}

View File

@@ -48,15 +48,7 @@ public partial class IconDataViewModel : ObservableObject, IIconData
if (model is IExtendedAttributesProvider icon2)
{
var props = icon2.GetProperties();
// From Raymond Chen:
// Make sure you don't try do do something like
// icon2.GetProperties().TryGetValue("awesomeKey", out var awesomeValue);
// icon2.GetProperties().TryGetValue("slackerKey", out var slackerValue);
// because each call to GetProperties() is a cross process hop, and if you
// marshal-by-value the property set, then you don't want to throw it away and
// re-marshal it for every property. MAKE SURE YOU CACHE IT.
var props = icon2.Properties;
if (props?.TryGetValue("FontFamily", out var family) ?? false)
{
FontFamily = family as string;

View File

@@ -1971,7 +1971,7 @@ we're going to add the following interface to our API:
```csharp
interface IExtendedAttributesProvider
{
Windows.Foundation.Collections.IMap<String, Object> GetProperties();
Windows.Foundation.Collections.IMap<String, Object> Properties { get; };
};
interface ICommandProvider2 requires ICommandProvider
@@ -2035,7 +2035,11 @@ public partial class SamplePagesCommandsProvider : CommandProvider, ICommandProv
return [new SupportCommandsWithProperties()];
}
private sealed partial class SupportCommandsWithProperties : IExtendedAttributesProvider {
public IDictionary<string, object>? GetProperties() => null;
public IPropertySet OtherProperties => null;
public IIconInfo Icon => null;
public string Id => string.Empty;
public string Name => string.Empty;
public event TypedEventHandler<object, IPropChangedEventArgs> PropChanged { add { } remove { } }
}
}

View File

@@ -191,7 +191,7 @@ internal sealed partial class SampleListPage : ListPage
public override string Name => "Whatever";
public IDictionary<string, object> GetProperties() => new Dictionary<string, object>()
public IDictionary<string, object> Properties => new Dictionary<string, object>()
{
{ "Foo", "bar" },
{ "Secret", 42 },
@@ -215,7 +215,7 @@ internal sealed partial class SampleListPage : ListPage
return CommandResult.ShowToast("whoop");
}
public IDictionary<string, object> GetProperties() => new Dictionary<string, object>()
public IDictionary<string, object> Properties => new Dictionary<string, object>()
{
{ "yo", "dog" },
{ "Secret", 12345 },

View File

@@ -3,7 +3,7 @@
"SamplePagesExtension (Package)": {
"commandName": "MsixPackage",
"doNotLaunchApp": true,
"nativeDebugging": false
"nativeDebugging": true
},
"SamplePagesExtension (Unpackaged)": {
"commandName": "Project"

View File

@@ -62,35 +62,9 @@
</PropertyGroup>
<PropertyGroup>
<PublishSingleFile>true</PublishSingleFile>
<IsAotCompatible>true</IsAotCompatible>
<CsWinRTAotOptimizerEnabled>true</CsWinRTAotOptimizerEnabled>
<CsWinRTAotWarningLevel>2</CsWinRTAotWarningLevel>
<!-- Suppress DynamicallyAccessedMemberTypes.PublicParameterlessConstructor in fallback code path of Windows SDK projection -->
<WarningsNotAsErrors>IL2081;$(WarningsNotAsErrors)</WarningsNotAsErrors>
<!-- When publishing trimmed, make sure to treat trimming warnings as build errors -->
<ILLinkTreatWarningsAsErrors>true</ILLinkTreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<!-- In Debug builds, trimming is disabled by default, but all the trim &
AOT warnings are enabled. This gives debug builds a tighter inner loop,
while at least warning about future trim violations -->
<PublishTrimmed>false</PublishTrimmed>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'!='Debug'">
<!-- In Release builds, trimming is enabled by default.
feel free to disable this if needed -->
<PublishTrimmed>true</PublishTrimmed>
<PublishSingleFile>true</PublishSingleFile>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View File

@@ -67,6 +67,6 @@ public abstract partial class CommandProvider : ICommandProvider, ICommandProvid
/// </summary>
private sealed partial class SupportCommandsWithProperties : IExtendedAttributesProvider
{
public IDictionary<string, object>? GetProperties() => null;
IDictionary<string, object>? IExtendedAttributesProvider.Properties => null;
}
}

View File

@@ -16,16 +16,16 @@ namespace Microsoft.CommandPalette.Extensions.Toolkit;
/// </summary>
public partial class FontIconData : IconData, IExtendedAttributesProvider
{
public string FontFamily { get; set; }
public string FontFace { get; set; }
public FontIconData(string glyph, string fontFamily)
public FontIconData(string glyph, string fontFace)
: base(glyph)
{
FontFamily = fontFamily;
FontFace = fontFace;
}
public IDictionary<string, object>? GetProperties() => new Dictionary<string, object>()
public IDictionary<string, object>? Properties => new Dictionary<string, object>()
{
{ "FontFamily", FontFamily },
{ "FontFamily", FontFace },
};
}

View File

@@ -367,7 +367,7 @@ namespace Microsoft.CommandPalette.Extensions
[contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)]
interface IExtendedAttributesProvider
{
Windows.Foundation.Collections.IMap<String, Object> GetProperties();
Windows.Foundation.Collections.IMap<String, Object> Properties { get; };
};
[contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)]