Сделан скелет плагина
This commit is contained in:
135
Community.PowerToys.Run.Plugin.YandexGPT/Main.cs
Normal file
135
Community.PowerToys.Run.Plugin.YandexGPT/Main.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.YandexGPT;
|
||||
|
||||
public class Main : IPlugin, IContextMenu, ISettingProvider, IDisposable
|
||||
{
|
||||
#region Plugin Info
|
||||
public static string PluginId => "C2218AB0D86F4345B55C60F9418A811C";
|
||||
public string Name => "Yandex GPT";
|
||||
public string Description => "Плагин для выполнения поисковых запросов через Yandex GPT";
|
||||
public IEnumerable<PluginAdditionalOption> AdditionalOptions =>
|
||||
[
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = nameof(Token),
|
||||
DisplayLabel = "Токен",
|
||||
DisplayDescription = "Ключ доступа к YandexGPT",
|
||||
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
|
||||
TextValue = Token
|
||||
}
|
||||
];
|
||||
#endregion
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
private string? Token { get; set; }
|
||||
private PluginInitContext? Context { get; set; }
|
||||
private string? IconPath { get; set; }
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
Log.Info("Init", GetType());
|
||||
Context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
//Context.API.ThemeChanged += OnThemeChanged;
|
||||
//UpdateIconPath(Context.API.GetCurrentTheme());
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
Log.Info("Query: " + query.Search, GetType());
|
||||
|
||||
return [
|
||||
new()
|
||||
{
|
||||
QueryTextDisplay = query.Search,
|
||||
IcoPath = IconPath,
|
||||
Title = $"YandexGPT: Чет такое",
|
||||
SubTitle = $"Ответ: иди туда!",
|
||||
ToolTipData = new ToolTipData("Ответы", $"Тут ответ\nИ тут ответ"),
|
||||
ContextData = Token,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
Log.Info("LoadContextMenus", GetType());
|
||||
|
||||
if (selectedResult?.ContextData is (int words, TimeSpan transcription))
|
||||
{
|
||||
return
|
||||
[
|
||||
new ContextMenuResult
|
||||
{
|
||||
PluginName = Name,
|
||||
Title = "Copy (Enter)",
|
||||
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
Glyph = "\xE8C8", // Copy
|
||||
AcceleratorKey = Key.Enter,
|
||||
Action = _ => CopyToClipboard(words.ToString()),
|
||||
},
|
||||
new ContextMenuResult
|
||||
{
|
||||
PluginName = Name,
|
||||
Title = "Copy time (Ctrl+Enter)",
|
||||
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
Glyph = "\xE916", // Stopwatch
|
||||
AcceleratorKey = Key.Enter,
|
||||
AcceleratorModifiers = ModifierKeys.Control,
|
||||
Action = _ => CopyToClipboard(transcription.ToString()),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (selectedResult?.ContextData is int characters)
|
||||
{
|
||||
return
|
||||
[
|
||||
new ContextMenuResult
|
||||
{
|
||||
PluginName = Name,
|
||||
Title = "Copy (Enter)",
|
||||
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
Glyph = "\xE8C8", // Copy
|
||||
AcceleratorKey = Key.Enter,
|
||||
Action = _ => CopyToClipboard(characters.ToString()),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel() => throw new NotImplementedException();
|
||||
|
||||
public void UpdateSettings(PowerLauncherPluginSettings settings)
|
||||
{
|
||||
var tokenSettings = settings.AdditionalOptions.SingleOrDefault(x => x.Key == nameof(Token));
|
||||
if (tokenSettings is null)
|
||||
return;
|
||||
Token = tokenSettings.TextValue;
|
||||
}
|
||||
|
||||
|
||||
private static bool CopyToClipboard(string? value)
|
||||
{
|
||||
if (value != null)
|
||||
Clipboard.SetText(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Log.Info("Dispose", GetType());
|
||||
if (!_disposed)
|
||||
return;
|
||||
_disposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user