Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update extension Json to make way for changes on extensions page and environments page #3923

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/Contracts/ILocalSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface ILocalSettingsService
Task<T?> ReadSettingAsync<T>(string key);

Task SaveSettingAsync<T>(string key, T value);

public string GetPathToPackageLocation();
}
1 change: 1 addition & 0 deletions common/DevHome.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.0.240109" />
<PackageReference Include="LibGit2Sharp" Version="0.30.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="JsonSchema.Net" Version="7.2.3" />
<PackageReference Include="Microsoft.Internal.Windows.DevHome.Helpers" Version="1.0.20240910-x0103" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
Expand Down
15 changes: 15 additions & 0 deletions common/Helpers/CommonConstants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json;
using DevHome.Common.Models.ExtensionJsonData;

namespace DevHome.Common.Helpers;

public static class CommonConstants
Expand Down Expand Up @@ -32,4 +35,16 @@ public static class CommonConstants
#endif

public const string HyperVWindowsOptionalFeatureName = "Microsoft-Hyper-V";

public static JsonSerializerOptions ExtensionJsonSerializerOptions => new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
TypeInfoResolver = new JsonSourceGenerationContext(),
TypeInfoResolverChain = { JsonSourceGenerationContext.Default },
};

public static readonly string LocalExtensionJsonSchemaRelativeFilePath = @"Assets\Schemas\ExtensionInformation.schema.json";

public static readonly string LocalExtensionJsonRelativeFilePath = @"Assets\ExtensionInformation.json";
}
15 changes: 15 additions & 0 deletions common/Models/ExtensionJsonData/DevHomeExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace DevHome.Common.Models.ExtensionJsonData;

public class DevHomeExtension
{
public LocalizedProperties LocalizedProperties { get; set; } = new();

public required List<string> SupportedProviderTypes { get; set; } = new();

public required List<ProviderSpecificProperty> ProviderSpecificProperties { get; set; } = new();
}
18 changes: 18 additions & 0 deletions common/Models/ExtensionJsonData/DevHomeExtensionContentData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace DevHome.Common.Models.ExtensionJsonData;

/// <summary>
/// Root class that will contain the deserialized data located in the
/// src\Assets\ExtensionInformation.json file. Its schema is located in
/// src\Assets\Schemas\ExtensionInformation.schema.json.
/// </summary>
public class DevHomeExtensionContentData
{
public List<string> ProductIds { get; set; } = new();

public List<Product> Products { get; set; } = new();
}
26 changes: 26 additions & 0 deletions common/Models/ExtensionJsonData/JsonSourceGenerationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;
using Json.Schema;

namespace DevHome.Common.Models.ExtensionJsonData;

/// <summary>
/// Used to generate C# classes from the extension json and extension json schema.
/// .Net 8 requires a JsonSerializerContext to be used with the JsonSerializerOptions when
/// deserializing JSON into objects.
/// See : https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/source-generation?pivots=dotnet-8-0
/// for more information
/// </summary>
[JsonSerializable(typeof(LocalizedProperties))]
[JsonSerializable(typeof(ProviderSpecificProperty))]
[JsonSerializable(typeof(Properties))]
[JsonSerializable(typeof(Product))]
[JsonSerializable(typeof(DevHomeExtensionContentData))]
[JsonSerializable(typeof(DevHomeExtension))]
[JsonSerializable(typeof(JsonSchema))]
[JsonSerializable(typeof(EvaluationResults))]
public partial class JsonSourceGenerationContext : JsonSerializerContext
{
}
11 changes: 11 additions & 0 deletions common/Models/ExtensionJsonData/LocalizedProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace DevHome.Common.Models.ExtensionJsonData;

public class LocalizedProperties
{
public string DisplayNameKey { get; set; } = string.Empty;

public string DisplayName { get; set; } = string.Empty;
}
65 changes: 65 additions & 0 deletions common/Models/ExtensionJsonData/LocalizedPropertiesConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using DevHome.Common.Services;

namespace DevHome.Common.Models.ExtensionJsonData;

/// <summary>
/// Custom JSON converter for <see cref="LocalizedProperties"/>.
/// This should be added directly to a <see cref="JsonSerializerOptions"/> to handle the conversion of a
/// localized key within the extension json to a value in the DevHome.pri resource file.
/// </summary>
public class LocalizedPropertiesConverter : JsonConverter<LocalizedProperties>
{
private readonly IStringResource _stringResource;

public LocalizedPropertiesConverter(IStringResource stringResource)
{
_stringResource = stringResource;
}

public override LocalizedProperties Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var localizedProperties = new LocalizedProperties();

// Read the JSON and populate the properties
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
{
break;
}

if (reader.TokenType == JsonTokenType.PropertyName)
{
var propertyName = reader.GetString();
reader.Read(); // Move to the value

if (reader.TokenType != JsonTokenType.String)
{
continue;
}

switch (propertyName)
{
case nameof(LocalizedProperties.DisplayNameKey):
localizedProperties.DisplayNameKey = reader.GetString()!;
break;
}
}
}

localizedProperties.DisplayName = _stringResource.GetLocalized(localizedProperties.DisplayNameKey);

return localizedProperties;
}

