forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
128 lines (103 loc) · 4.11 KB
/
Main.cs
File metadata and controls
128 lines (103 loc) · 4.11 KB
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
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Controls;
using ManagedCommon;
using Microsoft.Plugin.WindowWalker.Components;
using Microsoft.PowerToys.Settings.UI.Library;
using Wox.Plugin;
using Wox.Plugin.Common.VirtualDesktop.Helper;
namespace Microsoft.Plugin.WindowWalker
{
public class Main : IPlugin, IPluginI18n, ISettingProvider, IContextMenu, IDisposable
{
private CancellationTokenSource _cancellationTokenSource = new();
private bool _disposed;
private string IconPath { get; set; }
private string InfoIconPath { get; set; }
private PluginInitContext Context { get; set; }
public string Name => Properties.Resources.wox_plugin_windowwalker_plugin_name;
public string Description => Properties.Resources.wox_plugin_windowwalker_plugin_description;
public static string PluginID => "F737A9223560B3C6833B5FFB8CDF78E5";
internal static readonly VirtualDesktopHelper VirtualDesktopHelperInstance = new VirtualDesktopHelper();
public List<Result> Query(Query query)
{
ArgumentNullException.ThrowIfNull(query);
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = new CancellationTokenSource();
VirtualDesktopHelperInstance.UpdateDesktopList();
OpenWindows.Instance.UpdateOpenWindowsList(_cancellationTokenSource.Token);
SearchController.Instance.UpdateSearchText(query.Search);
List<SearchResult> searchControllerResults = SearchController.Instance.SearchMatches;
return ResultHelper.GetResultList(searchControllerResults, !string.IsNullOrEmpty(query.ActionKeyword), IconPath, InfoIconPath);
}
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
return ContextMenuHelper.GetContextMenuResults(selectedResult);
}
public void Init(PluginInitContext context)
{
Context = context;
Context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(Context.API.GetCurrentTheme());
}
public IEnumerable<PluginAdditionalOption> AdditionalOptions
{
get { return WindowWalkerSettings.GetAdditionalOptions(); }
}
// Todo : Update with theme based IconPath
private void UpdateIconPath(Theme theme)
{
if (theme == Theme.Light || theme == Theme.HighContrastWhite)
{
IconPath = "Images/windowwalker.light.png";
InfoIconPath = "Images/info.light.png";
}
else
{
IconPath = "Images/windowwalker.dark.png";
InfoIconPath = "Images/info.dark.png";
}
}
private void OnThemeChanged(Theme currentTheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
public string GetTranslatedPluginTitle()
{
return Properties.Resources.wox_plugin_windowwalker_plugin_name;
}
public string GetTranslatedPluginDescription()
{
return Properties.Resources.wox_plugin_windowwalker_plugin_description;
}
public Control CreateSettingPanel()
{
throw new NotImplementedException();
}
public void UpdateSettings(PowerLauncherPluginSettings settings)
{
WindowWalkerSettings.Instance.UpdateSettings(settings);
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_cancellationTokenSource?.Dispose();
_disposed = true;
}
}
}
}
}