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