/
Main.cs
84 lines (72 loc) · 2.85 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using NLog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Wox.Infrastructure;
using Wox.Infrastructure.Logger;
namespace Wox.Plugin.ControlPanel
{
public class Main : IPlugin, IPluginI18n
{
private PluginInitContext context;
private List<ControlPanelItem> controlPanelItems = new List<ControlPanelItem>();
private string iconFolder;
private string fileType;
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
public void Init(PluginInitContext context)
{
this.context = context;
controlPanelItems = ControlPanelList.Create();
}
public List<Result> Query(Query query)
{
List<Result> results = new List<Result>();
foreach (var item in controlPanelItems)
{
var titleMatch = StringMatcher.FuzzySearch(query.Search, item.LocalizedString);
item.Score = titleMatch.Score;
if (item.Score > 0)
{
var result = new Result
{
Title = item.LocalizedString,
TitleHighlightData = titleMatch.MatchData,
SubTitle = item.InfoTip,
Score = item.Score,
IcoPath = item.IconPath,
Action = e =>
{
try
{
Process.Start(item.ExecutablePath);
}
catch (Exception ex)
{
ex.Data.Add(nameof(item.LocalizedString), item.LocalizedString);
ex.Data.Add(nameof(item.ExecutablePath), item.ExecutablePath);
ex.Data.Add(nameof(item.IconPath), item.IconPath);
ex.Data.Add(nameof(item.GUID), item.GUID);
Logger.WoxError($"cannot start control panel item {item.ExecutablePath}", ex);
}
return true;
}
};
results.Add(result);
}
}
List<Result> panelItems = results.OrderByDescending(o => o.Score).Take(5).ToList();
return panelItems;
}
public string GetTranslatedPluginTitle()
{
return context.API.GetTranslation("wox_plugin_controlpanel_plugin_name");
}
public string GetTranslatedPluginDescription()
{
return context.API.GetTranslation("wox_plugin_controlpanel_plugin_description");
}
}
}