22using Avalonia . Controls ;
33using Avalonia . Layout ;
44using Avalonia . Media ;
5+ using Avalonia . Styling ;
56using Avalonia . Threading ;
67using UniGetUI . Avalonia . ViewModels . Pages . LogPages ;
78using UniGetUI . Core . Tools ;
@@ -13,8 +14,11 @@ namespace UniGetUI.Avalonia.Views.DialogPages;
1314
1415public partial class OperationFailedDialog : Window
1516{
17+ private readonly AbstractOperation _operation ;
18+
1619 public OperationFailedDialog ( AbstractOperation operation )
1720 {
21+ _operation = operation ;
1822 InitializeComponent ( ) ;
1923 UniGetUI . Avalonia . Infrastructure . MicaWindowHelper . Apply ( this ) ;
2024 Title = operation . Metadata . FailureMessage ;
@@ -25,23 +29,9 @@ public OperationFailedDialog(AbstractOperation operation)
2529 "Please see the Command-line Output or refer to the Operation History for further information about the issue."
2630 ) ;
2731
28- var errorBrush = new SolidColorBrush ( Color . Parse ( "#FF6B6B" ) ) ;
29- var debugBrush = new SolidColorBrush ( Color . Parse ( "#888888" ) ) ;
30- var normalBrush = Application . Current ? . FindResource ( "SystemControlForegroundBaseHighBrush" ) as IBrush
31- ?? Brushes . White ;
32-
33- var lines = new List < LogLineItem > ( ) ;
34- foreach ( var ( text , type ) in operation . GetOutput ( ) )
35- {
36- IBrush brush = type switch
37- {
38- AbstractOperation . LineType . Error => errorBrush ,
39- AbstractOperation . LineType . VerboseDetails => debugBrush ,
40- _ => normalBrush ,
41- } ;
42- lines . Add ( new LogLineItem ( text , brush ) ) ;
43- }
44- OutputText . SetLines ( lines ) ;
32+ PopulateOutput ( ) ;
33+ // Line brushes are baked per theme; recolor so they follow a live theme switch.
34+ ActualThemeVariantChanged += ( _ , _ ) => PopulateOutput ( ) ;
4535
4636 var closeButton = new Button
4737 {
@@ -59,6 +49,36 @@ public OperationFailedDialog(AbstractOperation operation)
5949 Grid . SetColumn ( closeButton , 1 ) ;
6050 }
6151
52+ private void PopulateOutput ( )
53+ {
54+ // Resolve against the actual theme variant; bare FindResource picks the light-theme
55+ // foreground (near-black) even in dark mode, making normal lines unreadable (#5032).
56+ var theme = Infrastructure . ThemeHelper . Variant ;
57+ var errorBrush = new SolidColorBrush ( Color . Parse ( "#FF6B6B" ) ) ;
58+ var debugBrush = new SolidColorBrush ( Color . Parse ( "#888888" ) ) ;
59+ var normalBrush = LookupBrush ( "SystemControlForegroundBaseHighBrush" , theme , Brushes . White ) ;
60+
61+ var lines = new List < LogLineItem > ( ) ;
62+ foreach ( var ( text , type ) in _operation . GetOutput ( ) )
63+ {
64+ IBrush brush = type switch
65+ {
66+ AbstractOperation . LineType . Error => errorBrush ,
67+ AbstractOperation . LineType . VerboseDetails => debugBrush ,
68+ _ => normalBrush ,
69+ } ;
70+ lines . Add ( new LogLineItem ( text , brush ) ) ;
71+ }
72+ OutputText . SetLines ( lines ) ;
73+ }
74+
75+ private static IBrush LookupBrush ( string key , ThemeVariant theme , IBrush fallback )
76+ {
77+ if ( Application . Current ? . TryGetResource ( key , theme , out var resource ) == true && resource is IBrush brush )
78+ return brush ;
79+ return fallback ;
80+ }
81+
6282 protected override void OnOpened ( EventArgs e )
6383 {
6484 base . OnOpened ( e ) ;
0 commit comments