Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Oct 9, 2024
1 parent 4f2aa6a commit 93c33f3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion JL.Core/Frontend/DummyFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void ApplyDictOptions()

public Task CopyFromWebSocket(string text) => Task.CompletedTask;

public byte[]? GetImageFromClipboardAsByteArray() => null;
public Task<byte[]?> GetImageFromClipboardAsByteArray() => new(() => null);

public Task TextToSpeech(string voiceName, string text) => Task.CompletedTask;

Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Frontend/IFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IFrontend

public void ApplyDictOptions();

public byte[]? GetImageFromClipboardAsByteArray();
public Task<byte[]?> GetImageFromClipboardAsByteArray();

public Task TextToSpeech(string voiceName, string text);

Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Mining/MiningUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public static async Task Mine(LookupResult lookupResult, string currentText, str
List<string> 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)
Expand Down
6 changes: 3 additions & 3 deletions JL.Windows/Utilities/WindowsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,16 +722,15 @@ public static void ChangeTheme(SkinType skin)
});
}

public static byte[]? GetImageFromClipboardAsByteArray()
public static Task<byte[]?> 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;
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/WindowsFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte[]?> GetImageFromClipboardAsByteArray() => WindowsUtils.GetImageFromClipboardAsByteArray();

public Task TextToSpeech(string voiceName, string text) => SpeechSynthesisUtils.TextToSpeech(voiceName, text);

Expand Down

0 comments on commit 93c33f3

Please sign in to comment.