-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
141 lines (121 loc) · 3.86 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
using System.Collections.Generic;
using System.Windows.Input;
using System.Reflection;
using System.Windows;
using Wox.Plugin;
using System.IO;
using Microsoft.PowerToys.Settings.UI.Library;
using System.Windows.Controls;
using System.Linq;
using Community.PowerToys.Run.Plugin.Update;
using Wox.Infrastructure.Storage;
using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.Its_MyPic
{
public class Main : IPlugin, IDelayedExecutionPlugin, IContextMenu, ISettingProvider, IPluginI18n, ISavable
{
public static string PluginID => "048FCB4CE3034FD9ACD9486F9FAB1F9E";
public string Name => "Its-MyPic";
public static string PluginDirectory => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
public string Description => "MyGO Screenshot Quick Copy";
public static bool CopyImage { get; set; }
public IEnumerable<PluginAdditionalOption> AdditionalOptions => [
new(){
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Checkbox,
Key = "copyType",
DisplayLabel = "Copy Image instead of copy file",
DisplayDescription = "Copy Image when enabled, otherwise copy file.",
Value = false
}
];
private readonly Data DB = new();
private PluginJsonStorage<SampleSettings> Storage { get; set; }
public void Save() => Storage.Save();
private SampleSettings Settings { get; set; }
private PluginUpdateHandler Updater { get; set; }
private PluginInitContext Context { get; set; }
public List<Result> Query(Query query)
{
return Query(query, false);
}
public List<Result> Query(Query query, bool delayedExecution)
{
var search = query.Search.ToLower();
List<Result> results;
if (Updater.IsUpdateAvailable())
{
Log.Info("Update available", GetType());
results = Updater.GetResults();
}
else
{
results = DB.GetMatchedSubtitleDatas(search, delayedExecution);
}
return results;
}
public void Init(PluginInitContext context)
{
CopyImage = false;
Context = context;
Storage = new PluginJsonStorage<SampleSettings>();
Settings = Storage.Load();
Log.Info(context.CurrentPluginMetadata.Version, GetType());
Updater = new PluginUpdateHandler(Settings.Update);
Updater.UpdateInstalling += OnUpdateInstalling;
Updater.UpdateInstalled += OnUpdateInstalled;
Updater.UpdateSkipped += OnUpdateSkipped;
Updater.Init(Context);
}
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
return [
new()
{
PluginName = "It's My Pic!",
Title = "Copy (Shift+Enter)",
Glyph = "\xE8C8",
FontFamily = "Segoe Fluent Icons, Segoe MDL2 Assets",
AcceleratorKey = Key.Enter,
AcceleratorModifiers = ModifierKeys.Shift,
Action = _ =>
{
Clipboard.SetText(selectedResult.Title);
return true;
}
}
];
}
public Control CreateSettingPanel()
{
throw new System.NotImplementedException();
}
public void UpdateSettings(PowerLauncherPluginSettings settings)
{
var option = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "copyType");
CopyImage = option.Value;
}
public string GetTranslatedPluginTitle()
{
throw new System.NotImplementedException();
}
public string GetTranslatedPluginDescription()
{
throw new System.NotImplementedException();
}
private void OnUpdateInstalling(object sender, PluginUpdateEventArgs e)
{
Log.Info("UpdateInstalling: " + e.Version, GetType());
}
private void OnUpdateInstalled(object sender, PluginUpdateEventArgs e)
{
Log.Info("UpdateInstalled: " + e.Version, GetType());
Context!.API.ShowNotification($"{Name} {e.Version}", "Update installed");
}
private void OnUpdateSkipped(object sender, PluginUpdateEventArgs e)
{
Log.Info("UpdateSkipped: " + e.Version, GetType());
Save();
Context?.API.ChangeQuery(Context.CurrentPluginMetadata.ActionKeyword, true);
}
}
}