[WindowsSettings] DevDocs + JSON schema (#13510)

* #10997 - Added JSON schema and extra shell class

* #13510 - Address feedback and fix wrong typo for a member

* #13510 - Add DevDoc (first version)

* #13510 - make spellcheck happy

* #13510 Address feedback, add scores, replace todos

* Make build server happy

* #13510 - Address feedback - Extra table for keys

* #13510 - Address feedback

* #13510 -Address feedback, add language specified

Co-authored-by: Sekan, Tobias <tobias.sekan@axp-consulting.de>
This commit is contained in:
Tobias Sekan
2021-10-14 16:17:41 +02:00
committed by GitHub
parent db1318fed1
commit da0b96a5ad
9 changed files with 292 additions and 42 deletions

View File

@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
{
/// <summary>
/// A class that contain all possible windows settings
/// </summary>
internal class WindowsSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="WindowsSettings"/> class with an empty settings list.
/// </summary>
public WindowsSettings()
{
Settings = Enumerable.Empty<WindowsSetting>();
}
/// <summary>
/// Gets or sets a list with all possible windows settings
/// </summary>
public IEnumerable<WindowsSetting> Settings { get; set; }
}
}

View File

@@ -27,12 +27,12 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
/// Read all possible Windows settings.
/// </summary>
/// <returns>A list with all possible windows settings.</returns>
internal static IEnumerable<WindowsSetting> ReadAllPossibleSettings()
internal static WindowsSettings ReadAllPossibleSettings()
{
var assembly = Assembly.GetExecutingAssembly();
var type = assembly.GetTypes().FirstOrDefault(x => x.Name == nameof(Main));
IEnumerable<WindowsSetting>? settingsList = null;
WindowsSettings? settings = null;
try
{
@@ -49,14 +49,14 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
using var reader = new StreamReader(stream);
var text = reader.ReadToEnd();
settingsList = JsonSerializer.Deserialize<IEnumerable<WindowsSetting>>(text, options);
settings = JsonSerializer.Deserialize<WindowsSettings>(text, options);
}
catch (Exception exception)
{
Log.Exception("Error loading settings JSON file", exception, typeof(JsonSettingsListHelper));
}
return settingsList ?? Enumerable.Empty<WindowsSetting>();
return settings ?? new WindowsSettings();
}
}
}

View File

