Сделан скелет плагина

This commit is contained in:
Mikhail Shahovalov
2025-05-08 00:18:12 +03:00
parent 7debe74b0b
commit 8757c60396
7 changed files with 193 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Platforms>x64;ARM64</Platforms>
<PlatformTarget>$(Platform)</PlatformTarget>
<UseWPF>true</UseWPF>
</PropertyGroup>
<PropertyGroup>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Images\*.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Images\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Community.PowerToys.Run.Plugin.Dependencies" Version="0.90.0" />
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View 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);
}
}

View File

@@ -0,0 +1,14 @@
{
"ID": "C2218AB0D86F4345B55C60F9418A811C",
"ActionKeyword": "YandexGPT",
"IsGlobal": false,
"Name": "YandexGPT",
"Author": "MikhailRaw",
"Version": "1.0.0",
"Language": "csharp",
"Website": "https://git.shahovalov.ru/mikhail/PowerToys.Run.YandexGPT",
"ExecuteFileName": "Community.PowerToys.Run.Plugin.YandexGPT.dll",
"IcoPathDark": "Images\\Yandex_Black.png",
"IcoPathLight": "Images\\Yandex_Black.png",
"DynamicLoading": false
}