AI-Studio/app/MindWork AI Studio/Tools/Services/RustService.Clipboard.cs
Thorsten Sommer 58cc811a58
Some checks failed
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Sync Flatpak repo (push) Has been cancelled
Build and Release / Collect Flatpak artifacts (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Added the visual briefing assistant (#893)
2026-08-02 21:41:12 +02:00

50 lines
2.0 KiB
C#

using AIStudio.Tools.Rust;
namespace AIStudio.Tools.Services;
public sealed partial class RustService
{
/// <summary>
/// Tries to copy the given text to the clipboard.
/// </summary>
/// <remarks>
/// The outcome is reported through the message bus. Callers used to hand in their snackbar, which
/// was the reason most components injected one at all, and it meant this notification was styled
/// here instead of together with every other notification of the app.
/// </remarks>
/// <param name="text">The text to copy to the clipboard.</param>
public async Task CopyText2Clipboard(string text)
{
var message = TB("Successfully copied the text to your clipboard");
var succeeded = false;
try
{
var encryptedText = await text.Encrypt(this.encryptor!);
var response = await this.http.PostAsync("/clipboard/set", new StringContent(encryptedText.EncryptedData));
if (!response.IsSuccessStatusCode)
{
this.logger!.LogError($"Failed to copy the text to the clipboard due to an network error: '{response.StatusCode}'");
message = TB("Failed to copy the text to your clipboard.");
return;
}
var state = await response.Content.ReadFromJsonAsync<SetClipboardResponse>(this.jsonRustSerializerOptions);
if (!state.Success)
{
this.logger!.LogError("Failed to copy the text to the clipboard.");
message = TB("Failed to copy the text to your clipboard.");
return;
}
succeeded = true;
this.logger!.LogDebug("Successfully copied the text to the clipboard.");
}
finally
{
if (succeeded)
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.ContentCopy, message));
else
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.ContentCopy, message));
}
}
}