diff --git a/Wox.Infrastructure/Storage/BaseStorage.cs b/Wox.Infrastructure/Storage/BaseStorage.cs index 4e1de3d28b..6b9fd4f89f 100644 --- a/Wox.Infrastructure/Storage/BaseStorage.cs +++ b/Wox.Infrastructure/Storage/BaseStorage.cs @@ -15,6 +15,14 @@ namespace Wox.Infrastructure.Storage private static object locker = new object(); private static T storage; + public event Action AfterLoadConfig; + + protected virtual void OnAfterLoadConfig(T obj) + { + Action handler = AfterLoadConfig; + if (handler != null) handler(obj); + } + protected abstract string ConfigName { get; } public static T Instance @@ -53,6 +61,7 @@ namespace Wox.Infrastructure.Storage try { storage = JsonConvert.DeserializeObject(json); + OnAfterLoadConfig(storage); } catch (Exception) { diff --git a/Wox.Infrastructure/Storage/UserSettings/CustomizedPluginConfig.cs b/Wox.Infrastructure/Storage/UserSettings/CustomizedPluginConfig.cs new file mode 100644 index 0000000000..e7f021843e --- /dev/null +++ b/Wox.Infrastructure/Storage/UserSettings/CustomizedPluginConfig.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Infrastructure.Storage.UserSettings +{ + public class CustomizedPluginConfig + { + public string ID { get; set; } + + public string Name { get; set; } + + public string Actionword { get; set; } + + public bool Disabled { get; set; } + } +} diff --git a/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs b/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs index d9e617e775..ce9acc6208 100644 --- a/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs +++ b/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs @@ -56,6 +56,8 @@ namespace Wox.Infrastructure.Storage.UserSettings [JsonProperty] public List FolderLinks { get; set; } //Aaron + public List CustomizedPluginConfigs { get; set; } + [JsonProperty] public List CustomPluginHotkeys { get; set; } @@ -147,6 +149,7 @@ namespace Wox.Infrastructure.Storage.UserSettings ReplaceWinR = true; WebSearches = LoadDefaultWebSearches(); ProgramSources = LoadDefaultProgramSources(); + CustomizedPluginConfigs = new List(); Hotkey = "Alt + Space"; QueryBoxFont = FontFamily.GenericSansSerif.Name; ResultItemFont = FontFamily.GenericSansSerif.Name; @@ -156,6 +159,13 @@ namespace Wox.Infrastructure.Storage.UserSettings HideWhenDeactive = false; } + protected override void OnAfterLoadConfig(UserSettingStorage storage) + { + if (storage.CustomizedPluginConfigs == null) + { + storage.CustomizedPluginConfigs = new List(); + } + } } public enum OpacityMode diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index 9eb0ebbd0d..5bdad21908 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -50,6 +50,7 @@ + diff --git a/Wox.Plugin.SystemPlugins/BaseSystemPlugin.cs b/Wox.Plugin.SystemPlugins/BaseSystemPlugin.cs index 81ba859a5c..b9bc92c084 100644 --- a/Wox.Plugin.SystemPlugins/BaseSystemPlugin.cs +++ b/Wox.Plugin.SystemPlugins/BaseSystemPlugin.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.Linq; +using Wox.Infrastructure.Storage.UserSettings; namespace Wox.Plugin.SystemPlugins { @@ -6,6 +8,8 @@ namespace Wox.Plugin.SystemPlugins public abstract class BaseSystemPlugin : ISystemPlugin { public string PluginDirectory { get; set; } + + public abstract string ID { get; } public virtual string Name { get { return "System workflow"; } } public virtual string Description { get { return "System workflow"; } } public virtual string IcoPath { get { return null; } } @@ -17,6 +21,11 @@ namespace Wox.Plugin.SystemPlugins public List Query(Query query) { if (string.IsNullOrEmpty(query.RawQuery)) return new List(); + var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == ID); + if (customizedPluginConfig != null && customizedPluginConfig.Disabled) + { + return new List(); + } return QueryInternal(query); } diff --git a/Wox.Plugin.SystemPlugins/CMD/CMD.cs b/Wox.Plugin.SystemPlugins/CMD/CMD.cs index c316ffae81..aeeb8405ae 100644 --- a/Wox.Plugin.SystemPlugins/CMD/CMD.cs +++ b/Wox.Plugin.SystemPlugins/CMD/CMD.cs @@ -148,6 +148,11 @@ namespace Wox.Plugin.SystemPlugins.CMD this.context = context; } + public override string ID + { + get { return "D409510CD0D2481F853690A07E6DC426"; } + } + public override string Name { get { return "Shell"; } diff --git a/Wox.Plugin.SystemPlugins/Calculator.cs b/Wox.Plugin.SystemPlugins/Calculator.cs index e4ddf5ae1c..c1f135482e 100644 --- a/Wox.Plugin.SystemPlugins/Calculator.cs +++ b/Wox.Plugin.SystemPlugins/Calculator.cs @@ -85,6 +85,11 @@ namespace Wox.Plugin.SystemPlugins this.context = context; } + public override string ID + { + get { return "CEA0FDFC6D3B4085823D60DC76F28855"; } + } + public override string Name { get { return "Calculator"; } diff --git a/Wox.Plugin.SystemPlugins/ColorsPlugin.cs b/Wox.Plugin.SystemPlugins/ColorsPlugin.cs index 6525d838b9..d80f685db0 100644 --- a/Wox.Plugin.SystemPlugins/ColorsPlugin.cs +++ b/Wox.Plugin.SystemPlugins/ColorsPlugin.cs @@ -101,6 +101,11 @@ namespace Wox.Plugin.SystemPlugins return string.Format("{0}{1}.png", ColorsDirectory.FullName, name.Substring(1)); } + public override string ID + { + get { return "9B36CE6181FC47FBB597AA2C29CD9B0A"; } + } + public override string Name { get { return "Colors"; } diff --git a/Wox.Plugin.SystemPlugins/Folder/FolderPlugin.cs b/Wox.Plugin.SystemPlugins/Folder/FolderPlugin.cs index 124890587b..edb8dd7a0c 100644 --- a/Wox.Plugin.SystemPlugins/Folder/FolderPlugin.cs +++ b/Wox.Plugin.SystemPlugins/Folder/FolderPlugin.cs @@ -23,7 +23,12 @@ namespace Wox.Plugin.SystemPlugins.Folder { } } - public override string Name { get { return "Folder"; } } + public override string ID + { + get { return "B4D3B69656E14D44865C8D818EAE47C4"; } + } + + public override string Name { get { return "Folder"; } } public override string IcoPath { get { return @"Images\folder.png"; } } #endregion Properties diff --git a/Wox.Plugin.SystemPlugins/ISystemPlugin.cs b/Wox.Plugin.SystemPlugins/ISystemPlugin.cs index cd61777402..de73c5b60e 100644 --- a/Wox.Plugin.SystemPlugins/ISystemPlugin.cs +++ b/Wox.Plugin.SystemPlugins/ISystemPlugin.cs @@ -7,6 +7,7 @@ namespace Wox.Plugin.SystemPlugins { public interface ISystemPlugin : IPlugin { + string ID { get; } string Name { get; } string Description { get; } } diff --git a/Wox.Plugin.SystemPlugins/Program/Programs.cs b/Wox.Plugin.SystemPlugins/Program/Programs.cs index a32e70ab30..aee98f353d 100644 --- a/Wox.Plugin.SystemPlugins/Program/Programs.cs +++ b/Wox.Plugin.SystemPlugins/Program/Programs.cs @@ -140,6 +140,11 @@ namespace Wox.Plugin.SystemPlugins.Program } + public override string ID + { + get { return "791FC278BA414111B8D1886DFE447410"; } + } + public override string Name { get { return "Programs"; } diff --git a/Wox.Plugin.SystemPlugins/Sys.cs b/Wox.Plugin.SystemPlugins/Sys.cs index c06d57a1cf..bf5720ee69 100644 --- a/Wox.Plugin.SystemPlugins/Sys.cs +++ b/Wox.Plugin.SystemPlugins/Sys.cs @@ -118,6 +118,11 @@ namespace Wox.Plugin.SystemPlugins } + public override string ID + { + get { return "CEA08895D2544B019B2E9C5009600DF4"; } + } + public override string Name { get { return "System Commands"; } diff --git a/Wox.Plugin.SystemPlugins/ThirdpartyPluginIndicator.cs b/Wox.Plugin.SystemPlugins/ThirdpartyPluginIndicator.cs index de6595f60b..b5c817bda8 100644 --- a/Wox.Plugin.SystemPlugins/ThirdpartyPluginIndicator.cs +++ b/Wox.Plugin.SystemPlugins/ThirdpartyPluginIndicator.cs @@ -22,6 +22,12 @@ namespace Wox.Plugin.SystemPlugins if (metadata.ActionKeyword.StartsWith(query.RawQuery)) { PluginMetadata metadataCopy = metadata; + var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadataCopy.ID); + if (customizedPluginConfig != null && customizedPluginConfig.Disabled) + { + continue; + } + Result result = new Result { Title = metadata.ActionKeyword, @@ -61,6 +67,11 @@ namespace Wox.Plugin.SystemPlugins } + public override string ID + { + get { return "6A122269676E40EB86EB543B945932B9"; } + } + public override string Name { get { return "Third-party Plugin Indicator"; } diff --git a/Wox.Plugin.SystemPlugins/UrlPlugin.cs b/Wox.Plugin.SystemPlugins/UrlPlugin.cs index bfe44421a2..77034dcee6 100644 --- a/Wox.Plugin.SystemPlugins/UrlPlugin.cs +++ b/Wox.Plugin.SystemPlugins/UrlPlugin.cs @@ -31,6 +31,11 @@ namespace Wox.Plugin.SystemPlugins return new List(0); } + public override string ID + { + get { return "0308FD86DE0A4DEE8D62B9B535370992"; } + } + public override string Name { get { return "URL handler"; } } public override string Description { get { return "Provide Opening the typed URL from Wox."; } } public override string IcoPath { get { return "Images/url2.png"; } } diff --git a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchPlugin.cs b/Wox.Plugin.SystemPlugins/WebSearch/WebSearchPlugin.cs index c9e250fcc0..e2c69c47f3 100644 --- a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchPlugin.cs +++ b/Wox.Plugin.SystemPlugins/WebSearch/WebSearchPlugin.cs @@ -81,6 +81,11 @@ namespace Wox.Plugin.SystemPlugins UserSettingStorage.Instance.WebSearches = UserSettingStorage.Instance.LoadDefaultWebSearches(); } + public override string ID + { + get { return "565B73353DBF4806919830B9202EE3BF"; } + } + public override string Name { get { return "Web Searches"; } diff --git a/Wox/Commands/PluginCommand.cs b/Wox/Commands/PluginCommand.cs index 5770188ad4..1c25e5d5ad 100644 --- a/Wox/Commands/PluginCommand.cs +++ b/Wox/Commands/PluginCommand.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using Python.Runtime; using Wox.Helper; +using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; using Wox.PluginLoader; @@ -19,6 +20,13 @@ namespace Wox.Commands PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName); if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword)) { + var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == thirdPlugin.Metadata.ID); + if (customizedPluginConfig != null && customizedPluginConfig.Disabled) + { + UpdateResultView(null); + return; + } + if (thirdPlugin.Metadata.Language == AllowedLanguage.Python) { SwitchPythonEnv(thirdPlugin); @@ -29,12 +37,15 @@ namespace Wox.Commands { thirdPlugin.InitContext.PushResults = (qu, r) => { - r.ForEach(o => + if (r != null) { - o.PluginDirectory = thirdPlugin.Metadata.PluginDirecotry; - o.OriginQuery = qu; - }); - UpdateResultView(r); + r.ForEach(o => + { + o.PluginDirectory = thirdPlugin.Metadata.PluginDirecotry; + o.OriginQuery = qu; + }); + UpdateResultView(r); + } }; List results = thirdPlugin.Plugin.Query(q) ?? new List(); thirdPlugin.InitContext.PushResults(q, results); diff --git a/Wox/Commands/SystemCommand.cs b/Wox/Commands/SystemCommand.cs index 30816701bf..e38a5ca12b 100644 --- a/Wox/Commands/SystemCommand.cs +++ b/Wox/Commands/SystemCommand.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; +using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; using Wox.PluginLoader; @@ -15,11 +16,11 @@ namespace Wox.Commands foreach (PluginPair pair in Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System)) { PluginPair pair1 = pair; + ThreadPool.QueueUserWorkItem(state => { pair1.InitContext.PushResults = (q, r) => { - if (r == null || r.Count == 0) return; foreach (Result result in r) { result.PluginDirectory = pair1.Metadata.PluginDirecotry; diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index bddb4f426e..c83d82073d 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -246,9 +246,9 @@ namespace Wox { // didn't. if (resultCtrl.Dirty) resultCtrl.Clear(); }, TimeSpan.FromMilliseconds(100), null); + queryHasReturn = false; var q = new Query(lastQuery); CommandFactory.DispatchCommand(q); - queryHasReturn = false; if (Plugins.HitThirdpartyKeyword(q)) { Dispatcher.DelayInvoke("ShowProgressbar", originQuery => { if (!queryHasReturn && originQuery == lastQuery) { @@ -455,10 +455,10 @@ namespace Wox { } public void OnUpdateResultView(List list) { - if (list == null) return; + queryHasReturn = true; + progressBar.Dispatcher.Invoke(new Action(StopProgress)); + if (list == null || list.Count == 0) return; - queryHasReturn = true; - progressBar.Dispatcher.Invoke(new Action(StopProgress)); if (list.Count > 0) { //todo:this should be opened to users, it's their choice to use it or not in their workflows diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index a2fa12023c..d79dc85900 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -129,7 +129,7 @@ - Enable + Disable diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 5b8c0a91a8..97a0375dca 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -15,6 +15,7 @@ using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; using Wox.Helper; using Wox.Plugin.SystemPlugins; +using Wox.PluginLoader; using Application = System.Windows.Forms.Application; using File = System.IO.File; using MessageBox = System.Windows.MessageBox; @@ -422,6 +423,8 @@ namespace Wox { ISettingProvider provider = null; var pair = lbPlugins.SelectedItem as PluginPair; + string pluginId = string.Empty; + if (pair != null) { //third-party plugin @@ -434,6 +437,7 @@ namespace Wox pluginAuthor.Text = "Author: " + pair.Metadata.Author; pluginWebsite.Text = "Website: " + pair.Metadata.Website; pluginSubTitle.Text = pair.Metadata.Description; + pluginId = pair.Metadata.ID; SyntaxSugars.CallOrRescueDefault( () => pluginIcon.Source = (ImageSource)new ImagePathConverter().Convert( @@ -452,6 +456,7 @@ namespace Wox if (sys != null) { pluginTitle.Text = sys.Name; + pluginId = sys.ID; pluginSubTitle.Text = sys.Description; pluginAuthor.Visibility = Visibility.Collapsed; pluginActionKeyword.Visibility = Visibility.Collapsed; @@ -466,7 +471,10 @@ namespace Wox } } - this.PluginContentPanel.Content = null; + var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginId); + cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled; + + PluginContentPanel.Content = null; if (provider != null) { Control control = null; @@ -482,5 +490,47 @@ namespace Wox // featureControls // throw new NotImplementedException(); } + + private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e) + { + CheckBox cbDisabled = e.Source as CheckBox; + if (cbDisabled == null) return; + + var pair = lbPlugins.SelectedItem as PluginPair; + var id = string.Empty; + var name = string.Empty; + if (pair != null) + { + //third-party plugin + id = pair.Metadata.ID; + name = pair.Metadata.Name; + } + else + { + //system plugin + var sys = lbPlugins.SelectedItem as BaseSystemPlugin; + if (sys != null) + { + id = sys.ID; + name = sys.Name; + } + } + var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == id); + if (customizedPluginConfig == null) + { + UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig() + { + Disabled = cbDisabled.IsChecked ?? true, + ID = id, + Name = name, + Actionword = string.Empty + }); + } + else + { + customizedPluginConfig.Disabled = cbDisabled.IsChecked ?? true; + } + UserSettingStorage.Instance.Save(); + } } }