Skip to content

Commit a078777

Browse files
committed
- Fixed an issue where font settings were not applied when using the Blur theme
- Removed bold style from highlight and delegated it to individual themes
1 parent ec22f59 commit a078777

File tree

6 files changed

+155
-30
lines changed

6 files changed

+155
-30
lines changed

Flow.Launcher.Core/Resource/Theme.cs

+140-16
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Theme(IPublicAPI publicAPI, Settings settings)
7272
}
7373
else
7474
{
75-
Log.Error("현재 테마 리소스를 찾을 수 없습니다. 기본 테마로 초기화합니다.");
75+
Log.Error("Current theme resource not found. Initializing with default theme.");
7676
_oldTheme = Constant.DefaultTheme;
7777
};
7878
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
@@ -104,26 +104,149 @@ private void MakeSureThemeDirectoriesExist()
104104

105105
private void UpdateResourceDictionary(ResourceDictionary dictionaryToUpdate)
106106
{
107-
// 새 테마 리소스를 먼저 추가하고
107+
// Add the new theme resource first
108108
if (!Application.Current.Resources.MergedDictionaries.Contains(dictionaryToUpdate))
109109
{
110110
Application.Current.Resources.MergedDictionaries.Add(dictionaryToUpdate);
111111
}
112112

113-
// 그 다음 이전 테마 리소스 제거
113+
// Then remove the old theme resource
114114
if (_oldResource != null &&
115115
_oldResource != dictionaryToUpdate &&
116116
Application.Current.Resources.MergedDictionaries.Contains(_oldResource))
117117
{
118118
Application.Current.Resources.MergedDictionaries.Remove(_oldResource);
119119
}
120-
121120
_oldResource = dictionaryToUpdate;
122-
123-
// 리소스 변경 후 문제가 없는지 검증
124-
Debug.WriteLine($"테마 변경 후 리소스 딕셔너리 수: {Application.Current.Resources.MergedDictionaries.Count}");
125121
}
126122

