This commit is contained in:
bao-qian
2016-04-22 22:42:26 +01:00
parent 03051a95cf
commit 681f57f703
3 changed files with 25 additions and 23 deletions

View File

@@ -7,14 +7,14 @@ using Wox.Infrastructure;
namespace Wox.Plugin.ControlPanel namespace Wox.Plugin.ControlPanel
{ {
public class ControlPanel : IPlugin,IPluginI18n public class ControlPanel : IPlugin, IPluginI18n
{ {
private PluginInitContext context; private PluginInitContext context;
private List<ControlPanelItem> controlPanelItems = new List<ControlPanelItem>(); private List<ControlPanelItem> controlPanelItems = new List<ControlPanelItem>();
private string iconFolder; private string iconFolder;
private string fileType; private string fileType;
public void Init(PluginInitContext context) public void Init(PluginInitContext context)
{ {
this.context = context; this.context = context;
controlPanelItems = ControlPanelList.Create(48); controlPanelItems = ControlPanelList.Create(48);
@@ -46,25 +46,27 @@ namespace Wox.Plugin.ControlPanel
var fuzzyMather = FuzzyMatcher.Create(myQuery); var fuzzyMather = FuzzyMatcher.Create(myQuery);
if (MatchProgram(item, fuzzyMather)) if (MatchProgram(item, fuzzyMather))
{ {
results.Add(new Result var result = new Result
{ {
Title = item.LocalizedString, Title = item.LocalizedString,
SubTitle = item.InfoTip, SubTitle = item.InfoTip,
Score = item.Score, Score = item.Score,
IcoPath = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, @"Images\\ControlPanelIcons\\" + item.GUID + fileType), IcoPath = Path.Combine(context.CurrentPluginMetadata.PluginDirectory,
@"Images\\ControlPanelIcons\\" + item.GUID + fileType),
Action = e => Action = e =>
{
try
{ {
Process.Start(item.ExecutablePath); try
{
Process.Start(item.ExecutablePath);
}
catch (Exception)
{
//Silently Fail for now.. todo
} }
catch (Exception) return true;
{
//Silently Fail for now..
} }
return true; };
} results.Add(result);
});
} }
} }

View File

@@ -13,7 +13,8 @@ namespace Wox.Converters
{ {
return null; return null;
} }
return App.ImageLoader.Load(value.ToString()); var image = App.ImageLoader.Load(value.ToString());
return image;
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

View File

@@ -16,7 +16,7 @@ namespace Wox.ImageLoader
{ {
public class ImageLoader public class ImageLoader
{ {
private readonly ConcurrentDictionary<string, ImageSource> ImageSources = new ConcurrentDictionary<string, ImageSource>(); private readonly ConcurrentDictionary<string, ImageSource> _imageSources = new ConcurrentDictionary<string, ImageSource>();
private readonly List<string> ImageExts = new List<string> private readonly List<string> ImageExts = new List<string>
{ {
@@ -40,7 +40,7 @@ namespace Wox.ImageLoader
}; };
private readonly ImageCache _cache; private readonly ImageCache _cache;
private readonly BinaryStorage<ImageCache> _storage; private readonly BinaryStorage<ImageCache> _storage;
public ImageLoader() public ImageLoader()
{ {
@@ -74,7 +74,7 @@ namespace Wox.ImageLoader
{ {
Stopwatch.Debug($"Preload {_cache.TopUsedImages.Count} images", () => Stopwatch.Debug($"Preload {_cache.TopUsedImages.Count} images", () =>
{ {
_cache.TopUsedImages.AsParallel().Where(i => !ImageSources.ContainsKey(i.Key)).ForAll(i => _cache.TopUsedImages.AsParallel().Where(i => !_imageSources.ContainsKey(i.Key)).ForAll(i =>
{ {
var img = Load(i.Key, false); var img = Load(i.Key, false);
if (img != null) if (img != null)
@@ -84,8 +84,7 @@ namespace Wox.ImageLoader
// this line made it possible // this line made it possible
// should be changed the Dispatcher.InvokeAsync in the future // should be changed the Dispatcher.InvokeAsync in the future
img.Freeze(); img.Freeze();
_imageSources[i.Key] = img;
ImageSources[i.Key] = img;
} }
}); });
}); });
@@ -104,9 +103,9 @@ namespace Wox.ImageLoader
} }
if (ImageSources.ContainsKey(path)) if (_imageSources.ContainsKey(path))
{ {
img = ImageSources[path]; img = _imageSources[path];
} }
else else
{ {
@@ -127,9 +126,9 @@ namespace Wox.ImageLoader
if (img != null && addToCache) if (img != null && addToCache)
{ {
if (!ImageSources.ContainsKey(path)) if (!_imageSources.ContainsKey(path))
{ {
ImageSources[path] = img; _imageSources[path] = img;
} }
} }
} }