public override void Write(Utf8JsonWriter writer, LocalizedProperties value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
11 changes: 11 additions & 0 deletions common/Models/ExtensionJsonData/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace DevHome.Common.Models.ExtensionJsonData;

public class Product
{
public required string ProductId { get; set; }

public required Properties Properties { get; set; }
}
21 changes: 21 additions & 0 deletions common/Models/ExtensionJsonData/Properties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace DevHome.Common.Models.ExtensionJsonData;

public class Properties
{
public required string PackageFamilyName { get; set; }

public required bool SupportsWidgets { get; set; }

public string Description { get; set; } = string.Empty;

public string PublisherName { get; set; } = string.Empty;

public string ProductTitle { get; set; } = string.Empty;

public required List<DevHomeExtension> DevHomeExtensions { get; set; } = new();
}
11 changes: 11 additions & 0 deletions common/Models/ExtensionJsonData/ProviderSpecificProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace DevHome.Common.Models.ExtensionJsonData;

public class ProviderSpecificProperty
{
public required LocalizedProperties LocalizedProperties { get; set; }

public required string ProviderType { get; set; }
}
7 changes: 7 additions & 0 deletions common/Services/IExtensionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DevHome.Common.Models.ExtensionJsonData;
using Windows.Foundation;

namespace DevHome.Common.Services;
Expand Down Expand Up @@ -35,4 +36,10 @@ public interface IExtensionService
/// <param name="extension">The out of proc extension object</param>
/// <returns>True only if the extension was disabled. False otherwise.</returns>
public Task<bool> DisableExtensionIfWindowsFeatureNotAvailable(IExtensionWrapper extension);

/// <summary>
/// Gets known extension information from internal extension json file.
/// </summary>
/// <returns>An object that holds a list of extension information based on the internal json file.</returns>
public Task<DevHomeExtensionContentData?> GetExtensionJsonDataAsync();
}
6 changes: 6 additions & 0 deletions common/Services/LocalSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using DevHome.Common.Helpers;
using DevHome.Common.Models;
using Microsoft.Extensions.Options;
using Windows.ApplicationModel;
using Windows.Storage;

namespace DevHome.Common.Services;
Expand Down Expand Up @@ -106,4 +107,9 @@ public async Task SaveSettingAsync<T>(string key, T value)
await Task.Run(() => _fileService.Save(_applicationDataFolder, _localSettingsFile, _settings));
}
}

public string GetPathToPackageLocation()
{
return Package.Current.EffectivePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public bool IsElevationRequired
get;
}

/// <summary>
/// Gets the package description.
/// </summary>
public string Description
{
get;
}

/// <summary>
/// Gets the package uri of this package
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public WinGetPackage(ILogger logger, CatalogPackage package, bool requiresElevat
PublisherUrl = GetMetadataValue(package, metadata => new Uri(metadata.PublisherUrl), nameof(CatalogPackageMetadata.PublisherUrl), null);
PublisherName = GetMetadataValue(package, metadata => metadata.Publisher, nameof(CatalogPackageMetadata.Publisher), null);
InstallationNotes = GetMetadataValue(package, metadata => metadata.InstallationNotes, nameof(CatalogPackageMetadata.InstallationNotes), null);
Description = GetMetadataValue(package, metadata => metadata.Description, nameof(CatalogPackageMetadata.Description), null);
}

public string Id { get; }
Expand Down Expand Up @@ -76,6 +77,8 @@ public WinGetPackage(ILogger logger, CatalogPackage package, bool requiresElevat

public bool IsElevationRequired { get; }

public string Description { get; }

public WinGetPackageUri GetUri(string installVersion = null)
{
var uriOptions = string.IsNullOrEmpty(installVersion) ? null : new WinGetPackageUriOptions(installVersion);
Expand Down
84 changes: 84 additions & 0 deletions src/Assets/ExtensionInformation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
bbonaby marked this conversation as resolved.
Show resolved Hide resolved
"ProductIds": [ "9MV8F79FGXTR", "9NZCC27PR6N6", "9NZ845RW19RW", "9NB9M5KZ8SLX" ],
"Products": [
{
"ProductId": "9MV8F79FGXTR",
"Properties": {
"PublisherName": "Microsoft Corporation",
"ProductTitle": "Dev Home Azure Extension (Preview)",
"PackageFamilyName": "Microsoft.Windows.DevHomeAzureExtension_8wekyb3d8bbwe",
"SupportsWidgets": true,
"DevHomeExtensions": [
{
"SupportedProviderTypes": [
"ComputeSystem",
"DeveloperId",
"QuickStartProject",
"Repository",
"Settings"
],
"ProviderSpecificProperties": [
{
"LocalizedProperties": {
"DisplayNameKey": "DevBoxProviderDisplayName"
},
"ProviderType": "ComputeSystem"
}
]
}
]
}
},
{
"ProductId": "9NZCC27PR6N6",
"Properties": {
"PublisherName": "Microsoft Corporation",
"ProductTitle": "Dev Home GitHub Extension (Preview)",
"PackageFamilyName": "Microsoft.Windows.DevHomeGitHubExtension_8wekyb3d8bbwe",
"SupportsWidgets": true,
"DevHomeExtensions": [
{
"SupportedProviderTypes": [
"DeveloperId",
"Repository",
"Settings"
],
"ProviderSpecificProperties": []
}
]
}
},
{
"ProductId": "9NZ845RW19RW",
"Properties": {
"PublisherName": "Microsoft Corporation",
"ProductTitle": "Microsoft Game Dev Extension (Preview)",
"PackageFamilyName": "Microsoft.DevHomeMicrosoftGameDevExtension_8wekyb3d8bbwe",
"SupportsWidgets": true,
"DevHomeExtensions": [
{
"SupportedProviderTypes": [
"FeaturedApplications"
],
"ProviderSpecificProperties": []
}
]
}
},
{
"ProductId": "9NB9M5KZ8SLX",
"Properties": {
"PublisherName": "Martí Climent",
"ProductTitle": "Widgets for UniGetUI (formerly WingetUI)",
"PackageFamilyName": "9932MartCliment.WingetUIWidgets_g91dtg5srk15g",
"SupportsWidgets": true,
"DevHomeExtensions": [
{
"SupportedProviderTypes": [],
"ProviderSpecificProperties": []
}
]
}
}
]
}
Loading
Loading