mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 01:08:18 +08:00
Refactoring directory path for plugin
This commit is contained in:
parent
ec40956721
commit
8ee94d75ca
@ -13,10 +13,10 @@ namespace Wox.Plugin.Everything
|
||||
{
|
||||
public class Main : IPlugin, IPluginI18n, IContextMenu
|
||||
{
|
||||
PluginInitContext context;
|
||||
EverythingAPI api = new EverythingAPI();
|
||||
private static List<string> imageExts = new List<string> { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" };
|
||||
private static List<string> executableExts = new List<string> { ".exe" };
|
||||
private PluginInitContext _context;
|
||||
private readonly EverythingAPI _api = new EverythingAPI();
|
||||
private static readonly List<string> ImageExts = new List<string> { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" };
|
||||
private static readonly List<string> ExecutableExts = new List<string> { ".exe" };
|
||||
|
||||
public List<Result> 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<ContextMenu> defaultContextMenus = new List<ContextMenu>();
|
||||
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<Result> 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;
|
||||
|
@ -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<WebSearch>(new List<WebSearch>()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -136,9 +136,6 @@
|
||||
<SubType>Designer</SubType>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="setting.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Page Include="WebSearchesSetting.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
|
@ -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<PluginPair> contextMenuPlugins;
|
||||
private static IEnumerable<PluginPair> _contextMenuPlugins;
|
||||
|
||||
/// <summary>
|
||||
/// Directories that will hold Wox plugin directory
|
||||
/// </summary>
|
||||
private static List<string> pluginDirectories = new List<string>();
|
||||
private static readonly List<string> PluginDirectories = new List<string>();
|
||||
|
||||
public static IEnumerable<PluginPair> AllPlugins { get; private set; }
|
||||
|
||||
public static List<PluginPair> GlobalPlugins { get; } = new List<PluginPair>();
|
||||
public static Dictionary<string, PluginPair> NonGlobalPlugins { get; set; } = new Dictionary<string, PluginPair>();
|
||||
public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
|
||||
|
||||
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
|
||||
|
||||
private static IEnumerable<PluginPair> 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<PythonPlugin>().LoadPlugin(metadatas));
|
||||
|
||||
@ -102,7 +99,7 @@ namespace Wox.Core.Plugin
|
||||
ThreadPool.QueueUserWorkItem(o =>
|
||||
{
|
||||
InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>();
|
||||
contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
||||
_contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
||||
foreach (var plugin in AllPlugins)
|
||||
{
|
||||
if (IsGlobalPlugin(plugin.Metadata))
|
||||
@ -231,7 +228,7 @@ namespace Wox.Core.Plugin
|
||||
|
||||
public static List<Result> 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)
|
||||
{
|
||||
|
@ -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; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user