diff --git a/Community.PowerToys.Run.Plugin.YandexGPT/Community.PowerToys.Run.Plugin.YandexGPT.csproj b/Community.PowerToys.Run.Plugin.YandexGPT/Community.PowerToys.Run.Plugin.YandexGPT.csproj new file mode 100644 index 0000000..9b05b5d --- /dev/null +++ b/Community.PowerToys.Run.Plugin.YandexGPT/Community.PowerToys.Run.Plugin.YandexGPT.csproj @@ -0,0 +1,34 @@ + + + + net8.0-windows + x64;ARM64 + $(Platform) + true + + + + preview + enable + enable + + + + + + PreserveNewest + + + PreserveNewest + + + + + + + + + + + + diff --git a/Community.PowerToys.Run.Plugin.YandexGPT/Images/Yandex_Black.png b/Community.PowerToys.Run.Plugin.YandexGPT/Images/Yandex_Black.png new file mode 100644 index 0000000..d0f4301 Binary files /dev/null and b/Community.PowerToys.Run.Plugin.YandexGPT/Images/Yandex_Black.png differ diff --git a/Community.PowerToys.Run.Plugin.YandexGPT/Main.cs b/Community.PowerToys.Run.Plugin.YandexGPT/Main.cs new file mode 100644 index 0000000..8f22f94 --- /dev/null +++ b/Community.PowerToys.Run.Plugin.YandexGPT/Main.cs @@ -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 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 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 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); + } +} \ No newline at end of file diff --git a/Community.PowerToys.Run.Plugin.YandexGPT/plugin.json b/Community.PowerToys.Run.Plugin.YandexGPT/plugin.json new file mode 100644 index 0000000..2ed6e54 --- /dev/null +++ b/Community.PowerToys.Run.Plugin.YandexGPT/plugin.json @@ -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 +} \ No newline at end of file diff --git a/PowerToys.Run.YandexGPT.sln b/PowerToys.Run.YandexGPT.sln index 2650cff..dc800ac 100644 --- a/PowerToys.Run.YandexGPT.sln +++ b/PowerToys.Run.YandexGPT.sln @@ -1,6 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerToys.Run.YandexGPT", "PowerToys.Run.YandexGPT\PowerToys.Run.YandexGPT.csproj", "{5CE18468-6AB9-476F-9935-E12740111946}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Items", "Items", "{4A6F7084-0B6D-4C57-8E46-C430B7F343C2}" + ProjectSection(SolutionItems) = preProject + readme.md = readme.md + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.PowerToys.Run.Plugin.YandexGPT", "Community.PowerToys.Run.Plugin.YandexGPT\Community.PowerToys.Run.Plugin.YandexGPT.csproj", "{B65D8913-4679-46A0-84EA-DF11C641DDF5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -8,9 +13,9 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5CE18468-6AB9-476F-9935-E12740111946}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5CE18468-6AB9-476F-9935-E12740111946}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5CE18468-6AB9-476F-9935-E12740111946}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5CE18468-6AB9-476F-9935-E12740111946}.Release|Any CPU.Build.0 = Release|Any CPU + {B65D8913-4679-46A0-84EA-DF11C641DDF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B65D8913-4679-46A0-84EA-DF11C641DDF5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B65D8913-4679-46A0-84EA-DF11C641DDF5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B65D8913-4679-46A0-84EA-DF11C641DDF5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/PowerToys.Run.YandexGPT/PowerToys.Run.YandexGPT.csproj b/PowerToys.Run.YandexGPT/PowerToys.Run.YandexGPT.csproj deleted file mode 100644 index 17b910f..0000000 --- a/PowerToys.Run.YandexGPT/PowerToys.Run.YandexGPT.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net9.0 - enable - enable - - - diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4ed8eaf Binary files /dev/null and b/readme.md differ