fix(app): make --capture failures visible in CI
Mirror the log to stderr in capture mode, report how many screenshots were written, exit non-zero when none were, and print the capture log in the CI step with a warning annotation when no images are produced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+48
-9
No files matched your search
@@ -28,6 +28,7 @@ public static class ScreenCapture
|
||||
|
||||
window.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
|
||||
{
|
||||
var written = 0;
|
||||
try
|
||||
{
|
||||
foreach (var theme in new[] { AppTheme.Dark, AppTheme.Light })
|
||||
@@ -37,10 +38,11 @@ public static class ScreenCapture
|
||||
{
|
||||
shell.Navigate(section.Key);
|
||||
Settle(window);
|
||||
Save(window, Path.Combine(directory, $"{section.Key}-{theme.ToString().ToLowerInvariant()}.png"));
|
||||
if (Save(window, Path.Combine(directory, $"{section.Key}-{theme.ToString().ToLowerInvariant()}.png"))) written++;
|
||||
}
|
||||
}
|
||||
Log.Info("capture", $"Screenshots written to {Path.GetFullPath(directory)}");
|
||||
Log.Info("capture", $"{written} screenshot(s) written to {Path.GetFullPath(directory)}");
|
||||
if (written == 0) Environment.ExitCode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -62,19 +64,29 @@ public static class ScreenCapture
|
||||
window.UpdateLayout();
|
||||
}
|
||||
|
||||
private static void Save(Window window, string path)
|
||||
private static bool Save(Window window, string path)
|
||||
{
|
||||
if (VisualTreeHelper.GetChildrenCount(window) == 0) return;
|
||||
if (VisualTreeHelper.GetChildrenCount(window) == 0) window.ApplyTemplate();
|
||||
if (VisualTreeHelper.GetChildrenCount(window) == 0)
|
||||
{
|
||||
Log.Warning("capture", "Window has no visual tree; nothing to render");
|
||||
return false;
|
||||
}
|
||||
var root = (FrameworkElement)VisualTreeHelper.GetChild(window, 0);
|
||||
var dpi = VisualTreeHelper.GetDpi(window);
|
||||
var width = (int)Math.Ceiling(root.ActualWidth * dpi.DpiScaleX);
|
||||
var height = (int)Math.Ceiling(root.ActualHeight * dpi.DpiScaleY);
|
||||
if (width <= 0 || height <= 0) return;
|
||||
if (width <= 0 || height <= 0)
|
||||
{
|
||||
Log.Warning("capture", $"Root element has no size ({root.ActualWidth}×{root.ActualHeight}); skipped {Path.GetFileName(path)}");
|
||||
return false;
|
||||
}
|
||||
var bitmap = new RenderTargetBitmap(width, height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32);
|
||||
bitmap.Render(root);
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(bitmap));
|
||||
using var stream = File.Create(path);
|
||||
encoder.Save(stream);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user