Skip to content

Commit ed14c45

Browse files
committed
Refactor brush creation with ThemeHelper utility
Introduce ThemeHelper.GetFreezeSolidColorBrush to centralize and reuse SolidColorBrush creation and freezing logic. Refactor Theme.cs to use this helper, improving code clarity and maintainability. Also, use Brushes.Transparent directly where appropriate.
1 parent 9abf136 commit ed14c45

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -674,16 +674,12 @@ private void SetBlurForWindow(string theme, BackdropTypes backdropType)
674674
if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt)
675675
{
676676
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty));
677-
var brush = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
678-
brush.Freeze();
679-
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, brush));
677+
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, ThemeHelper.GetFreezeSolidColorBrush(Color.FromArgb(1, 0, 0, 0))));
680678
}
681679
else if (backdropType == BackdropTypes.Acrylic)
682680
{
683681
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty));
684-
var brush = new SolidColorBrush(Colors.Transparent);
685-
brush.Freeze();
686-
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, brush));
682+
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, Brushes.Transparent));
687683
}
688684

689685
// For themes with blur enabled, the window border is rendered by the system, so it's treated as a simple rectangle regardless of thickness.
@@ -806,10 +802,8 @@ private void ApplyPreviewBackground(Color? bgColor = null)
806802
}
807803

808804
// Apply background color (remove transparency in color)
809-
Color backgroundColor = Color.FromRgb(bgColor.Value.R, bgColor.Value.G, bgColor.Value.B);
810-
var brush = new SolidColorBrush(backgroundColor);
811-
brush.Freeze();
812-
previewStyle.Setters.Add(new Setter(Border.BackgroundProperty, brush));
805+
var backgroundColor = Color.FromRgb(bgColor.Value.R, bgColor.Value.G, bgColor.Value.B);
806+
previewStyle.Setters.Add(new Setter(Border.BackgroundProperty, ThemeHelper.GetFreezeSolidColorBrush(backgroundColor)));
813807

814808
// The blur theme keeps the corner round fixed (applying DWM code to modify it causes rendering issues).
815809
// The non-blur theme retains the previously set WindowBorderStyle.
@@ -923,15 +917,11 @@ private void ColorizeWindow(string theme, BackdropTypes backdropType)
923917
// Only set the background to transparent if the theme supports blur
924918
if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt)
925919
{
926-
var backgroundBrush = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
927-
backgroundBrush.Freeze();
928-
mainWindow.Background = backgroundBrush;
920+
mainWindow.Background = ThemeHelper.GetFreezeSolidColorBrush(Color.FromArgb(1, 0, 0, 0));
929921
}
930922
else
931923
{
932-
var backgroundBrush = new SolidColorBrush(selectedBG);
933-
backgroundBrush.Freeze();
934-
mainWindow.Background = backgroundBrush;
924+
mainWindow.Background = ThemeHelper.GetFreezeSolidColorBrush(selectedBG);
935925
}
936926
}
937927
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Windows.Media;
2+
3+
namespace Flow.Launcher.Core.Resource;
4+
5+
public static class ThemeHelper
6+
{
7+
public static SolidColorBrush GetFreezeSolidColorBrush(Color color)
8+
{
9+
var brush = new SolidColorBrush(color);
10+
brush.Freeze();
11+
return brush;
12+
}
13+
}

0 commit comments

Comments
 (0)