From f91f591e76e2ffc72fbd238014fea496a4b573a3 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 13 Feb 2025 16:30:08 -0600 Subject: [PATCH] Add settings for All Apps (#424) Expose a couple of the settings for apps as actual settings in the settings UI --- .../AllAppsCommandProvider.cs | 1 + .../AllAppsSettings.cs | 65 +++++++++++++++++-- .../Properties/Resources.Designer.cs | 36 ++++++++++ .../Properties/Resources.resx | 17 +++-- 4 files changed, 110 insertions(+), 9 deletions(-) diff --git a/src/modules/cmdpal/Exts/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs b/src/modules/cmdpal/Exts/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs index f9ad7bde46..c7d253b39e 100644 --- a/src/modules/cmdpal/Exts/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs +++ b/src/modules/cmdpal/Exts/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs @@ -20,6 +20,7 @@ public partial class AllAppsCommandProvider : CommandProvider Id = "AllApps"; DisplayName = Resources.installed_apps; Icon = new IconInfo("\ue71d"); + Settings = AllAppsSettings.Instance.Settings; _listItem = new(Page) { Subtitle = Resources.search_installed_apps }; } diff --git a/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/AllAppsSettings.cs b/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/AllAppsSettings.cs index 2f2724af1f..4a14804ecc 100644 --- a/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/AllAppsSettings.cs +++ b/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/AllAppsSettings.cs @@ -4,12 +4,19 @@ using System; using System.Collections.Generic; +using System.IO; using Microsoft.CmdPal.Ext.Apps.Programs; +using Microsoft.CmdPal.Ext.Apps.Properties; +using Microsoft.CommandPalette.Extensions.Toolkit; namespace Microsoft.CmdPal.Ext.Apps; -public class AllAppsSettings +public class AllAppsSettings : JsonSettingsManager { + private static readonly string _namespace = "apps"; + + private static string Namespaced(string propertyName) => $"{_namespace}.{propertyName}"; + #pragma warning disable SA1401 // Fields should be private internal static AllAppsSettings Instance = new(); #pragma warning restore SA1401 // Fields should be private @@ -24,15 +31,63 @@ public class AllAppsSettings public List RunCommandSuffixes { get; set; } = new List() { "bat", "appref-ms", "exe", "lnk", "url", "cpl", "msc" }; - public bool EnableStartMenuSource { get; set; } = true; + public bool EnableStartMenuSource => _enableStartMenuSource.Value; - public bool EnableDesktopSource { get; set; } = true; + public bool EnableDesktopSource => _enableDesktopSource.Value; - public bool EnableRegistrySource { get; set; } = true; + public bool EnableRegistrySource => _enableRegistrySource.Value; - public bool EnablePathEnvironmentVariableSource { get; set; } = true; + public bool EnablePathEnvironmentVariableSource => _enablePathEnvironmentVariableSource.Value; + + private readonly ToggleSetting _enableStartMenuSource = new( + Namespaced(nameof(EnableStartMenuSource)), + Resources.enable_start_menu_source, + Resources.enable_start_menu_source, + true); + + private readonly ToggleSetting _enableDesktopSource = new( + Namespaced(nameof(EnableDesktopSource)), + Resources.enable_desktop_source, + Resources.enable_desktop_source, + true); + + private readonly ToggleSetting _enableRegistrySource = new( + Namespaced(nameof(EnableRegistrySource)), + Resources.enable_registry_source, + Resources.enable_registry_source, + false); // This one is very noisy + + private readonly ToggleSetting _enablePathEnvironmentVariableSource = new( + Namespaced(nameof(EnablePathEnvironmentVariableSource)), + Resources.enable_path_environment_variable_source, + Resources.enable_path_environment_variable_source, + true); public double MinScoreThreshold { get; set; } = 0.75; internal const char SuffixSeparator = ';'; + + internal static string SettingsJsonPath() + { + var directory = Utilities.BaseSettingsPath("Microsoft.CmdPal"); + Directory.CreateDirectory(directory); + + // now, the state is just next to the exe + return Path.Combine(directory, "settings.json"); + } + + public AllAppsSettings() + { + FilePath = SettingsJsonPath(); + + Settings.Add(_enableStartMenuSource); + Settings.Add(_enableDesktopSource); + Settings.Add(_enableRegistrySource); + Settings.Add(_enablePathEnvironmentVariableSource); + + // Load settings from file upon initialization + LoadSettings(); + + Settings.SettingsChanged += (s, a) => this.SaveSettings(); + } } diff --git a/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs b/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs index 6bf34fc0eb..8d7c3b3147 100644 --- a/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs +++ b/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs @@ -78,6 +78,42 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties { } } + /// + /// Looks up a localized string similar to Include apps found on the desktop. + /// + internal static string enable_desktop_source { + get { + return ResourceManager.GetString("enable_desktop_source", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Include apps anywhere on the %PATH%. + /// + internal static string enable_path_environment_variable_source { + get { + return ResourceManager.GetString("enable_path_environment_variable_source", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Include apps registered in the Registry. + /// + internal static string enable_registry_source { + get { + return ResourceManager.GetString("enable_registry_source", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Include apps found in the Start Menu. + /// + internal static string enable_start_menu_source { + get { + return ResourceManager.GetString("enable_start_menu_source", resourceCulture); + } + } + /// /// Looks up a localized string similar to File. /// diff --git a/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx b/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx index c2e0f04551..7707b0a207 100644 --- a/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx +++ b/src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx @@ -59,10 +59,7 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - + @@ -172,4 +169,16 @@ Run as different user + + Include apps found in the Start Menu + + + Include apps found on the desktop + + + Include apps registered in the Registry + + + Include apps anywhere on the %PATH% + \ No newline at end of file