Skip to content

Commit

Permalink
add settings for All Apps
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii committed Feb 13, 2025
1 parent cd5a541 commit 34ca19f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public AllAppsCommandProvider()
Id = "AllApps";
DisplayName = Resources.installed_apps;
Icon = new IconInfo("\ue71d");
Settings = AllAppsSettings.Instance.Settings;

_listItem = new(Page) { Subtitle = Resources.search_installed_apps };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,15 +31,63 @@ public class AllAppsSettings

public List<string> RunCommandSuffixes { get; set; } = new List<string>() { "bat", "appref-ms", "exe", "lnk", "url", "cpl", "msc" };

public bool EnableStartMenuSource { get; set; } = true;
public bool EnableStartMenuSource => _enableStartMenuSource.Value;

public bool EnableDesktopSource => _enableDesktopSource.Value;

public bool EnableRegistrySource => _enableRegistrySource.Value;

public bool EnablePathEnvironmentVariableSource => _enablePathEnvironmentVariableSource.Value;

private readonly ToggleSetting _enableStartMenuSource = new(
Namespaced(nameof(EnableStartMenuSource)),
Resources.enable_start_menu_source,
Resources.enable_start_menu_source,
true);

public bool EnableDesktopSource { get; set; } = true;
private readonly ToggleSetting _enableDesktopSource = new(
Namespaced(nameof(EnableDesktopSource)),
Resources.enable_desktop_source,
Resources.enable_desktop_source,
true);

public bool EnableRegistrySource { get; set; } = true;
private readonly ToggleSetting _enableRegistrySource = new(
Namespaced(nameof(EnableRegistrySource)),
Resources.enable_registry_source,
Resources.enable_registry_source,
false); // This one is very noisy

public bool EnablePathEnvironmentVariableSource { get; set; } = true;
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();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root"
xmlns=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
Expand Down Expand Up @@ -172,4 +169,16 @@
<data name="run_as_different_user" xml:space="preserve">
<value>Run as different user</value>
</data>
<data name="enable_start_menu_source" xml:space="preserve">
<value>Include apps found in the Start Menu</value>
</data>
<data name="enable_desktop_source" xml:space="preserve">
<value>Include apps found on the desktop</value>
</data>
<data name="enable_registry_source" xml:space="preserve">
<value>Include apps registered in the Registry</value>
</data>
<data name="enable_path_environment_variable_source" xml:space="preserve">
<value>Include apps anywhere on the %PATH%</value>
</data>
</root>

0 comments on commit 34ca19f

Please sign in to comment.