From 5a0e522620b69982aa756490d7b732de0991fb5c Mon Sep 17 00:00:00 2001 From: nilsk Date: Tue, 21 Jul 2026 13:35:00 +0200 Subject: [PATCH] add RustService method for sharing files via native share sheet --- .../Tools/Services/RustService.Share.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/MindWork AI Studio/Tools/Services/RustService.Share.cs diff --git a/app/MindWork AI Studio/Tools/Services/RustService.Share.cs b/app/MindWork AI Studio/Tools/Services/RustService.Share.cs new file mode 100644 index 00000000..b078ba37 --- /dev/null +++ b/app/MindWork AI Studio/Tools/Services/RustService.Share.cs @@ -0,0 +1,45 @@ +namespace AIStudio.Tools.Services; + +public sealed partial class RustService +{ + public async Task ShareFile(string filePath) + { + try + { + using var response = await this.http.PostAsJsonAsync( + "/share/file", + new ShareFileRequest(filePath), + this.jsonRustSerializerOptions); + if (!response.IsSuccessStatusCode) + { + this.logger?.LogError($"The Rust runtime rejected the share request: {response.StatusCode}."); + return false; + } + + var result = await response.Content.ReadFromJsonAsync(this.jsonRustSerializerOptions); + if (result?.Success == true) + return true; + + this.logger?.LogError($"The native share sheet could not be opened: {result?.Issue ?? "Unknown error"}"); + return false; + } + catch (HttpRequestException exception) + { + this.logger?.LogWarning(exception, "Failed to reach the Rust runtime share endpoint."); + return false; + } + catch (TaskCanceledException exception) + { + this.logger?.LogWarning(exception, "Timed out while reaching the Rust runtime share endpoint."); + return false; + } + catch (Exception exception) + { + this.logger?.LogError(exception, "Failed to process the Rust runtime share response."); + return false; + } + } + + private sealed record ShareFileRequest(string FilePath); + private sealed record ShareFileResponse(bool Success, string Issue); +}