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, }; }); } public async Task CheckForUpdate(IJSRuntime jsRuntime) { var cts = new CancellationTokenSource(TimeSpan.FromSeconds(16)); return await jsRuntime.InvokeAsync("window.__TAURI__.invoke", cts.Token, "check_for_update"); } public async Task InstallUpdate(IJSRuntime jsRuntime) { var cts = new CancellationTokenSource(); await jsRuntime.InvokeVoidAsync("window.__TAURI__.invoke", cts.Token, "install_update"); } }