123+
/// <summary>
124+
/// Updates only the font settings and refreshes the UI.
125+
/// </summary>
126+
public void UpdateFonts()
127+
{
128+
try
129+
{
130+
// Loads a ResourceDictionary for the specified theme.
131+
var themeName = GetCurrentTheme();
132+
var dict = GetThemeResourceDictionary(themeName);
133+
134+
// Applies font settings to the theme resource.
135+
ApplyFontSettings(dict);
136+
UpdateResourceDictionary(dict);
137+
_ = RefreshFrameAsync();
138+
}
139+
catch (Exception e)
140+
{
141+
Log.Exception("Error occurred while updating theme fonts", e);
142+
}
143+
}
144+
145+
/// <summary>
146+
/// Loads and applies font settings to the theme resource.
147+
/// </summary>
148+
private void ApplyFontSettings(ResourceDictionary dict)
149+
{
150+
if (dict["QueryBoxStyle"] is Style queryBoxStyle &&
151+
dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle)
152+
{
153+
var fontFamily = new FontFamily(_settings.QueryBoxFont);
154+
var fontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.QueryBoxFontStyle);
155+
var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.QueryBoxFontWeight);
156+
var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.QueryBoxFontStretch);
157+
158+
SetFontProperties(queryBoxStyle, fontFamily, fontStyle, fontWeight, fontStretch, true);
159+
SetFontProperties(querySuggestionBoxStyle, fontFamily, fontStyle, fontWeight, fontStretch, false);
160+
}
161+
162+
if (dict["ItemTitleStyle"] is Style resultItemStyle &&
163+
dict["ItemTitleSelectedStyle"] is Style resultItemSelectedStyle &&
164+
dict["ItemHotkeyStyle"] is Style resultHotkeyItemStyle &&
165+
dict["ItemHotkeySelectedStyle"] is Style resultHotkeyItemSelectedStyle)
166+
{
167+
var fontFamily = new FontFamily(_settings.ResultFont);
168+
var fontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultFontStyle);
169+
var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultFontWeight);
170+
var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultFontStretch);
171+
172+
SetFontProperties(resultItemStyle, fontFamily, fontStyle, fontWeight, fontStretch, false);
173+
SetFontProperties(resultItemSelectedStyle, fontFamily, fontStyle, fontWeight, fontStretch, false);
174+
SetFontProperties(resultHotkeyItemStyle, fontFamily, fontStyle, fontWeight, fontStretch, false);
175+
SetFontProperties(resultHotkeyItemSelectedStyle, fontFamily, fontStyle, fontWeight, fontStretch, false);
176+
}
177+
178+
if (dict["ItemSubTitleStyle"] is Style resultSubItemStyle &&
179+
dict["ItemSubTitleSelectedStyle"] is Style resultSubItemSelectedStyle)
180+
{
181+
var fontFamily = new FontFamily(_settings.ResultSubFont);
182+
var fontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultSubFontStyle);
183+
var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultSubFontWeight);
184+
var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultSubFontStretch);
185+
186+
SetFontProperties(resultSubItemStyle, fontFamily, fontStyle, fontWeight, fontStretch, false);
187+
SetFontProperties(resultSubItemSelectedStyle, fontFamily, fontStyle, fontWeight, fontStretch, false);
188+
}
189+
}
190+
191+
/// <summary>
192+
/// Applies font properties to a Style.
193+
/// </summary>
194+
private void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, bool isTextBox)
195+
{
196+
// Remove existing font-related setters
197+
if (isTextBox)
198+
{
199+
// First, find the setters to remove and store them in a list
200+
var settersToRemove = style.Setters
201+
.OfType<Setter>()
202+
.Where(setter =>
203+
setter.Property == TextBox.FontFamilyProperty ||
204+
setter.Property == TextBox.FontStyleProperty ||
205+
setter.Property == TextBox.FontWeightProperty ||
206+
setter.Property == TextBox.FontStretchProperty)
207+
.ToList();
208+
209+
// Remove each found setter one by one
210+
foreach (var setter in settersToRemove)
211+
{
212+
style.Setters.Remove(setter);
213+
}
214+
215+
// Add New font setter
216+
style.Setters.Add(new Setter(TextBox.FontFamilyProperty, fontFamily));
217+
style.Setters.Add(new Setter(TextBox.FontStyleProperty, fontStyle));
218+
style.Setters.Add(new Setter(TextBox.FontWeightProperty, fontWeight));
219+
style.Setters.Add(new Setter(TextBox.FontStretchProperty, fontStretch));
220+
221+
// Set caret brush (retain existing logic)
222+
var caretBrushPropertyValue = style.Setters.OfType<Setter>().Any(x => x.Property.Name == "CaretBrush");
223+
var foregroundPropertyValue = style.Setters.OfType<Setter>().Where(x => x.Property.Name == "Foreground")
224+
.Select(x => x.Value).FirstOrDefault();
225+
if (!caretBrushPropertyValue && foregroundPropertyValue != null)
226+
style.Setters.Add(new Setter(TextBox.CaretBrushProperty, foregroundPropertyValue));
227+
}
228+
else
229+
{
230+
var settersToRemove = style.Setters
231+
.OfType<Setter>()
232+
.Where(setter =>
233+
setter.Property == TextBlock.FontFamilyProperty ||
234+
setter.Property == TextBlock.FontStyleProperty ||
235+
setter.Property == TextBlock.FontWeightProperty ||
236+
setter.Property == TextBlock.FontStretchProperty)
237+
.ToList();
238+
239+
foreach (var setter in settersToRemove)
240+
{
241+
style.Setters.Remove(setter);
242+
}
243+
244+
style.Setters.Add(new Setter(TextBlock.FontFamilyProperty, fontFamily));
245+
style.Setters.Add(new Setter(TextBlock.FontStyleProperty, fontStyle));
246+
style.Setters.Add(new Setter(TextBlock.FontWeightProperty, fontWeight));
247+
style.Setters.Add(new Setter(TextBlock.FontStretchProperty, fontStretch));
248+
}
249+
}
127250
private ResourceDictionary GetThemeResourceDictionary(string theme)
128251
{
129252
var uri = GetThemePath(theme);
@@ -286,9 +409,10 @@ public bool ChangeTheme(string theme = null)
286409
if (string.IsNullOrEmpty(path))
287410
throw new DirectoryNotFoundException("Theme path can't be found <{path}>");
288411

289-
// reload all resources even if the theme itself hasn't changed in order to pickup changes
290-
// to things like fonts
291-
UpdateResourceDictionary(GetResourceDictionary(theme));
412+
// Retrieve theme resource – always use the resource with font settings applied.
413+
var resourceDict = GetResourceDictionary(theme);
414+
415+
UpdateResourceDictionary(resourceDict);
292416

293417
_settings.Theme = theme;
294418

@@ -299,10 +423,11 @@ public bool ChangeTheme(string theme = null)
299423
}
300424

