diff --git a/src/ChatPrisma/App.xaml.cs b/src/ChatPrisma/App.xaml.cs index 0e62d05..4e11dd9 100644 --- a/src/ChatPrisma/App.xaml.cs +++ b/src/ChatPrisma/App.xaml.cs @@ -96,7 +96,7 @@ private IHostBuilder CreateHostBuilder(string[] args) => Microsoft.Extensions.Ho o.AppShutdownHeader = "Beenden"; }); services.AddOptions() - .Bind(context.Configuration.GetSection("OpenAI")) + .BindConfiguration("OpenAI") .ValidateDataAnnotations() .ValidateOnStart(); services.AddOptions() @@ -117,17 +117,20 @@ private IHostBuilder CreateHostBuilder(string[] args) => Microsoft.Extensions.Ho o.GitHubUsername = "haefele"; o.GitHubRepository = "ChatPrisma"; o.GitHubReleaseAssetName = "App.zip"; + o.CheckForUpdatesInBackground = true; + o.MinutesBetweenUpdateChecks = 30; }) - .Bind(context.Configuration.GetSection("Updater")) + .BindConfiguration("Updater") .ValidateDataAnnotations() .ValidateOnStart(); - services.AddOptions() + services.AddOptions() .Configure(o => { o.Key = "Y"; o.KeyModifiers = "Ctrl+Shift+Alt"; + o.HotkeyDelayInMilliseconds = 200; }) - .Bind(context.Configuration.GetSection("Keyboard")) + .BindConfiguration("Hotkey") .ValidateDataAnnotations() .ValidateOnStart(); diff --git a/src/ChatPrisma/Options/KeyboardOptions.cs b/src/ChatPrisma/Options/HotkeyOptions.cs similarity index 73% rename from src/ChatPrisma/Options/KeyboardOptions.cs rename to src/ChatPrisma/Options/HotkeyOptions.cs index e6a1a3a..f77293a 100644 --- a/src/ChatPrisma/Options/KeyboardOptions.cs +++ b/src/ChatPrisma/Options/HotkeyOptions.cs @@ -2,11 +2,12 @@ namespace ChatPrisma.Options { - public class KeyboardOptions + public class HotkeyOptions { [Required] public string Key { get; set; } = default!; [Required] public string KeyModifiers { get; set; } = default!; + public int HotkeyDelayInMilliseconds { get; set; } } } diff --git a/src/ChatPrisma/Options/UpdaterOptions.cs b/src/ChatPrisma/Options/UpdaterOptions.cs index 9822846..06666f9 100644 --- a/src/ChatPrisma/Options/UpdaterOptions.cs +++ b/src/ChatPrisma/Options/UpdaterOptions.cs @@ -11,6 +11,6 @@ public class UpdaterOptions [Required] public string GitHubReleaseAssetName { get; set; } = default!; - public bool CheckForUpdatesInBackground { get; set; } = true; - public int MinutesBetweenUpdateChecks { get; set; } = 10; + public bool CheckForUpdatesInBackground { get; set; } + public int MinutesBetweenUpdateChecks { get; set; } } diff --git a/src/ChatPrisma/Services/KeyboardHooks/GlobalKeyInterceptorKeyboardHooks.cs b/src/ChatPrisma/Services/KeyboardHooks/GlobalKeyInterceptorKeyboardHooks.cs index c7292a0..898262f 100644 --- a/src/ChatPrisma/Services/KeyboardHooks/GlobalKeyInterceptorKeyboardHooks.cs +++ b/src/ChatPrisma/Services/KeyboardHooks/GlobalKeyInterceptorKeyboardHooks.cs @@ -6,7 +6,7 @@ namespace ChatPrisma.Services.KeyboardHooks; -public class GlobalKeyInterceptorKeyboardHooks(ILogger logger, IOptions keyboardOptions) : IKeyboardHooks, IDisposable +public class GlobalKeyInterceptorKeyboardHooks(ILogger logger, IOptions keyboardOptions) : IKeyboardHooks, IDisposable { public event EventHandler? CombinationPressed; @@ -21,7 +21,7 @@ public Task StartAsync() }; this._interceptor = new KeyInterceptor(shortcuts); - this._interceptor.ShortcutPressed += OnShortcutPressed; + this._interceptor.ShortcutPressed += this.OnShortcutPressed; logger.LogInformation("Started listening for keyboard shortcuts."); diff --git a/src/ChatPrisma/Services/TextExtractor/ClipboardTextExtractor.cs b/src/ChatPrisma/Services/TextExtractor/ClipboardTextExtractor.cs index d4b98d6..d1a1b80 100644 --- a/src/ChatPrisma/Services/TextExtractor/ClipboardTextExtractor.cs +++ b/src/ChatPrisma/Services/TextExtractor/ClipboardTextExtractor.cs @@ -1,14 +1,16 @@ -using System.Windows.Forms; +using System.Windows.Forms; +using ChatPrisma.Options; +using Microsoft.Extensions.Options; namespace ChatPrisma.Services.TextExtractor; -public class ClipboardTextExtractor : ITextExtractor +public class ClipboardTextExtractor(IOptionsMonitor hotkeyOptions) : ITextExtractor { public async Task GetCurrentTextAsync() { // Give the user a bit of time to release the keyboard keys, // otherwise CTRL+C will not work - await Task.Delay(TimeSpan.FromMilliseconds(200)); + await Task.Delay(TimeSpan.FromMilliseconds(hotkeyOptions.CurrentValue.HotkeyDelayInMilliseconds)); // Need to clear the clipboard, or otherwise we might get some previously copied text Clipboard.Clear(); diff --git a/src/ChatPrisma/appsettings.json b/src/ChatPrisma/appsettings.json index 445f26b..abf669a 100644 --- a/src/ChatPrisma/appsettings.json +++ b/src/ChatPrisma/appsettings.json @@ -5,11 +5,12 @@ }, "Updater": { "CheckForUpdatesInBackground": true, - "MinutesBetweenUpdateChecks": 10 + "MinutesBetweenUpdateChecks": 30 }, - "Keyboard": { + "Hotkey": { "Key": "Y", "KeyModifiers": "Ctrl+Shift+Alt", + "HotkeyDelayInMilliseconds": 200, }, "NLog": { "throwConfigExceptions": true,