From 4a6242b3a06f1995fade1e8913407300abe90d4b Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 8 Sep 2019 22:18:55 +1000 Subject: [PATCH] Add initial disable program code --- Plugins/Wox.Plugin.Program/Main.cs | 8 +++---- Plugins/Wox.Plugin.Program/Programs/UWP.cs | 4 ++++ Plugins/Wox.Plugin.Program/Programs/Win32.cs | 4 +++- .../Views/Commands/ProgramSettingDisplay.cs | 23 +++++++++++++++++++ .../Views/Models/ProgramSource.cs | 18 +++++++++++++++ 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 Plugins/Wox.Plugin.Program/Views/Models/ProgramSource.cs diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index f3321e9dc8..571217ae34 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -17,14 +17,14 @@ namespace Wox.Plugin.Program public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable { private static readonly object IndexLock = new object(); - private static Win32[] _win32s; - private static UWP.Application[] _uwps; + internal static Win32[] _win32s { get; set; } + internal static UWP.Application[] _uwps { get; set; } + internal static Settings _settings { get; set; } private static PluginInitContext _context; private static BinaryStorage _win32Storage; - private static BinaryStorage _uwpStorage; - private static Settings _settings; + private static BinaryStorage _uwpStorage; private readonly PluginJsonStorage _settingsStorage; public Main() diff --git a/Plugins/Wox.Plugin.Program/Programs/UWP.cs b/Plugins/Wox.Plugin.Program/Programs/UWP.cs index d270aef859..1bbd73764e 100644 --- a/Plugins/Wox.Plugin.Program/Programs/UWP.cs +++ b/Plugins/Wox.Plugin.Program/Programs/UWP.cs @@ -248,6 +248,8 @@ namespace Wox.Plugin.Program.Programs public string UserModelId { get; set; } public string BackgroundColor { get; set; } + public bool Enabled { get; set; } + public string LogoUri { get; set; } public string LogoPath { get; set; } public UWP Package { get; set; } @@ -344,6 +346,8 @@ namespace Wox.Plugin.Program.Programs Description = ResourceFromPri(package.FullName, Description); LogoUri = LogoUriFromManifest(manifestApp); LogoPath = LogoPathFromUri(LogoUri); + + Enabled = true; } internal string ResourceFromPri(string packageFullName, string resourceReference) diff --git a/Plugins/Wox.Plugin.Program/Programs/Win32.cs b/Plugins/Wox.Plugin.Program/Programs/Win32.cs index 855e1f4a43..535e40c105 100644 --- a/Plugins/Wox.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Wox.Plugin.Program/Programs/Win32.cs @@ -24,6 +24,7 @@ namespace Wox.Plugin.Program.Programs public string ExecutableName { get; set; } public string Description { get; set; } public bool Valid { get; set; } + public bool Enabled { get; set; } private const string ShortcutExtension = "lnk"; private const string ApplicationReferenceExtension = "appref-ms"; @@ -129,7 +130,8 @@ namespace Wox.Plugin.Program.Programs FullPath = path, ParentDirectory = Directory.GetParent(path).FullName, Description = string.Empty, - Valid = true + Valid = true, + Enabled = true }; return p; } diff --git a/Plugins/Wox.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Wox.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs index 9b27474fc2..aa6f415949 100644 --- a/Plugins/Wox.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs +++ b/Plugins/Wox.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs @@ -28,5 +28,28 @@ namespace Wox.Plugin.Program.Views.Commands .ToList() .ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.DisplayName, Location = t1.Package.Location, Enabled = t1.Enabled })); } + + internal static void DisableProgramSources(this List listToUpdate, List selectedprogramSourcesToDisable) + { + ProgramSetting.ProgramSettingDisplayList + .Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.Location && t1.Enabled)) + .ToList() + .ForEach(t1 => t1.Enabled = false); + + Main._win32s + .Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.ParentDirectory && t1.Enabled)) + .ToList() + .ForEach(t1 => t1.Enabled = false); + + Main._uwps + .Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.DisplayName && x.Location == t1.Package.Location && t1.Enabled)) + .ToList() + .ForEach(t1 => t1.Enabled = false); + + Main._settings.ProgramSources + .Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.Location && t1.Enabled)) + .ToList() + .ForEach(t1 => t1.Enabled = false); + } } } diff --git a/Plugins/Wox.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Wox.Plugin.Program/Views/Models/ProgramSource.cs new file mode 100644 index 0000000000..9a5c7f4f85 --- /dev/null +++ b/Plugins/Wox.Plugin.Program/Views/Models/ProgramSource.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wox.Plugin.Program.Views.Models +{ + public class ProgramSource + { + private string name; + + public string Location { get; set; } + public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; } + public bool Enabled { get; set; } = true; + } +}