mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 19:19:23 +08:00
Fix multi application uwp package #198
This commit is contained in:
parent
9dc7142e4a
commit
fe85ce5885
@ -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;
|
||||
|
||||
@ -51,17 +50,15 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
var results1 = _win32s.AsParallel()
|
||||
.Where(p => Score(p, query.Search) > 0)
|
||||
.Select(ResultFromProgram);
|
||||
|
||||
.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;
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user