Refine WinUI shell and improve render diagnostics
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using AmigaDB.VideoRenderer.Models;
|
||||
using AmigaDB.VideoRenderer.Services;
|
||||
using Microsoft.UI.Xaml;
|
||||
@@ -15,7 +16,11 @@ public sealed partial class MainPage : Page
|
||||
{
|
||||
private readonly ObservableCollection<string> _inputs = [];
|
||||
private readonly AppSettings _loadedSettings;
|
||||
private readonly StringBuilder _pendingLog = new();
|
||||
private readonly object _logLock = new();
|
||||
private CancellationTokenSource? _renderCancellation;
|
||||
private string? _lastRenderedFile;
|
||||
private bool _logFlushScheduled;
|
||||
|
||||
public MainPage()
|
||||
{
|
||||
@@ -107,7 +112,9 @@ public sealed partial class MainPage : Page
|
||||
_renderCancellation = new CancellationTokenSource();
|
||||
Progress<RenderProgress> progress = new(UpdateProgress);
|
||||
await new RenderPipeline().RenderAsync(settings, progress, AppendLog, _renderCancellation.Token);
|
||||
_lastRenderedFile = Path.Combine(settings.OutputDirectory, settings.OutputName + "_final.mp4");
|
||||
OpenOutputButton.IsEnabled = true;
|
||||
PreviewRenderedButton.IsEnabled = File.Exists(_lastRenderedFile);
|
||||
await ShowMessageAsync("Render complete", "The AmiReel render completed successfully.");
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@@ -118,7 +125,7 @@ public sealed partial class MainPage : Page
|
||||
{
|
||||
AppendLog("ERROR: " + exception);
|
||||
StageText.Text = "Failed";
|
||||
await ShowMessageAsync("Render failed", exception.Message);
|
||||
await ShowMessageAsync("Render failed", UserFacingErrors.Summarize(exception));
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -141,6 +148,18 @@ public sealed partial class MainPage : Page
|
||||
Process.Start(new ProcessStartInfo("explorer.exe", OutputFolderBox.Text) { UseShellExecute = true });
|
||||
}
|
||||
|
||||
private void PreviewSource_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (InputList.SelectedItem is string path)
|
||||
OpenPreview(path);
|
||||
}
|
||||
|
||||
private void PreviewRendered_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(_lastRenderedFile) && File.Exists(_lastRenderedFile))
|
||||
OpenPreview(_lastRenderedFile);
|
||||
}
|
||||
|
||||
private void ThemeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (!IsLoaded) return;
|
||||
@@ -191,11 +210,39 @@ public sealed partial class MainPage : Page
|
||||
StatusText.Text = value.Message;
|
||||
}
|
||||
|
||||
private void OpenPreview(string mediaPath)
|
||||
{
|
||||
if (!File.Exists(mediaPath))
|
||||
return;
|
||||
|
||||
Process.Start(new ProcessStartInfo(mediaPath) { UseShellExecute = true });
|
||||
}
|
||||
|
||||
private void AppendLog(string line)
|
||||
{
|
||||
lock (_logLock)
|
||||
{
|
||||
_pendingLog.AppendLine(line);
|
||||
if (_logFlushScheduled)
|
||||
return;
|
||||
|
||||
_logFlushScheduled = true;
|
||||
}
|
||||
|
||||
_ = DispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
LogBox.Text += line + Environment.NewLine;
|
||||
string chunk;
|
||||
lock (_logLock)
|
||||
{
|
||||
chunk = _pendingLog.ToString();
|
||||
_pendingLog.Clear();
|
||||
_logFlushScheduled = false;
|
||||
}
|
||||
|
||||
if (chunk.Length == 0)
|
||||
return;
|
||||
|
||||
LogBox.Text += chunk;
|
||||
LogBox.Select(LogBox.Text.Length, 0);
|
||||
});
|
||||
}
|
||||
@@ -207,7 +254,7 @@ public sealed partial class MainPage : Page
|
||||
EndCardBox.Text.Trim(),
|
||||
FfmpegPathBox.Text.Trim(),
|
||||
FfprobePathBox.Text.Trim(),
|
||||
string.Empty,
|
||||
_loadedSettings.PreviewPlayerPath,
|
||||
SelectedTheme(),
|
||||
SelectedEncoder(),
|
||||
TrimBox.Text.Trim(),
|
||||
@@ -248,6 +295,11 @@ public sealed partial class MainPage : Page
|
||||
EncoderBox.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
private void InputList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
PreviewSourceButton.IsEnabled = InputList.SelectedItem is string;
|
||||
}
|
||||
|
||||
private void ApplyTheme(string theme)
|
||||
{
|
||||
RequestedTheme = string.Equals(theme, "Light", StringComparison.OrdinalIgnoreCase)
|
||||
|
||||
Reference in New Issue
Block a user