diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index 857e87d013..15745c58c1 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; -using System.Windows; using System.Windows.Controls; using Wox.Infrastructure; using Wox.Infrastructure.Logger; @@ -16,7 +15,7 @@ namespace Wox.Plugin.Program public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable { private static Win32[] _win32s = { }; - private static UWP[] _uwps = { }; + private static UWP.Application[] _uwps = { }; private PluginInitContext _context; @@ -50,18 +49,16 @@ namespace Wox.Plugin.Program public List Query(Query query) { var results1 = _win32s.AsParallel() - .Where(p => Score(p, query.Search) > 0) - .Select(ResultFromProgram); - + .Where(p => Score(p, query.Search) > 0) + .Select(ResultFromWin32); var results2 = _uwps.AsParallel() - .Where(u => Score(u, query.Search) > 0) - .Select(ResultFromUWPApp); + .Where(app => Score(app, query.Search) > 0) + .Select(ResultFromUWP); var result = results1.Concat(results2).ToList(); - return result; } - public Result ResultFromProgram(Win32 p) + public Result ResultFromWin32(Win32 p) { var result = new Result { @@ -83,15 +80,14 @@ namespace Wox.Plugin.Program }; return result; } - public Result ResultFromUWPApp(UWP uwp) + public Result ResultFromUWP(UWP.Application app) { - var app = uwp.Apps[0]; var result = new Result { Title = app.DisplayName, SubTitle = $"Windows Store app: {app.Description}", Icon = app.Logo, - Score = uwp.Score, + Score = app.Score, ContextData = app, Action = e => { @@ -113,11 +109,11 @@ namespace Wox.Plugin.Program return score; } - private int Score(UWP app, string query) + private int Score(UWP.Application app, string query) { - var score1 = StringMatcher.Score(app.Apps[0].DisplayName, query); - var score2 = StringMatcher.ScoreForPinyin(app.Apps[0].DisplayName, query); - var score3 = StringMatcher.Score(app.Apps[0].Description, query); + var score1 = StringMatcher.Score(app.DisplayName, query); + var score2 = StringMatcher.ScoreForPinyin(app.DisplayName, query); + var score3 = StringMatcher.Score(app.Description, query); var score = new[] { score1, score2, score3 }.Max(); app.Score = score; return score; diff --git a/Plugins/Wox.Plugin.Program/Programs/UWP.cs b/Plugins/Wox.Plugin.Program/Programs/UWP.cs index e7ca829b3d..febb1d378a 100644 --- a/Plugins/Wox.Plugin.Program/Programs/UWP.cs +++ b/Plugins/Wox.Plugin.Program/Programs/UWP.cs @@ -35,12 +35,6 @@ namespace Wox.Plugin.Program.Programs public Application[] Apps { get; set; } public Package Package { get; } - public int Score { get; set; } - - public UWP() - { - Apps = new Application[] { }; - } public UWP(Package package) { Package = package; @@ -122,32 +116,32 @@ namespace Wox.Plugin.Program.Programs }).ToArray(); } - public static UWP[] All() + public static Application[] All() { var windows10 = new Version(10, 0); var support = Environment.OSVersion.Version.Major >= windows10.Major; if (support) { - var packages = CurrentUserPackages().AsParallel().Select(p => + var application = CurrentUserPackages().AsParallel().SelectMany(p => { try { var u = new UWP(p); - return u; + return u.Apps; } catch (Exception e) { // if there are errors, just ignore it and continue var message = $"Can't parse {p.Id.Name}: {e.Message}"; Log.Error(message); - return new UWP(); + return new Application[] { }; } - }).Where(u => u.Apps.Length > 0); - return packages.ToArray(); + }); + return application.ToArray(); } else { - return new UWP[] { }; + return new Application[] { }; } } @@ -210,6 +204,7 @@ namespace Wox.Plugin.Program.Programs public string PublisherDisplayName { get; set; } public string BackgroundColor { get; set; } public string LogoPath { get; set; } + public int Score { get; set; } // todo: wrap with try exception public void Launch()