Skip to content

Commit 33675b6

Browse files
**fix: enhance bug reporting with structured payload and improve app shutdown**
- Refactored `BugReportService` to send detailed structured fields (env, exception, stack) matching API model. - Updated `MainWindow` closing logic for better cancellation handling and forced shutdown. - Converted event handlers to async naming convention and centralized log/terminal styles in App.xaml. - Bumped SharpCompress to v0.47.4.
1 parent 81fe63d commit 33675b6

7 files changed

Lines changed: 220 additions & 75 deletions

File tree

BatchConvertToCHD/App.xaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,5 +579,49 @@
579579
<Setter Property="Padding" Value="10"/>
580580
</Style>
581581

582+
<!-- ==================== LOG TEXTBOX STYLES ==================== -->
583+
<!-- Terminal TextBox Style (reused across windows) -->
584+
<Style x:Key="TerminalLogTextBox" TargetType="TextBox">
585+
<Setter Property="FontFamily" Value="Consolas"/>
586+
<Setter Property="FontSize" Value="12"/>
587+
<Setter Property="Background" Value="{StaticResource TerminalBackgroundBrush}"/>
588+
<Setter Property="Foreground" Value="{StaticResource TerminalForegroundBrush}"/>
589+
<Setter Property="BorderThickness" Value="0"/>
590+
<Setter Property="Padding" Value="10"/>
591+
<Setter Property="AcceptsReturn" Value="True"/>
592+
<Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
593+
<Setter Property="HorizontalScrollBarVisibility" Value="Auto"/>
594+
<Setter Property="IsReadOnly" Value="True"/>
595+
<Setter Property="TextAlignment" Value="Left"/>
596+
<Setter Property="TextWrapping" Value="NoWrap"/>
597+
<Setter Property="CaretBrush" Value="{StaticResource TerminalForegroundBrush}"/>
598+
<Setter Property="VerticalAlignment" Value="Stretch"/>
599+
<Setter Property="VerticalContentAlignment" Value="Top"/>
600+
</Style>
601+
602+
<!-- Terminal TextBox with Glow Effect -->
603+
<Style x:Key="TerminalLogTextBoxWithGlow" TargetType="TextBox" BasedOn="{StaticResource TerminalLogTextBox}">
604+
<Setter Property="Effect">
605+
<Setter.Value>
606+
<DropShadowEffect ShadowDepth="0" Color="#39FF14" BlurRadius="2" Opacity="0.4"/>
607+
</Setter.Value>
608+
</Setter>
609+
</Style>
610+
611+
<!-- ==================== BUTTON CONTENT COLORS ==================== -->
612+
<!-- Dark text color for buttons with light backgrounds -->
613+
<SolidColorBrush x:Key="ButtonTextDarkBrush" Color="#121518"/>
614+
615+
<!-- ==================== TABCONTROL STYLE ==================== -->
616+
<Style TargetType="TabControl">
617+
<Setter Property="Background" Value="Transparent"/>
618+
<Setter Property="BorderThickness" Value="0"/>
619+
</Style>
620+
621+
<!-- ==================== GRIDSPLITTER STYLE ==================== -->
622+
<Style TargetType="GridSplitter">
623+
<Setter Property="Background" Value="Transparent"/>
624+
</Style>
625+
582626
</Application.Resources>
583627
</Application>

BatchConvertToCHD/App.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public App()
3434

3535
protected override void OnStartup(StartupEventArgs e)
3636
{
37+
// Set shutdown mode to close the application when the main window closes
38+
// This ensures the app fully terminates when the user closes the window
39+
ShutdownMode = ShutdownMode.OnMainWindowClose;
40+
3741
// Delete old 7z DLL files if they exist
3842
DeleteOldDllFiles();
3943

BatchConvertToCHD/AppConfig.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@ internal static class AppConfig
1919

2020
// Timeout configurations
2121
public const int MaxConversionTimeoutHours = 4;
22-
public const int ProcessKillTimeoutSeconds = 5;
23-
public const int FileAccessTimeoutSeconds = 5;
24-
public const int ValidationTimeoutSeconds = 10;
2522
}

