mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
[Run-Plugin] Settings plugin (#11663)
* Current settings plugin state on fresh master * typo fixes * Add to YML * Add to WXS * Address feedback - highlight the note in the tool-tip a little bit * Address feedback add extra note for "Manage known networks" * Address feedback - Show type of settings in sub-line and remove extra ControlPanel prefix in json * Add "WiFi" as alternative name for each Wi-Fi setting * Add a few more alternative names * Make RESX happy * exclude WindowsSettings.json from spell checker because all entries are placeholders for the translation * Translate all alternative names * Translate all notes * fix for not find "wifi" * fix typo * typo fixes and remove debug * Address feedback - correct author * Address feedback - settings entries * Address feedback - code changes * Address feedback - RESX changes and tool-tip * fix typo * Address feedback - remove superfluous interface * Address feedback - Update RESX * Address feedback - simplification * Address feedback - remove enumeration * Address feedback - move big function in extra helper classes * Address feedback - move big function in extra helper class * Address feedback - correct namespace * Address feedback - move translation to translation helper and make translation more robust * fix typo * Update src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Main.cs Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Helper/ResultHelper.cs Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Main.cs Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * fix build * Address feedback * ups * Address feedback - Correct windows update settings name * Update src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/WindowsSettings.json Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * adding in dependencies so when you build Launcher, all plugins are included * Address feedback - add optional updates * Address feedback - use build numebr instaed of Windows version * Address feedback - Log difference between registry values + fix wrong ValueType (ushort -> uint) * Address feebdback - improved warning message on different registry values * fix typo * removed not need using * Update src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Helper/UnsupportedSettingsHelper.cs Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Helper/UnsupportedSettingsHelper.cs Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Update src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Helper/UnsupportedSettingsHelper.cs Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Addrress feedback, don't copy embed file * Address feedback - Remove duplicated or not available settings * Address feedback - Improve scoring * Address feedback - Add extra filter * Address feedback - replace the are filter sign with a better one * Address feedback - fix unwanted behavior * Address feedback - Change class name * Address feedback - Rename settings type * typo fix * Fix installer * Comment out localization support Co-authored-by: Sekan, Tobias <tobias.sekan@startmail.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> Co-authored-by: crutkas <crutkas@microsoft.com>
This commit is contained in:
@@ -0,0 +1,217 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper;
|
||||
using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Main class of this plugin that implement all used interfaces.
|
||||
/// </summary>
|
||||
public class Main : IPlugin, IContextMenu, IPluginI18n, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The path to the symbol for a light theme.
|
||||
/// </summary>
|
||||
private const string _lightSymbol = "Images/WindowsSettings.light.png";
|
||||
|
||||
/// <summary>
|
||||
/// The path to the symbol for a dark theme.
|
||||
/// </summary>
|
||||
private const string _darkSymbol = "Images/WindowsSettings.dark.png";
|
||||
|
||||
/// <summary>
|
||||
/// The name of this assembly.
|
||||
/// </summary>
|
||||
private readonly string _assemblyName;
|
||||
|
||||
/// <summary>
|
||||
/// The initial context for this plugin (contains API and meta-data).
|
||||
/// </summary>
|
||||
private PluginInitContext? _context;
|
||||
|
||||
/// <summary>
|
||||
/// The path to the icon for each result.
|
||||
/// </summary>
|
||||
private string _defaultIconPath;
|
||||
|
||||
/// <summary>
|
||||
/// Indicate that the plugin is disposed.
|
||||
/// </summary>
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// List that contain all settings.
|
||||
/// </summary>
|
||||
private IEnumerable<WindowsSetting>? _settingsList;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Main"/> class.
|
||||
/// </summary>
|
||||
public Main()
|
||||
{
|
||||
_assemblyName = Assembly.GetExecutingAssembly().GetName().Name ?? Name;
|
||||
_defaultIconPath = _lightSymbol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized name.
|
||||
/// </summary>
|
||||
public string Name => Resources.PluginTitle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized description.
|
||||
/// </summary>
|
||||
public string Description => Resources.PluginDescription;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the plugin with the given <see cref="PluginInitContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">The <see cref="PluginInitContext"/> for this plugin.</param>
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
_context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateIconPath(_context.API.GetCurrentTheme());
|
||||
|
||||
_settingsList = JsonSettingsListHelper.ReadAllPossibleSettings();
|
||||
_settingsList = UnsupportedSettingsHelper.FilterByBuild(_settingsList);
|
||||
|
||||
TranslationHelper.TranslateAllSettings(_settingsList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a filtered list, based on the given query.
|
||||
/// </summary>
|
||||
/// <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)
|
||||
{
|
||||
return new List<Result>(0);
|
||||
}
|
||||
|
||||
var filteredList = _settingsList
|
||||
.Where(Predicate)
|
||||
.OrderBy(found => found.Name);
|
||||
|
||||
var newList = ResultHelper.GetResultList(filteredList, query.Search, _defaultIconPath);
|
||||
return newList;
|
||||
|
||||
bool Predicate(WindowsSetting found)
|
||||
{
|
||||
if (found.Name.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for Area only by key char
|
||||
if (found.Area.Contains(query.Search.Replace(":", string.Empty), StringComparison.CurrentCultureIgnoreCase)
|
||||
&& query.Search.EndsWith(":"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (found.Area.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(found.AltNames is null))
|
||||
{
|
||||
foreach (var altName in found.AltNames)
|
||||
{
|
||||
if (altName.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list context menu entries for a given <see cref="Result"/> (shown at the right side of the result).
|
||||
/// </summary>
|
||||
/// <param name="selectedResult">The <see cref="Result"/> for the list with context menu entries.</param>
|
||||
/// <returns>A list context menu entries.</returns>
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
return ContextMenuHelper.GetContextMenu(selectedResult, _assemblyName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper method for <see cref="Dispose"/> that dispose additional objects and events form the plugin itself.
|
||||
/// </summary>
|
||||
/// <param name="disposing">Indicate that the plugin is disposed.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposed || !disposing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(_context is null))
|
||||
{
|
||||
_context.API.ThemeChanged -= OnThemeChanged;
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized name.
|
||||
/// </summary>
|
||||
public string GetTranslatedPluginTitle()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized description.
|
||||
/// </summary>
|
||||
public string GetTranslatedPluginDescription()
|
||||
{
|
||||
return Description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change all theme-based elements (typical called when the plugin theme has changed).
|
||||
/// </summary>
|
||||
/// <param name="oldtheme">The old <see cref="Theme"/>.</param>
|
||||
/// <param name="newTheme">The new <see cref="Theme"/>.</param>
|
||||
private void OnThemeChanged(Theme oldtheme, Theme newTheme)
|
||||
{
|
||||
UpdateIconPath(newTheme);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update all icons (typical called when the plugin theme has changed).
|
||||
/// </summary>
|
||||
/// <param name="theme">The new <see cref="Theme"/> for the icons.</param>
|
||||
private void UpdateIconPath(Theme theme)
|
||||
{
|
||||
_defaultIconPath = theme == Theme.Light || theme == Theme.HighContrastWhite
|
||||
? _lightSymbol
|
||||
: _darkSymbol;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user