301425
BlurEnabled = IsBlurTheme();
302-
//if (_settings.UseDropShadowEffect)
303-
// AddDropShadowEffectToCurrentTheme();
304-
//Win32Helper.SetBlurForWindow(Application.Current.MainWindow, BlurEnabled);
305-
_ = SetBlurForWindowAsync();
426+
427+
// 블러 및 그림자 효과 적용을 위한 비동기 처리
428+
_ = RefreshFrameAsync();
429+
430+
return true;
306431
}
307432
catch (DirectoryNotFoundException)
308433
{
@@ -324,7 +449,6 @@ public bool ChangeTheme(string theme = null)
324449
}
325450
return false;
326451
}
327-
return true;
328452
}
329453

330454
#endregion
@@ -500,7 +624,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
500624

501625
private void SetBlurForWindow(string theme, BackdropTypes backdropType)
502626
{
503-
var dict = GetThemeResourceDictionary(theme);
627+
var dict = GetResourceDictionary(theme); // GetThemeResourceDictionary 대신 GetResourceDictionary 사용
504628
if (dict == null)
505629
return;
506630

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public FontFamily SelectedQueryBoxFont
342342
set
343343
{
344344
Settings.QueryBoxFont = value.ToString();
345-
_theme.ChangeTheme();
345+
_theme.UpdateFonts();
346346
}
347347
}
348348

@@ -364,7 +364,7 @@ public FamilyTypeface SelectedQueryBoxFontFaces
364364
Settings.QueryBoxFontStretch = value.Stretch.ToString();
365365
Settings.QueryBoxFontWeight = value.Weight.ToString();
366366
Settings.QueryBoxFontStyle = value.Style.ToString();
367-
_theme.ChangeTheme();
367+
_theme.UpdateFonts();
368368
}
369369
}
370370

@@ -386,7 +386,7 @@ public FontFamily SelectedResultFont
386386
set
387387
{
388388
Settings.ResultFont = value.ToString();
389-
_theme.ChangeTheme();
389+
_theme.UpdateFonts();
390390
}
391391
}
392392

@@ -408,7 +408,7 @@ public FamilyTypeface SelectedResultFontFaces
408408
Settings.ResultFontStretch = value.Stretch.ToString();
409409
Settings.ResultFontWeight = value.Weight.ToString();
410410
Settings.ResultFontStyle = value.Style.ToString();
411-
_theme.ChangeTheme();
411+
_theme.UpdateFonts();
412412
}
413413
}
414414

@@ -432,7 +432,7 @@ public FontFamily SelectedResultSubFont
432432
set
433433
{
434434
Settings.ResultSubFont = value.ToString();
435-
_theme.ChangeTheme();
435+
_theme.UpdateFonts();
436436
}
437437
}
438438

@@ -453,7 +453,7 @@ public FamilyTypeface SelectedResultSubFontFaces
453453
Settings.ResultSubFontStretch = value.Stretch.ToString();
454454
Settings.ResultSubFontWeight = value.Weight.ToString();
455455
Settings.ResultSubFontStyle = value.Style.ToString();
456-
_theme.ChangeTheme();
456+
_theme.UpdateFonts();
457457
}
458458
}
459459

