Files
ClaudeDo/src/ClaudeDo.Ui/Services/ClipboardImageTempStore.cs
T
mika kunsandClaude Sonnet 5.5 393e59460d feat(details): attach clipboard image on Ctrl+V in the task description
Extracts the clipboard bitmap read into a shared ClipboardBitmap helper
(also used by the terminal view); the description TextBox now routes an
image paste through AddFilesAsync as a unique paste-*.png attachment.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-02 10:31:47 +02:00

49 lines
2.1 KiB
C#

using System;
using System.IO;
using ClaudeDo.Data;
namespace ClaudeDo.Ui.Services;
/// <summary>
/// Temp PNGs written for clipboard-image paste into the interactive terminal (see
/// <see cref="ClaudeDo.Ui.Views.InteractiveTerminalView"/>) — dropped into the composer as a path,
/// the same way a file drop is, then read by Claude like any other file.
/// </summary>
public static class ClipboardImageTempStore
{
public static string Directory => Path.Combine(Paths.AppDataRoot(), "tmp");
/// <summary>A fresh, collision-free path for one pasted image.</summary>
public static string NewPngPath(DateTime utcNow) => NewPngPath(Directory, utcNow);
/// <summary>Deletes files older than <paramref name="maxAge"/> under the tmp dir — called once at
/// app startup, not a running cleanup service.</summary>
public static void DeleteOlderThan(TimeSpan maxAge, DateTime utcNow) => DeleteOlderThan(Directory, maxAge, utcNow);
/// <summary>Test seam for <see cref="NewPngPath(DateTime)"/> — takes the target dir explicitly
/// instead of the real app data root.</summary>
internal static string NewPngPath(string dir, DateTime utcNow) => Path.Combine(dir, NewPngFileName(utcNow));
/// <summary>A fresh, collision-free <c>paste-….png</c> file name (also used as an attachment name).</summary>
public static string NewPngFileName(DateTime utcNow) =>
$"paste-{utcNow:yyyyMMdd-HHmmssfff}-{Guid.NewGuid():N}.png";
/// <summary>Test seam for <see cref="DeleteOlderThan(TimeSpan,DateTime)"/> — takes the target dir
/// explicitly instead of the real app data root.</summary>
internal static void DeleteOlderThan(string dir, TimeSpan maxAge, DateTime utcNow)
{
if (!System.IO.Directory.Exists(dir)) return;
foreach (var file in System.IO.Directory.EnumerateFiles(dir))
{
try
{
if (utcNow - File.GetLastWriteTimeUtc(file) > maxAge)
File.Delete(file);
}
catch (IOException) { /* best effort */ }
catch (UnauthorizedAccessException) { /* best effort */ }
}
}
}