This repository has been archived by the owner on Nov 13, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Plugin.cs
80 lines (74 loc) · 2.64 KB
/
Plugin.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using S = Switcheroo;
namespace Wox.Plugin.Switcheroo
{
public class Plugin : IPlugin
{
protected PluginInitContext context;
public void Init(PluginInitContext context)
{
this.context = context;
S.CoreStuff.Initialize();
}
public String IconImageDataUri(S.AppWindow self)
{
var key = "IconImageDataUri-" + self.HWnd;
var iconImageDataUri = System.Runtime.Caching.MemoryCache.Default.Get(key) as String; ;
if (iconImageDataUri == null)
{
var iconImage = self.IconImage;
try
{
using (MemoryStream memoryStream = new MemoryStream())
{
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(iconImage));
encoder.Save(memoryStream);
var b64String = Convert.ToBase64String(memoryStream.ToArray());
iconImageDataUri = "data:image/png;base64," + b64String;
System.Runtime.Caching.MemoryCache.Default.Add(key, iconImageDataUri, DateTimeOffset.Now.AddHours(1));
}
}
catch {
return null;
}
}
return iconImageDataUri;
}
public List<Result> Query(Query query)
{
var queryString = query.GetAllRemainingParameter();
S.CoreStuff.WindowList.Clear();
S.CoreStuff.GetWindows();
var filterResults = S.CoreStuff.FilterList(queryString).ToList();
return filterResults.Select(o =>
{
return new Result()
{
Title = o.AppWindow.Title,
SubTitle = o.AppWindow.ProcessTitle,
IcoPath = IconImageDataUri(o.AppWindow),
Action = con =>
{
context.HideApp();
if (con.SpecialKeyState.CtrlPressed)
{
o.AppWindow.PostClose();
o.AppWindow.SwitchTo();
}
else
{
o.AppWindow.SwitchTo();
}
return true;
}
};
}).ToList();
}
}
}