diff --git a/Plugins/Wox.Plugin.Everything/Main.cs b/Plugins/Wox.Plugin.Everything/Main.cs index dffa1ea87a..b50d92174b 100644 --- a/Plugins/Wox.Plugin.Everything/Main.cs +++ b/Plugins/Wox.Plugin.Everything/Main.cs @@ -13,10 +13,10 @@ namespace Wox.Plugin.Everything { public class Main : IPlugin, IPluginI18n, IContextMenu { - PluginInitContext context; - EverythingAPI api = new EverythingAPI(); - private static List imageExts = new List { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" }; - private static List executableExts = new List { ".exe" }; + private PluginInitContext _context; + private readonly EverythingAPI _api = new EverythingAPI(); + private static readonly List ImageExts = new List { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" }; + private static readonly List ExecutableExts = new List { ".exe" }; public List Query(Query query) { @@ -47,7 +47,7 @@ namespace Wox.Plugin.Everything try { - var searchList = api.Search(keyword, maxCount: ContextMenuStorage.Instance.MaxSearchCount).ToList(); + var searchList = _api.Search(keyword, maxCount: ContextMenuStorage.Instance.MaxSearchCount).ToList(); foreach (var s in searchList) { var path = s.FullPath; @@ -57,7 +57,7 @@ namespace Wox.Plugin.Everything r.IcoPath = GetIconPath(s); r.Action = c => { - context.API.HideApp(); + _context.API.HideApp(); Process.Start(new ProcessStartInfo { FileName = path, @@ -74,7 +74,7 @@ namespace Wox.Plugin.Everything StartEverything(); results.Add(new Result { - Title = context.API.GetTranslation("wox_plugin_everything_is_not_running"), + Title = _context.API.GetTranslation("wox_plugin_everything_is_not_running"), IcoPath = "Images\\warning.png" }); } @@ -82,12 +82,12 @@ namespace Wox.Plugin.Everything { results.Add(new Result { - Title = context.API.GetTranslation("wox_plugin_everything_query_error"), + Title = _context.API.GetTranslation("wox_plugin_everything_query_error"), SubTitle = e.Message, Action = _ => { Clipboard.SetText(e.Message + "\r\n" + e.StackTrace); - context.API.ShowMsg(context.API.GetTranslation("wox_plugin_everything_copied"), null, string.Empty); + _context.API.ShowMsg(_context.API.GetTranslation("wox_plugin_everything_copied"), null, string.Empty); return false; }, IcoPath = "Images\\error.png" @@ -95,7 +95,7 @@ namespace Wox.Plugin.Everything } } - api.Reset(); + _api.Reset(); return results; } @@ -109,11 +109,11 @@ namespace Wox.Plugin.Everything } else if (!string.IsNullOrEmpty(ext)) { - if (imageExts.Contains(ext.ToLower())) + if (ImageExts.Contains(ext.ToLower())) { return "Images\\image.png"; } - else if (executableExts.Contains(ext.ToLower())) + else if (ExecutableExts.Contains(ext.ToLower())) { return s.FullPath; } @@ -130,7 +130,7 @@ namespace Wox.Plugin.Everything List defaultContextMenus = new List(); ContextMenu openFolderContextMenu = new ContextMenu { - Name = context.API.GetTranslation("wox_plugin_everything_open_containing_folder"), + Name = _context.API.GetTranslation("wox_plugin_everything_open_containing_folder"), Command = "explorer.exe", Argument = " /select,\"{path}\"", ImagePath = "Images\\folder.png" @@ -142,7 +142,7 @@ namespace Wox.Plugin.Everything public void Init(PluginInitContext context) { - this.context = context; + _context = context; ContextMenuStorage.Instance.API = context.API; LoadLibrary(Path.Combine( @@ -225,7 +225,7 @@ namespace Wox.Plugin.Everything } catch (Exception e) { - context.API.ShowMsg("Start Everything failed"); + _context.API.ShowMsg("Start Everything failed"); } } @@ -250,8 +250,10 @@ namespace Wox.Plugin.Everything private string GetEverythingPath() { - string everythingFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "PortableEverything"); - return Path.Combine(everythingFolder, "Everything.exe"); + string directory = Path.Combine(_context.CurrentPluginMetadata.PluginDirectory, + "PortableEverything", + "Everything.exe"); + return directory; } public string GetLanguagesFolder() @@ -261,12 +263,12 @@ namespace Wox.Plugin.Everything public string GetTranslatedPluginTitle() { - return context.API.GetTranslation("wox_plugin_everything_plugin_name"); + return _context.API.GetTranslation("wox_plugin_everything_plugin_name"); } public string GetTranslatedPluginDescription() { - return context.API.GetTranslation("wox_plugin_everything_plugin_description"); + return _context.API.GetTranslation("wox_plugin_everything_plugin_description"); } public List LoadContextMenus(Result selectedResult) @@ -296,7 +298,7 @@ namespace Wox.Plugin.Everything } catch { - context.API.ShowMsg(string.Format(context.API.GetTranslation("wox_plugin_everything_canot_start"), record.FullPath), string.Empty, string.Empty); + _context.API.ShowMsg(string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_start"), record.FullPath), string.Empty, string.Empty); return false; } return true; diff --git a/Plugins/Wox.Plugin.WebSearch/WebSearchStorage.cs b/Plugins/Wox.Plugin.WebSearch/WebSearchStorage.cs index 82e1d61356..824ad6e261 100644 --- a/Plugins/Wox.Plugin.WebSearch/WebSearchStorage.cs +++ b/Plugins/Wox.Plugin.WebSearch/WebSearchStorage.cs @@ -18,5 +18,166 @@ namespace Wox.Plugin.WebSearch public string WebSearchSuggestionSource { get; set; } protected override string FileName { get; } = "settings_plugin_websearch"; + + protected override WebSearchStorage LoadDefault() + { + WebSearches = new List(new List() + { + new WebSearch + { + Title = "Google", + ActionKeyword = "g", + IconPath = "Images\\google.png", + Url = "https://www.google.com/search?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Wikipedia", + ActionKeyword = "wiki", + IconPath = "Images\\wiki.png", + Url = "http://en.wikipedia.org/wiki/new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "FindIcon", + ActionKeyword = "findicon", + IconPath = "Images\\pictures.png", + Url = "http://findicons.com/search/new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Facebook", + ActionKeyword = "facebook", + IconPath = "Images\\facebook.png", + Url = "http://www.facebook.com/search/?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Twitter", + ActionKeyword = "twitter", + IconPath = "Images\\twitter.png", + Url = "http://twitter.com/search?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Google Maps", + ActionKeyword = "maps", + IconPath = "Images\\google_maps.png", + Url = "http://maps.google.com/maps?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Google Translate", + ActionKeyword = "translate", + IconPath = "Images\\google_translate.png", + Url = "http://translate.google.com/#auto|en|new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Duckduckgo", + ActionKeyword = "duckduckgo", + IconPath = "Images\\duckduckgo.png", + Url = "https://duckduckgo.com/?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Github", + ActionKeyword = "github", + IconPath = "Images\\github.png", + Url = "https://github.com/search?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Github Gist", + ActionKeyword = "gist", + IconPath = "Images\\gist.png", + Url = "https://gist.github.com/search?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Gmail", + ActionKeyword = "gmail", + IconPath = "Images\\gmail.png", + Url = "https://mail.google.com/mail/ca/u/0/#apps/new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Google Drive", + ActionKeyword = "drive", + IconPath = "Images\\google_drive.png", + Url = "http://drive.google.com/?hl=en&tab=bo#search/new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Wolframalpha", + ActionKeyword = "wolframalpha", + IconPath = "Images\\wolframalpha.png", + Url = "http://www.wolframalpha.com/input/?i=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Stackoverflow", + ActionKeyword = "stackoverflow", + IconPath = "Images\\stackoverflow.png", + Url = "http://stackoverflow.com/search?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "I'm Feeling Lucky", + ActionKeyword = "lucky", + IconPath = "Images\\google.png", + Url = "http://google.com/search?q=new WebSearch {q}&btnI=I", + Enabled = true + }, + new WebSearch + { + Title = "Google Image", + ActionKeyword = "image", + IconPath = "Images\\google.png", + Url = "https://www.google.com/search?q=new WebSearch {q}&tbm=isch", + Enabled = true + }, + new WebSearch + { + Title = "Youtube", + ActionKeyword = "youtube", + IconPath = "Images\\youtube.png", + Url = "http://www.youtube.com/results?search_query=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Bing", + ActionKeyword = "bing", + IconPath = "Images\\bing.png", + Url = "https://www.bing.com/search?q=new WebSearch {q}", + Enabled = true + }, + new WebSearch + { + Title = "Yahoo", + ActionKeyword = "yahoo", + IconPath = "Images\\yahoo.png", + Url = "http://www.search.yahoo.com/search?p=new WebSearch {q}", + Enabled = true + } + }); + + return this; + } } -} +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj index 44ccaff99c..2150e91aab 100644 --- a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj +++ b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj @@ -136,9 +136,6 @@ Designer PreserveNewest - - PreserveNewest - MSBuild:Compile Designer diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 7ccdc60a6e..f3da6bb0ea 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; using System.Threading; using Wox.Core.Resource; using Wox.Core.UserSettings; @@ -19,35 +18,33 @@ namespace Wox.Core.Plugin public static class PluginManager { public const string DirectoryName = "Plugins"; - private static IEnumerable contextMenuPlugins; + private static IEnumerable _contextMenuPlugins; /// /// Directories that will hold Wox plugin directory /// - private static List pluginDirectories = new List(); + private static readonly List PluginDirectories = new List(); public static IEnumerable AllPlugins { get; private set; } - public static List GlobalPlugins { get; } = new List(); - public static Dictionary NonGlobalPlugins { get; set; } = new Dictionary(); + public static readonly List GlobalPlugins = new List(); + + public static readonly Dictionary NonGlobalPlugins = new Dictionary(); private static IEnumerable InstantQueryPlugins { get; set; } public static IPublicAPI API { private set; get; } - public static string PluginDirectory - { - get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), DirectoryName); } - } + public static readonly string PluginDirectory = Path.Combine(WoxDirectroy.Executable, DirectoryName); private static void SetupPluginDirectories() { - pluginDirectories.Add(PluginDirectory); + PluginDirectories.Add(PluginDirectory); MakesurePluginDirectoriesExist(); } private static void MakesurePluginDirectoriesExist() { - foreach (string pluginDirectory in pluginDirectories) + foreach (string pluginDirectory in PluginDirectories) { if (!Directory.Exists(pluginDirectory)) { @@ -73,7 +70,7 @@ namespace Wox.Core.Plugin SetupPluginDirectories(); API = api; - var metadatas = PluginConfig.Parse(pluginDirectories); + var metadatas = PluginConfig.Parse(PluginDirectories); AllPlugins = (new CSharpPluginLoader().LoadPlugin(metadatas)). Concat(new JsonRPCPluginLoader().LoadPlugin(metadatas)); @@ -102,7 +99,7 @@ namespace Wox.Core.Plugin ThreadPool.QueueUserWorkItem(o => { InstantQueryPlugins = GetPluginsForInterface(); - contextMenuPlugins = GetPluginsForInterface(); + _contextMenuPlugins = GetPluginsForInterface(); foreach (var plugin in AllPlugins) { if (IsGlobalPlugin(plugin.Metadata)) @@ -231,7 +228,7 @@ namespace Wox.Core.Plugin public static List GetContextMenusForPlugin(Result result) { - var pluginPair = contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID); + var pluginPair = _contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID); var plugin = (IContextMenu)pluginPair?.Plugin; if (plugin != null) { diff --git a/Wox.Plugin/PluginMetadata.cs b/Wox.Plugin/PluginMetadata.cs index ded0941651..6c6dc5136e 100644 --- a/Wox.Plugin/PluginMetadata.cs +++ b/Wox.Plugin/PluginMetadata.cs @@ -15,10 +15,7 @@ namespace Wox.Plugin public string Website { get; set; } - public string ExecuteFilePath - { - get { return Path.Combine(PluginDirectory, ExecuteFileName); } - } + public string ExecuteFilePath => Path.Combine(PluginDirectory, ExecuteFileName); public string ExecuteFileName { get; set; }