BatchConvertToCHD/MainWindow.xaml

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
<Button.Content>
3131
<StackPanel Orientation="Horizontal">
3232
<Image Source="pack://application:,,,/images/about.png" Width="16" Height="16" Margin="0,0,5,0" />
33-
<TextBlock Text="About" Foreground="#121518" VerticalAlignment="Center" />
33+
<TextBlock Text="About" Foreground="{StaticResource ButtonTextDarkBrush}" VerticalAlignment="Center" />
3434
</StackPanel>
3535
</Button.Content>
3636
</Button>
3737
<Button Click="ExitMenuItem_Click" Style="{StaticResource ActionButtonStyle}" Background="{StaticResource ExitButtonBrush}" ToolTip="Close the application">
3838
<Button.Content>
3939
<StackPanel Orientation="Horizontal">
4040
<Image Source="pack://application:,,,/images/exit.png" Width="16" Height="16" Margin="0,0,5,0" />
41-
<TextBlock Text="Exit" Foreground="#121518" VerticalAlignment="Center" />
41+
<TextBlock Text="Exit" Foreground="{StaticResource ButtonTextDarkBrush}" VerticalAlignment="Center" />
4242
</StackPanel>
4343
</Button.Content>
4444
</Button>
@@ -61,7 +61,7 @@
6161
<ColumnDefinition Width="*" MinWidth="300" />
6262
</Grid.ColumnDefinitions>
6363

64-
<TabControl Grid.Column="0" x:Name="MainTabControl" SelectionChanged="MainTabControl_SelectionChanged" Background="Transparent" BorderThickness="0">
64+
<TabControl Grid.Column="0" x:Name="MainTabControl" SelectionChanged="MainTabControl_SelectionChanged">
6565
<TabItem Header="Convert to CHD" x:Name="ConvertTab" ToolTip="Batch convert various disc image formats to CHD">
6666
<Border Background="{StaticResource CardBackgroundBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" CornerRadius="0,0,6,6" Padding="15">
6767
<Grid>
@@ -123,7 +123,7 @@
123123
<Button Content="Deselect All" Click="DeselectAllConversion_Click" Style="{StaticResource ActionButtonStyle}" Margin="5,0" />
124124
</StackPanel>
125125

126-
<Button Grid.Row="6" x:Name="StartConversionButton" Content="Start Conversion" Click="StartConversionButton_Click" Style="{StaticResource StartButtonStyle}" HorizontalAlignment="Stretch" ToolTip="Begin the batch conversion process" />
126+
<Button Grid.Row="6" x:Name="StartConversionButton" Content="Start Conversion" Click="StartConversionButton_ClickAsync" Style="{StaticResource StartButtonStyle}" HorizontalAlignment="Stretch" ToolTip="Begin the batch conversion process" />
127127
</Grid>
128128
</Border>
129129
</TabItem>
@@ -173,7 +173,7 @@
173173
<Button Content="Deselect All" Click="DeselectAllVerification_Click" Style="{StaticResource ActionButtonStyle}" Margin="5,0" />
174174
</StackPanel>
175175

176-
<Button Grid.Row="5" x:Name="StartVerificationButton" Content="Start Verification" Click="StartVerificationButton_Click" Style="{StaticResource StartButtonStyle}" HorizontalAlignment="Stretch" ToolTip="Begin the batch verification process" />
176+
<Button Grid.Row="5" x:Name="StartVerificationButton" Content="Start Verification" Click="StartVerificationButton_ClickAsync" Style="{StaticResource StartButtonStyle}" HorizontalAlignment="Stretch" ToolTip="Begin the batch verification process" />
177177
</Grid>
178178
</Border>
179179
</TabItem>
@@ -256,36 +256,18 @@
256256
<Button Content="Deselect All" Click="DeselectAllExtraction_Click" Style="{StaticResource ActionButtonStyle}" Margin="5,0" />
257257
</StackPanel>
258258

259-
<Button Grid.Row="6" x:Name="StartExtractionButton" Content="Start Extraction" Click="StartExtractionButton_Click" Style="{StaticResource StartButtonStyle}" HorizontalAlignment="Stretch" ToolTip="Begin the batch extraction process" />
259+
<Button Grid.Row="6" x:Name="StartExtractionButton" Content="Start Extraction" Click="StartExtractionButton_ClickAsync" Style="{StaticResource StartButtonStyle}" HorizontalAlignment="Stretch" ToolTip="Begin the batch extraction process" />
260260
</Grid>
261261
</Border>
262262
</TabItem>
263263
</TabControl>
264264

265-
<GridSplitter Grid.Column="1" Width="10" HorizontalAlignment="Stretch" Background="Transparent" />
265+
<GridSplitter Grid.Column="1" Width="10" HorizontalAlignment="Stretch" />
266266

