diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsSettings.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsSettings.cs index bf326221f9..1ec7fd48b0 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsSettings.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsSettings.cs @@ -48,6 +48,10 @@ public class AllAppsSettings : JsonSettingsManager, ISettingsInterface public bool EnablePathEnvironmentVariableSource => _enablePathEnvironmentVariableSource.Value; + public bool HideGenericFilesOnDesktop => _hideGenericFilesOnDesktop.Value; + + public bool HideGenericFilesInStartMenu => _hideGenericFilesInStartMenu.Value; + private readonly ChoiceSetSetting _searchResultLimitSource = new( Namespaced(nameof(SearchResultLimit)), Resources.limit_fallback_results_source, @@ -80,6 +84,18 @@ public class AllAppsSettings : JsonSettingsManager, ISettingsInterface string.Empty, false); // this one is very VERY noisy + private readonly ToggleSetting _hideGenericFilesOnDesktop = new( + Namespaced(nameof(HideGenericFilesOnDesktop)), + " " + Resources.hide_generic_files_on_desktop, + string.Empty, + true); + + private readonly ToggleSetting _hideGenericFilesInStartMenu = new( + Namespaced(nameof(HideGenericFilesInStartMenu)), + " " + Resources.hide_generic_files_in_start_menu, + string.Empty, + false); + public double MinScoreThreshold { get; set; } = 0.75; internal const char SuffixSeparator = ';'; @@ -98,7 +114,9 @@ public class AllAppsSettings : JsonSettingsManager, ISettingsInterface FilePath = SettingsJsonPath(); Settings.Add(_enableStartMenuSource); + Settings.Add(_hideGenericFilesInStartMenu); Settings.Add(_enableDesktopSource); + Settings.Add(_hideGenericFilesOnDesktop); Settings.Add(_enableRegistrySource); Settings.Add(_enablePathEnvironmentVariableSource); Settings.Add(_searchResultLimitSource); diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs index 1de01b408e..3512de5921 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs @@ -409,9 +409,37 @@ public class Win32Program : IProgram program.Description = info.FileDescription; } } + + if (program.AppType is ApplicationType.GenericFile or ApplicationType.Folder) + { + var hideNonAppsOnDesktop = AllAppsSettings.Instance.HideGenericFilesOnDesktop; + var hideNonAppsInStartMenu = AllAppsSettings.Instance.HideGenericFilesInStartMenu; + + var lnk = program.LnkFilePath; + if (!string.IsNullOrEmpty(lnk)) + { + var isDesktop = StartsWithFolder(lnk, Environment.SpecialFolder.Desktop) || + StartsWithFolder(lnk, Environment.SpecialFolder.CommonDesktopDirectory); + + var isStartMenu = StartsWithFolder(lnk, Environment.SpecialFolder.StartMenu) || + StartsWithFolder(lnk, Environment.SpecialFolder.CommonStartMenu); + + if ((isDesktop && hideNonAppsOnDesktop) || (isStartMenu && hideNonAppsInStartMenu)) + { + program.Enabled = false; + } + } + } } return program; + + static bool StartsWithFolder(string path, Environment.SpecialFolder folder) + { + var folderPath = Environment.GetFolderPath(folder); + return !string.IsNullOrEmpty(folderPath) + && path.StartsWith(folderPath, StringComparison.OrdinalIgnoreCase); + } } catch (System.IO.FileLoadException e) { diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs index 9fdf833b0a..7d51108ba8 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -141,6 +141,24 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties { } } + /// + /// Looks up a localized string similar to Hide shortcuts to non-executable files in Start menu. + /// + internal static string hide_generic_files_in_start_menu { + get { + return ResourceManager.GetString("hide_generic_files_in_start_menu", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Hide shortcuts to non-executable files on Desktop. + /// + internal static string hide_generic_files_on_desktop { + get { + return ResourceManager.GetString("hide_generic_files_on_desktop", resourceCulture); + } + } + /// /// Looks up a localized string similar to Installed apps. /// diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx index 758c61e20f..52aba3fb4d 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Properties/Resources.resx @@ -234,4 +234,10 @@ Unlimited + + Hide shortcuts to non-executable files on Desktop + + + Hide shortcuts to non-executable files in Start menu + \ No newline at end of file