From 93c33f3e57bb29a3da68dcb0f2428b969c2d85af Mon Sep 17 00:00:00 2001 From: rampaa Date: Wed, 9 Oct 2024 21:00:37 +0300 Subject: [PATCH] Minor --- JL.Core/Frontend/DummyFrontend.cs | 2 +- JL.Core/Frontend/IFrontend.cs | 2 +- JL.Core/Mining/MiningUtils.cs | 2 +- JL.Windows/Utilities/WindowsUtils.cs | 6 +++--- JL.Windows/WindowsFrontend.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/JL.Core/Frontend/DummyFrontend.cs b/JL.Core/Frontend/DummyFrontend.cs index 0118a918..aea8a1fa 100644 --- a/JL.Core/Frontend/DummyFrontend.cs +++ b/JL.Core/Frontend/DummyFrontend.cs @@ -26,7 +26,7 @@ public void ApplyDictOptions() public Task CopyFromWebSocket(string text) => Task.CompletedTask; - public byte[]? GetImageFromClipboardAsByteArray() => null; + public Task GetImageFromClipboardAsByteArray() => new(() => null); public Task TextToSpeech(string voiceName, string text) => Task.CompletedTask; diff --git a/JL.Core/Frontend/IFrontend.cs b/JL.Core/Frontend/IFrontend.cs index 46fb1696..86b203ee 100644 --- a/JL.Core/Frontend/IFrontend.cs +++ b/JL.Core/Frontend/IFrontend.cs @@ -18,7 +18,7 @@ public interface IFrontend public void ApplyDictOptions(); - public byte[]? GetImageFromClipboardAsByteArray(); + public Task GetImageFromClipboardAsByteArray(); public Task TextToSpeech(string voiceName, string text); diff --git a/JL.Core/Mining/MiningUtils.cs b/JL.Core/Mining/MiningUtils.cs index d745adf7..2275a474 100644 --- a/JL.Core/Mining/MiningUtils.cs +++ b/JL.Core/Mining/MiningUtils.cs @@ -508,7 +508,7 @@ public static async Task Mine(LookupResult lookupResult, string currentText, str List imageFields = FindFields(JLField.Image, userFields); bool needsImage = imageFields.Count > 0; byte[]? imageBytes = needsImage - ? Utils.Frontend.GetImageFromClipboardAsByteArray() + ? await Utils.Frontend.GetImageFromClipboardAsByteArray().ConfigureAwait(false) : null; if (imageBytes is not null) diff --git a/JL.Windows/Utilities/WindowsUtils.cs b/JL.Windows/Utilities/WindowsUtils.cs index 668854fb..805de7d9 100644 --- a/JL.Windows/Utilities/WindowsUtils.cs +++ b/JL.Windows/Utilities/WindowsUtils.cs @@ -722,16 +722,15 @@ public static void ChangeTheme(SkinType skin) }); } - public static byte[]? GetImageFromClipboardAsByteArray() + public static Task GetImageFromClipboardAsByteArray() { - return Application.Current.Dispatcher.Invoke(static () => + return Application.Current.Dispatcher.Invoke(static async () => { while (Clipboard.ContainsImage()) { try { BitmapSource? image = Clipboard.GetImage(); - if (image is null) { return null; @@ -747,6 +746,7 @@ public static void ChangeTheme(SkinType skin) catch (Exception ex) { Utils.Logger.Warning(ex, "GetImageFromClipboard failed"); + await Task.Delay(5).ConfigureAwait(true); } } diff --git a/JL.Windows/WindowsFrontend.cs b/JL.Windows/WindowsFrontend.cs index 08b31995..4eb41c3a 100644 --- a/JL.Windows/WindowsFrontend.cs +++ b/JL.Windows/WindowsFrontend.cs @@ -27,7 +27,7 @@ public void ShowOkDialog(string text, string caption) public Task CopyFromWebSocket(string text) => MainWindow.Instance.CopyFromWebSocket(text); - public byte[]? GetImageFromClipboardAsByteArray() => WindowsUtils.GetImageFromClipboardAsByteArray(); + public Task GetImageFromClipboardAsByteArray() => WindowsUtils.GetImageFromClipboardAsByteArray(); public Task TextToSpeech(string voiceName, string text) => SpeechSynthesisUtils.TextToSpeech(voiceName, text);