diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d7ba5ae9..0e95bd97 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -89,9 +89,14 @@ jobs:
- name: Screenshots
if: runner.os == 'Windows'
run: |
- src/Titano.App/bin/Release/net10.0-windows/Titano.exe --capture out/screenshots &
+ set +e
+ src/Titano.App/bin/Release/net10.0-windows/Titano.exe --capture out/screenshots 2> out/capture.log &
wait $!
- ls -la out/screenshots
+ code=$?
+ cat out/capture.log
+ count=$(ls out/screenshots/*.png 2>/dev/null | wc -l)
+ echo "capture exit code $code, $count screenshot(s)"
+ if [ "$count" -eq 0 ]; then echo "::warning title=Screenshots::Titano --capture produced no images (exit $code)"; fi
- name: Publish desktop programs (win-x64, self-contained single file)
if: runner.os == 'Windows'
diff --git a/src/Titano.App/App.xaml.cs b/src/Titano.App/App.xaml.cs
index d3122b31..90c39120 100644
--- a/src/Titano.App/App.xaml.cs
+++ b/src/Titano.App/App.xaml.cs
@@ -24,7 +24,9 @@ public partial class App : Application
base.OnStartup(e);
Environment = AppEnvironment.Detect();
_log = new FileLogSink(Environment.LogDirectory, "titano");
- Log.SetSink(_log);
+ var capture = Array.IndexOf(e.Args, "--capture") >= 0;
+ // Capture runs in CI: mirror the log to stderr so failures are visible in the job output.
+ Log.SetSink(capture ? new TeeLogSink(_log, new StderrLogSink()) : _log);
Log.Info("app", $"Titano {typeof(App).Assembly.GetName().Version} starting; data at {Environment.DataDirectory}");
Settings = AppSettings.Load(Environment.SettingsPath);
@@ -45,7 +47,7 @@ public partial class App : Application
MainWindow = window;
var captureIndex = Array.IndexOf(e.Args, "--capture");
- if (captureIndex >= 0)
+ if (capture)
{
var dir = captureIndex + 1 < e.Args.Length ? e.Args[captureIndex + 1] : "screenshots";
ScreenCapture.Run(window, shell, dir);
diff --git a/src/Titano.App/Shell/ScreenCapture.cs b/src/Titano.App/Shell/ScreenCapture.cs
index 343f78ba..199d12c7 100644
--- a/src/Titano.App/Shell/ScreenCapture.cs
+++ b/src/Titano.App/Shell/ScreenCapture.cs
@@ -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;
}
}
diff --git a/src/Titano.Core/Diagnostics/Log.cs b/src/Titano.Core/Diagnostics/Log.cs
index 0aa6da57..95c084ab 100644
--- a/src/Titano.Core/Diagnostics/Log.cs
+++ b/src/Titano.Core/Diagnostics/Log.cs
@@ -114,3 +114,23 @@ public sealed class FileLogSink : ILogSink, IDisposable
lock (_gate) _writer?.Dispose();
}
}
+
+/// Writes every event to several sinks.
+public sealed class TeeLogSink(params ILogSink[] sinks) : ILogSink
+{
+ public void Write(LogLevel level, string category, string message, Exception? exception)
+ {
+ foreach (var sink in sinks) sink.Write(level, category, message, exception);
+ }
+}
+
+/// Writes events to standard error (CI and command-line diagnostics).
+public sealed class StderrLogSink : ILogSink
+{
+ public void Write(LogLevel level, string category, string message, Exception? exception)
+ {
+ var line = string.Create(CultureInfo.InvariantCulture, $"{DateTime.UtcNow:O} {level,-7} {category}: {message}");
+ if (exception is not null) line += Environment.NewLine + exception;
+ Console.Error.WriteLine(line);
+ }
+}