diff --git a/app/MindWork AI Studio/Tools/Rust.cs b/app/MindWork AI Studio/Tools/Rust.cs new file mode 100644 index 0000000..6db275a --- /dev/null +++ b/app/MindWork AI Studio/Tools/Rust.cs @@ -0,0 +1,46 @@ +using Microsoft.JSInterop; + +using MudBlazor; + +namespace AIStudio.Tools; + +/// +/// Calling Rust functions. +/// +public sealed class Rust +{ + /// + /// Tries to copy the given text to the clipboard. + /// + /// The JS runtime to access the Rust code. + /// The snackbar to show the result. + /// The text to copy to the clipboard. + public async Task CopyText2Clipboard(IJSRuntime jsRuntime, ISnackbar snackbar, string text) + { + var response = await jsRuntime.InvokeAsync("window.__TAURI__.invoke", "set_clipboard", new SetClipboardText(text)); + var msg = response.Success switch + { + true => "Successfully copied text to clipboard!", + false => $"Failed to copy text to clipboard: {response.Issue}", + }; + + var severity = response.Success switch + { + true => Severity.Success, + false => Severity.Error, + }; + + snackbar.Add(msg, severity, config => + { + config.Icon = Icons.Material.Filled.ContentCopy; + config.IconSize = Size.Large; + config.IconColor = severity switch + { + Severity.Success => Color.Success, + Severity.Error => Color.Error, + + _ => Color.Default, + }; + }); + } +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/SetClipboardResponse.cs b/app/MindWork AI Studio/Tools/SetClipboardResponse.cs new file mode 100644 index 0000000..7a65caa --- /dev/null +++ b/app/MindWork AI Studio/Tools/SetClipboardResponse.cs @@ -0,0 +1,8 @@ +namespace AIStudio.Tools; + +/// +/// The response from the set clipboard operation. +/// +/// True when the operation was successful. +/// The issue that occurred during the operation, empty when successful. +public readonly record struct SetClipboardResponse(bool Success, string Issue); \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/SetClipboardText.cs b/app/MindWork AI Studio/Tools/SetClipboardText.cs new file mode 100644 index 0000000..9776d29 --- /dev/null +++ b/app/MindWork AI Studio/Tools/SetClipboardText.cs @@ -0,0 +1,7 @@ +namespace AIStudio.Tools; + +/// +/// Model for setting clipboard text. +/// +/// The text to set to the clipboard. +public record SetClipboardText(string Text); \ No newline at end of file