Refine WinUI shell and improve render diagnostics
This commit is contained in:
+27
-9
@@ -2,6 +2,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using AmigaDB.VideoRenderer.Models;
|
||||
@@ -15,8 +16,11 @@ public partial class MainWindow : Window
|
||||
{
|
||||
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 MainWindow()
|
||||
{
|
||||
@@ -110,7 +114,7 @@ public partial class MainWindow : Window
|
||||
catch (Exception exception)
|
||||
{
|
||||
AppendLog("ERROR: " + exception);
|
||||
MessageBox.Show(this, exception.Message, "Render failed", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
MessageBox.Show(this, UserFacingErrors.Summarize(exception), "Render failed", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
StageText.Text = "Failed";
|
||||
}
|
||||
finally
|
||||
@@ -165,12 +169,6 @@ public partial class MainWindow : Window
|
||||
private void InputList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
=> PreviewSourceButton.IsEnabled = InputList.SelectedItem is string;
|
||||
|
||||
private void InputList_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (InputList.SelectedItem is string path)
|
||||
OpenPreview(path);
|
||||
}
|
||||
|
||||
private void SetRendering(bool rendering)
|
||||
{
|
||||
RenderButton.IsEnabled = !rendering;
|
||||
@@ -187,9 +185,29 @@ public partial class MainWindow : Window
|
||||
|
||||
private void AppendLog(string line)
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
lock (_logLock)
|
||||
{
|
||||
LogBox.AppendText(line + Environment.NewLine);
|
||||
_pendingLog.AppendLine(line);
|
||||
if (_logFlushScheduled)
|
||||
return;
|
||||
|
||||
_logFlushScheduled = true;
|
||||
}
|
||||
|
||||
_ = Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
string chunk;
|
||||
lock (_logLock)
|
||||
{
|
||||
chunk = _pendingLog.ToString();
|
||||
_pendingLog.Clear();
|
||||
_logFlushScheduled = false;
|
||||
}
|
||||
|
||||
if (chunk.Length == 0)
|
||||
return;
|
||||
|
||||
LogBox.AppendText(chunk);
|
||||
LogBox.ScrollToEnd();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user