Flow.Launcher/Themes/Base.xaml

-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<Style x:Key="BaseQueryBoxStyle" TargetType="{x:Type TextBox}">
2828
<Setter Property="BorderThickness" Value="0" />
2929
<Setter Property="FontSize" Value="28" />
30-
<Setter Property="FontWeight" Value="Regular" />
3130
<Setter Property="Margin" Value="16 7 0 7" />
3231
<Setter Property="Padding" Value="0 0 68 0" />
3332
<Setter Property="Background" Value="Transparent" />
@@ -181,12 +180,10 @@
181180
<Style x:Key="BaseItemTitleStyle" TargetType="{x:Type TextBlock}">
182181
<Setter Property="Foreground" Value="#FFFFF8" />
183182
<Setter Property="FontSize" Value="16" />
184-
<Setter Property="FontWeight" Value="Medium" />
185183
</Style>
186184
<Style x:Key="BaseItemSubTitleStyle" TargetType="{x:Type TextBlock}">
187185
<Setter Property="Foreground" Value="#D9D9D4" />
188186
<Setter Property="FontSize" Value="13" />
189-
<Setter Property="FontWeight" Value="Normal" />
190187
<Style.Triggers>
191188
<DataTrigger Binding="{Binding ElementName=SubTitle, UpdateSourceTrigger=PropertyChanged, Path=Text.Length}" Value="0">
192189
<Setter Property="Height" Value="0" />
@@ -218,7 +215,6 @@
218215
<Style x:Key="BaseItemTitleSelectedStyle" TargetType="{x:Type TextBlock}">
219216
<Setter Property="Foreground" Value="#FFFFF8" />
220217
<Setter Property="FontSize" Value="16" />
221-
<Setter Property="FontWeight" Value="Normal" />
222218
</Style>
223219
<Style x:Key="BaseItemSubTitleSelectedStyle" TargetType="{x:Type TextBlock}">
224220
<Setter Property="Foreground" Value="#D9D9D4" />
@@ -352,7 +348,6 @@
352348
</Style>
353349
<Style x:Key="BaseSeparatorStyle" TargetType="Rectangle" />
354350
<Style x:Key="HighlightStyle">
355-
<Setter Property="Inline.FontWeight" Value="Bold" />
356351
</Style>
357352
<Style x:Key="BaseItemHotkeyStyle" TargetType="{x:Type TextBlock}">
358353
<Setter Property="FontSize" Value="15" />

Flow.Launcher/Themes/BlurBlack Darker.xaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
</Setter.Value>
5555
</Setter>
5656
</Style>
57-
57+
<Style x:Key="HighlightStyle">
58+
<Setter Property="Inline.FontWeight" Value="Bold" />
59+
</Style>
5860
<Style
5961
x:Key="SeparatorStyle"
6062
BasedOn="{StaticResource BaseSeparatorStyle}"

Flow.Launcher/Themes/BlurBlack.xaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
</Setter.Value>
5353
</Setter>
5454
</Style>
55-
55+
<Style x:Key="HighlightStyle">
56+
<Setter Property="Inline.FontWeight" Value="Bold" />
57+
</Style>
5658
<Style
5759
x:Key="SeparatorStyle"
5860
BasedOn="{StaticResource BaseSeparatorStyle}"

Flow.Launcher/Themes/BlurWhite.xaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@
6060
<Setter Property="BorderBrush" Value="#aaaaaa" />
6161
<Setter Property="CornerRadius" Value="0" />
6262
</Style>
63-
63+
<Style x:Key="HighlightStyle">
64+
<Setter Property="Inline.FontWeight" Value="Bold" />
65+
</Style>
6466
<Style
6567
x:Key="WindowStyle"
6668
BasedOn="{StaticResource BaseWindowStyle}"

0 commit comments

Comments
 (0)