267267
<Border Grid.Column="2" BorderBrush="{StaticResource TerminalBorderBrush}" BorderThickness="2" CornerRadius="4" Background="{StaticResource TerminalBackgroundBrush}">
268268
<TextBox x:Name="LogViewer"
269-
AcceptsReturn="True"
270-
VerticalScrollBarVisibility="Auto"
271-
HorizontalScrollBarVisibility="Auto"
272-
VerticalAlignment="Stretch"
273-
VerticalContentAlignment="Top"
274-
IsReadOnly="True"
275-
Padding="10"
276-
FontFamily="Consolas"
277-
FontSize="12"
278-
Background="{StaticResource TerminalBackgroundBrush}"
279-
Foreground="{StaticResource TerminalForegroundBrush}"
280-
BorderThickness="0"
281-
TextAlignment="Left"
282-
TextWrapping="NoWrap"
283-
CaretBrush="{StaticResource TerminalForegroundBrush}"
284-
ToolTip="Application activity log">
285-
<TextBox.Effect>
286-
<DropShadowEffect ShadowDepth="0" Color="#39FF14" BlurRadius="2" Opacity="0.4" />
287-
</TextBox.Effect>
288-
</TextBox>
269+
Style="{StaticResource TerminalLogTextBoxWithGlow}"
270+
ToolTip="Application activity log" />
289271
</Border>
290272
</Grid>
291273

BatchConvertToCHD/MainWindow.xaml.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ public MainWindow()
9292
LogEnvironmentDetails();
9393

9494
// Defer heavy initialization until after window is shown
95-
Loaded += MainWindow_Loaded;
95+
Loaded += MainWindow_LoadedAsync;
9696

9797
// Hide speed display initially until we know counters are available
9898
SpeedStatCard.Visibility = Visibility.Collapsed;
9999
}
100100

101-
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
101+
private async void MainWindow_LoadedAsync(object sender, RoutedEventArgs e)
102102
{
103103
try
104104
{
@@ -414,8 +414,30 @@ private void MainTabControl_SelectionChanged(object sender, SelectionChangedEven
414414

415415
private void Window_Closing(object sender, CancelEventArgs e)
416416
{
417-
_cts.Cancel();
417+
// Check if any operation is currently running (buttons disabled = operation in progress)
418+
bool isOperationRunning = !StartConversionButton.IsEnabled || !StartVerificationButton.IsEnabled || !StartExtractionButton.IsEnabled;
419+
420+
if (isOperationRunning)
421+
{
422+
if (!_cts.IsCancellationRequested)
423+
{
424+
// First close attempt - cancel operations but keep window open momentarily
425+
_cts.Cancel();
426+
LogMessage("Cancelling operations before closing...");
427+
UpdateStatusBarMessage("Cancelling...");
428+
e.Cancel = true;
429+
return;
430+
}
431+
// else: Cancellation already requested, allow close but force termination
432+
// because background tasks might be stuck
433+
}
434+
435+
// Perform cleanup of resources
418436
Dispose();
437+
438+
// Ensure the application shuts down completely
439+
// This is necessary because background tasks/threads might keep the app alive
440+
Application.Current.Shutdown();
419441
}
420442

421443
private void LogMessage(string message)
@@ -486,7 +508,7 @@ private void BrowseExtractionOutputButton_Click(object sender, RoutedEventArgs e
486508
HandleFolderBrowse(ExtractionOutputFolderTextBox, "Extraction output");
487509
}
488510

489-
private async void StartExtractionButton_Click(object sender, RoutedEventArgs e)
511+
private async void StartExtractionButton_ClickAsync(object sender, RoutedEventArgs e)
490512
{
491513
try
492514
{
@@ -796,7 +818,7 @@ private void DeselectAllExtraction_Click(object sender, RoutedEventArgs e)
796818
}
797819
}
798820

799-
private async void StartConversionButton_Click(object sender, RoutedEventArgs e)
821+
private async void StartConversionButton_ClickAsync(object sender, RoutedEventArgs e)
800822
{
801823
try
802824
{
@@ -870,7 +892,7 @@ await PerformBatchConversionAsync(Path.Combine(AppDomain.CurrentDomain.BaseDirec
870892
}
871893
}
872894

873-
private async void StartVerificationButton_Click(object sender, RoutedEventArgs e)
895+
private async void StartVerificationButton_ClickAsync(object sender, RoutedEventArgs e)
874896
{
875897
try
876898
{
@@ -2270,6 +2292,8 @@ private void ResetSpeedCounters()
22702292

22712293
private void ExitMenuItem_Click(object sender, RoutedEventArgs e)
22722294
{
2295+
// Ensure the window close process is initiated
2296+
// The Window_Closing event will handle proper cleanup and shutdown
22732297
Close();
22742298
}
22752299

0 commit comments

Comments
 (0)