@@ -16,17 +16,17 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
internal static class TranslationHelper
{
/// <summary>
/// Translate all settings of the given list with <see cref="WindowsSetting"/>.
/// Translate all settings of the settings list in the given <see cref="WindowsSettings"/> class.
/// </summary>
/// <param name="settingsList">The list that contains <see cref="WindowsSetting"/> to translate.</param>
internal static void TranslateAllSettings(in IEnumerable<WindowsSetting>? settingsList)
/// <param name="windowsSettings">A class that contain all possible windows settings.</param>
internal static void TranslateAllSettings(in WindowsSettings windowsSettings)
{
if (settingsList is null)
if (windowsSettings?.Settings is null)
{
return;
}
foreach (var settings in settingsList)
foreach (var settings in windowsSettings.Settings)
{
// Translate Name
if (!string.IsNullOrWhiteSpace(settings.Name))

View File

@@ -19,15 +19,14 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
private const string _keyNameBuildNumber = "CurrentBuildNumber";
/// <summary>
/// Remove all <see cref="WindowsSetting"/> of the given list that are not present on the current used Windows build.
/// Remove all <see cref="WindowsSetting"/> from the settings list in the given <see cref="WindowsSetting"/> class.
/// </summary>
/// <param name="settingsList">The list with <see cref="WindowsSetting"/> to filter.</param>
/// <returns>A new list with <see cref="WindowsSetting"/> that only contain present Windows settings for this OS.</returns>
internal static IEnumerable<WindowsSetting> FilterByBuild(in IEnumerable<WindowsSetting>? settingsList)
/// <param name="windowsSettings">A class that contain all possible windows settings.</param>
internal static void FilterByBuild(in WindowsSettings windowsSettings)
{
if (settingsList is null)
if (windowsSettings?.Settings is null)
{
return Enumerable.Empty<WindowsSetting>();
return;
}
var currentBuild = GetNumericRegistryValue(_keyPath, _keyNameBuild);
@@ -48,13 +47,13 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
? currentBuild
: currentBuildNumber;
var filteredSettingsList = settingsList.Where(found
var filteredSettingsList = windowsSettings.Settings.Where(found
=> (found.DeprecatedInBuild == null || currentWindowsBuild < found.DeprecatedInBuild)
&& (found.IntroducedInBuild == null || currentWindowsBuild >= found.IntroducedInBuild));
filteredSettingsList = filteredSettingsList.OrderBy(found => found.Name);
return filteredSettingsList;
windowsSettings.Settings = filteredSettingsList;
}
/// <summary>

View File

@@ -19,17 +19,17 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
private const string _pathDelimiterSequence = "\u0020\u0020\u02C3\u0020\u0020"; // = "<space><space><arrow><space><space>"
/// <summary>
/// Generates the values for <see cref="WindowsSetting.JoinedAreaPath"/> and <see cref="WindowsSetting.JoinedFullSettingsPath"/> on all settings of the given list with <see cref="WindowsSetting"/>.
/// Generates the values for <see cref="WindowsSetting.JoinedAreaPath"/> and <see cref="WindowsSetting.JoinedFullSettingsPath"/> on all settings of the list in the given <see cref="WindowsSettings"/> class.
/// </summary>
/// <param name="settingsList">The list that contains <see cref="WindowsSetting"/> to translate.</param>
internal static void GenerateSettingsPathValues(in IEnumerable<WindowsSetting>? settingsList)
/// <param name="windowsSettings">A class that contain all possible windows settings.</param>
internal static void GenerateSettingsPathValues(in WindowsSettings windowsSettings)
{
if (settingsList is null)
if (windowsSettings?.Settings is null)
{
return;
}
foreach (var settings in settingsList)
foreach (var settings in windowsSettings.Settings)
{
// Check if type value is filled. If not, then write log warning.
if (string.IsNullOrEmpty(settings.Type))
@@ -52,9 +52,9 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
// Generating path values.
if (!(settings.Areas is null) && settings.Areas.Any())
{
var areaValue = string.Join(WindowsSettingsPathHelper._pathDelimiterSequence, settings.Areas);
var areaValue = string.Join(_pathDelimiterSequence, settings.Areas);
settings.JoinedAreaPath = areaValue;
settings.JoinedFullSettingsPath = $"{settings.Type}{WindowsSettingsPathHelper._pathDelimiterSequence}{areaValue}";
settings.JoinedFullSettingsPath = $"{settings.Type}{_pathDelimiterSequence}{areaValue}";
}
else
{

View File

@@ -49,9 +49,9 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
private bool _disposed;
/// <summary>
/// List that contain all settings.
/// A class that contain all possible windows settings.
/// </summary>
private IEnumerable<WindowsSetting>? _settingsList;
private WindowsSettings? _windowsSettings;
/// <summary>
/// Initializes a new instance of the <see cref="Main"/> class.
@@ -82,11 +82,12 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
_context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(_context.API.GetCurrentTheme());
_settingsList = JsonSettingsListHelper.ReadAllPossibleSettings();
_settingsList = UnsupportedSettingsHelper.FilterByBuild(_settingsList);
_windowsSettings = JsonSettingsListHelper.ReadAllPossibleSettings();
TranslationHelper.TranslateAllSettings(_settingsList);
WindowsSettingsPathHelper.GenerateSettingsPathValues(_settingsList);
UnsupportedSettingsHelper.FilterByBuild(_windowsSettings);
TranslationHelper.TranslateAllSettings(_windowsSettings);
WindowsSettingsPathHelper.GenerateSettingsPathValues(_windowsSettings);
}
/// <summary>
@@ -95,13 +96,13 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
/// <param name="query">The query to filter the list.</param>
/// <returns>A filtered list, can be empty when nothing was found.</returns>
public List<Result> Query(Query query)
{
if (_settingsList is null)
{
if (_windowsSettings?.Settings is null)
{
return new List<Result>(0);
}
var filteredList = _settingsList
var filteredList = _windowsSettings.Settings
.Where(Predicate)
.OrderBy(found => found.Name);

View File

@@ -1,11 +1,13 @@
[
{
"Name": "AccessWorkOrSchool",
"Areas": [ "AreaAccounts" ],
"Type": "AppSettingsApp",
"AltNames": [ "Workplace" ],
"Command": "ms-settings:workplace"
},
{
"$schema" : "./WindowsSettings.schema.json",
"Settings": [
{
"Name": "AccessWorkOrSchool",
"Areas": [ "AreaAccounts" ],
"Type": "AppSettingsApp",
"AltNames": [ "Workplace" ],
"Command": "ms-settings:workplace"
},
{
"Name": "EmailAndAppAccounts",
"Areas": [ "AreaAccounts" ],
@@ -1734,4 +1736,4 @@
"AltNames": [ "wgpocpl.cpl" ],
"Command": "control Wgpocpl.cpl"
}
]
]}

View File

@@ -0,0 +1,65 @@
{
"$schema": "http://json-schema.org/draft-04/schema",
"additionalProperties": false,
"required": [ "Settings" ],
"properties": {
"Settings": {
"description": "A list with all possible windows settings.",
"type": "array",
"items": {
"additionalProperties": false,
"required": [ "Name", "Command", "Type" ],
"type": "object",
"properties": {
"Name": {
"description": "The name of this setting.",
"type": "string"
},
"Areas": {
"description": "A list of areas of this setting",
"type": "array",
"items": {
"description": "A area of this setting",
"type": "string",
"pattern": "^Area"
}
},
"Type": {
"description": "The type of this setting.",
"type": "string",
"pattern": "^App"
},
"AltNames": {
"description": "A list with alternative names for this setting",
"type": "array",
"items": {
"description": "A alternative name for this setting",
"type": "string"
}
},
"Command": {
"description": "The command for this setting.",
"type": "string"
},
"Note": {
"description": "A additional note for this setting.",
"type": "string",
"pattern": "^Note"
},
"DeprecatedInBuild": {
"description": "The Windows build since this settings is not longer present.",
"type": "integer",
"minimum": 0,
"maximum": 4294967295
},
"IntroducedInBuild": {
"description": "The minimum need Windows build for this setting.",
"type": "integer",
"minimum": 0,
"maximum": 4294967295
}
}
}
}
}
}