-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.cs
157 lines (134 loc) · 4.72 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using Community.PowerToys.Run.Plugin.$safeprojectname$.Properties;
using System.Windows.Controls;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Wox.Infrastructure;
using Wox.Plugin;
using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.$safeprojectname$
{
public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider, IReloadable, IDisposable, IDelayedExecutionPlugin
{
private const string Setting = nameof(Setting);
// current value of the setting
private bool _setting;
private PluginInitContext _context;
private string _iconPath;
private bool _disposed;
public string Name => Resources.plugin_name;
public string Description => Resources.plugin_description;
// TODO: remove dash from ID below and inside plugin.json
public static string PluginID => "$guid1$";
// TODO: add additional options (optional)
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
{
new PluginAdditionalOption()
{
PluginOptionType= PluginAdditionalOption.AdditionalOptionType.Checkbox,
Key = Setting,
DisplayLabel = Resources.plugin_setting,
},
};
public void UpdateSettings(PowerLauncherPluginSettings settings)
{
_setting = settings?.AdditionalOptions?.FirstOrDefault(x => x.Key == Setting)?.Value ?? false;
}
// TODO: return context menus for each Result (optional)
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
return new List<ContextMenuResult>(0);
}
// TODO: return query results
public List<Result> Query(Query query)
{
ArgumentNullException.ThrowIfNull(query);
var results = new List<Result>();
// empty query
if (string.IsNullOrEmpty(query.Search))
{
results.Add(new Result
{
Title = Name,
SubTitle = Description,
QueryTextDisplay = string.Empty,
IcoPath = _iconPath,
Action = action =>
{
return true;
},
});
return results;
}
return results;
}
// TODO: return delayed query results (optional)
public List<Result> Query(Query query, bool delayedExecution)
{
ArgumentNullException.ThrowIfNull(query);
var results = new List<Result>();
// empty query
if (string.IsNullOrEmpty(query.Search))
{
return results;
}
return results;
}
public void Init(PluginInitContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(_context.API.GetCurrentTheme());
}
public string GetTranslatedPluginTitle()
{
return Resources.plugin_name;
}
public string GetTranslatedPluginDescription()
{
return Resources.plugin_description;
}
private void OnThemeChanged(Theme oldTheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
private void UpdateIconPath(Theme theme)
{
if (theme == Theme.Light || theme == Theme.HighContrastWhite)
{
_iconPath = "Images/$projectname$.light.png";
}
else
{
_iconPath = "Images/$projectname$.dark.png";
}
}
public Control CreateSettingPanel()
{
throw new NotImplementedException();
}
public void ReloadData()
{
if (_context is null)
{
return;
}
UpdateIconPath(_context.API.GetCurrentTheme());
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed && disposing)
{
if (_context != null && _context.API != null)
{
_context.API.ThemeChanged -= OnThemeChanged;
}
_disposed = true;
}
}
}
}