Skip to content

Commit 0591970

Browse files
authored
Merge pull request #3458 from onesounds/250412-ImportThemePreset
Import Theme Size / Select Default Font / Small Design Fixes
2 parents a088e42 + 5cea434 commit 0591970

File tree

16 files changed

+320
-92
lines changed

16 files changed

+320
-92
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ private ResourceDictionary GetResourceDictionary(string theme)
325325
return dict;
326326
}
327327

328-
private ResourceDictionary GetCurrentResourceDictionary()
328+
public ResourceDictionary GetCurrentResourceDictionary()
329329
{
330330
return GetResourceDictionary(_settings.Theme);
331331
}
@@ -772,22 +772,18 @@ private void ApplyPreviewBackground(Color? bgColor = null)
772772
{
773773
if (bgColor == null) return;
774774

775-
// Copy the existing WindowBorderStyle
775+
// Create a new Style for the preview
776776
var previewStyle = new Style(typeof(Border));
777-
if (Application.Current.Resources.Contains("WindowBorderStyle"))
777+
778+
// Get the original WindowBorderStyle
779+
if (Application.Current.Resources.Contains("WindowBorderStyle") &&
780+
Application.Current.Resources["WindowBorderStyle"] is Style originalStyle)
778781
{
779-
if (Application.Current.Resources["WindowBorderStyle"] is Style originalStyle)
780-
{
781-
foreach (var setter in originalStyle.Setters.OfType<Setter>())
782-
{
783-
previewStyle.Setters.Add(new Setter(setter.Property, setter.Value));
784-
}
785-
}
782+
// Copy the original style, including the base style if it exists
783+
CopyStyle(originalStyle, previewStyle);
786784
}
787785

788786
// Apply background color (remove transparency in color)
789-
// WPF does not allow the use of an acrylic brush within the window's internal area,
790-
// so transparency effects are not applied to the preview.
791787
Color backgroundColor = Color.FromRgb(bgColor.Value.R, bgColor.Value.G, bgColor.Value.B);
792788
previewStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(backgroundColor)));
793789

@@ -798,9 +794,26 @@ private void ApplyPreviewBackground(Color? bgColor = null)
798794
previewStyle.Setters.Add(new Setter(Border.CornerRadiusProperty, new CornerRadius(5)));
799795
previewStyle.Setters.Add(new Setter(Border.BorderThicknessProperty, new Thickness(1)));
800796
}
797+
798+
// Set the new style to the resource
801799
Application.Current.Resources["PreviewWindowBorderStyle"] = previewStyle;
802800
}
803801

802+
private void CopyStyle(Style originalStyle, Style targetStyle)
803+
{
804+
// If the style is based on another style, copy the base style first
805+
if (originalStyle.BasedOn != null)
806+
{
807+
CopyStyle(originalStyle.BasedOn, targetStyle);
808+
}
809+
810+
// Copy the setters from the original style
811+
foreach (var setter in originalStyle.Setters.OfType<Setter>())
812+
{
813+
targetStyle.Setters.Add(new Setter(setter.Property, setter.Value));
814+
}
815+
}
816+
804817
private void ColorizeWindow(string theme, BackdropTypes backdropType)
805818
{
806819
var dict = GetThemeResourceDictionary(theme);

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
3-
using System.Drawing;
43
using System.Text.Json.Serialization;
54
using System.Windows;
65
using CommunityToolkit.Mvvm.DependencyInjection;
@@ -32,8 +31,7 @@ public void Save()
3231
{
3332
_storage.Save();
3433
}
35-
36-
private string language = Constant.SystemLanguageCode;
34+
3735
private string _theme = Constant.DefaultTheme;
3836
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
3937
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
@@ -54,12 +52,13 @@ public void Save()
5452
public string CycleHistoryUpHotkey { get; set; } = $"{KeyConstant.Alt} + Up";
5553
public string CycleHistoryDownHotkey { get; set; } = $"{KeyConstant.Alt} + Down";
5654

55+
private string _language = Constant.SystemLanguageCode;
5756
public string Language
5857
{
59-
get => language;
58+
get => _language;
6059
set
6160
{
62-
language = value;
61+
_language = value;
6362
OnPropertyChanged();
6463
}
6564
}
@@ -82,18 +81,18 @@ public string Theme
8281
/* Appearance Settings. It should be separated from the setting later.*/
8382
public double WindowHeightSize { get; set; } = 42;
8483
public double ItemHeightSize { get; set; } = 58;
85-
public double QueryBoxFontSize { get; set; } = 20;
84+
public double QueryBoxFontSize { get; set; } = 16;
8685
public double ResultItemFontSize { get; set; } = 16;
8786
public double ResultSubItemFontSize { get; set; } = 13;
88-
public string QueryBoxFont { get; set; } = FontFamily.GenericSansSerif.Name;
87+
public string QueryBoxFont { get; set; } = Win32Helper.GetSystemDefaultFont();
8988
public string QueryBoxFontStyle { get; set; }
9089
public string QueryBoxFontWeight { get; set; }
9190
public string QueryBoxFontStretch { get; set; }
92-
public string ResultFont { get; set; } = FontFamily.GenericSansSerif.Name;
91+
public string ResultFont { get; set; } = Win32Helper.GetSystemDefaultFont();
9392
public string ResultFontStyle { get; set; }
9493
public string ResultFontWeight { get; set; }
9594
public string ResultFontStretch { get; set; }
96-
public string ResultSubFont { get; set; } = FontFamily.GenericSansSerif.Name;
95+
public string ResultSubFont { get; set; } = Win32Helper.GetSystemDefaultFont();
9796
public string ResultSubFontStyle { get; set; }
9897
public string ResultSubFontWeight { get; set; }
9998
public string ResultSubFontStretch { get; set; }
@@ -116,7 +115,7 @@ public string Theme
116115
public double? SettingWindowLeft { get; set; } = null;
117116
public WindowState SettingWindowState { get; set; } = WindowState.Normal;
118117

119-
bool _showPlaceholder { get; set; } = false;
118+
private bool _showPlaceholder { get; set; } = true;
120119
public bool ShowPlaceholder
121120
{
122121
get => _showPlaceholder;
@@ -129,7 +128,7 @@ public bool ShowPlaceholder
129128
}
130129
}
131130
}
132-
string _placeholderText { get; set; } = string.Empty;
131+
private string _placeholderText { get; set; } = string.Empty;
133132
public string PlaceholderText
134133
{
135134
get => _placeholderText;
@@ -142,7 +141,6 @@ public string PlaceholderText
142141
}
143142
}
144143
}
145-
146144
public int CustomExplorerIndex { get; set; } = 0;
147145

148146
[JsonIgnore]
@@ -309,7 +307,7 @@ public bool KeepMaxResults
309307
public bool StartFlowLauncherOnSystemStartup { get; set; } = false;
310308
public bool UseLogonTaskForStartup { get; set; } = false;
311309
public bool HideOnStartup { get; set; } = true;
312-
bool _hideNotifyIcon { get; set; }
310+
private bool _hideNotifyIcon;
313311
public bool HideNotifyIcon
314312
{
315313
get => _hideNotifyIcon;

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
34
using System.Diagnostics;
45
using System.Globalization;
6+
using System.Linq;
57
using System.Runtime.InteropServices;
68
using System.Windows;
79
using System.Windows.Interop;
10+
using System.Windows.Markup;
811
using System.Windows.Media;
912
using Flow.Launcher.Infrastructure.UserSettings;
1013
using Microsoft.Win32;
@@ -14,6 +17,7 @@
1417
using Windows.Win32.UI.Input.KeyboardAndMouse;
1518
using Windows.Win32.UI.WindowsAndMessaging;
1619
using Point = System.Windows.Point;
20+
using SystemFonts = System.Windows.SystemFonts;
1721

1822
namespace Flow.Launcher.Infrastructure
1923
{
@@ -595,5 +599,73 @@ public static void OpenImeSettings()
595599
}
596600

597601
#endregion
602+
603+
#region System Font
604+
605+
private static readonly Dictionary<string, string> _languageToNotoSans = new()
606+
{
607+
{ "ko", "Noto Sans KR" },
608+
{ "ja", "Noto Sans JP" },
609+
{ "zh-CN", "Noto Sans SC" },
610+
{ "zh-SG", "Noto Sans SC" },
611+
{ "zh-Hans", "Noto Sans SC" },
612+
{ "zh-TW", "Noto Sans TC" },
613+
{ "zh-HK", "Noto Sans TC" },
614+
{ "zh-MO", "Noto Sans TC" },
615+
{ "zh-Hant", "Noto Sans TC" },
616+
{ "th", "Noto Sans Thai" },
617+
{ "ar", "Noto Sans Arabic" },
618+
{ "he", "Noto Sans Hebrew" },
619+
{ "hi", "Noto Sans Devanagari" },
620+
{ "bn", "Noto Sans Bengali" },
621+
{ "ta", "Noto Sans Tamil" },
622+
{ "el", "Noto Sans Greek" },
623+
{ "ru", "Noto Sans" },
624+
{ "en", "Noto Sans" },
625+
{ "fr", "Noto Sans" },
626+
{ "de", "Noto Sans" },
627+
{ "es", "Noto Sans" },
628+
{ "pt", "Noto Sans" }
629+
};
630+
631+
public static string GetSystemDefaultFont()
632+
{
633+
try
634+
{
635+
var culture = CultureInfo.CurrentCulture;
636+
var language = culture.Name; // e.g., "zh-TW"
637+
var langPrefix = language.Split('-')[0]; // e.g., "zh"
638+
639+
// First, try to find by full name, and if not found, fallback to prefix
640+
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
641+
{
642+
// If the font is installed, return it
643+
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
644+
{
645+
return notoFont;
646+
}
647+
}
648+
649+
// If Noto font is not found, fallback to the system default font
650+
var font = SystemFonts.MessageFontFamily;
651+
if (font.FamilyNames.TryGetValue(XmlLanguage.GetLanguage("en-US"), out var englishName))
652+
{
653+
return englishName;
654+
}
655+
656+
return font.Source ?? "Segoe UI";
657+
}
658+
catch
659+
{
660+
return "Segoe UI";
661+
}
662+
}
663+
664+
private static bool TryGetNotoFont(string langKey, out string notoFont)
665+
{
666+
return _languageToNotoSans.TryGetValue(langKey, out notoFont);
667+
}
668+
669+
#endregion
598670
}
599671
}

Flow.Launcher/Languages/en.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@
199199
<system:String x:Key="resultItemFont">Result Title Font</system:String>
200200
<system:String x:Key="resultSubItemFont">Result Subtitle Font</system:String>
201201
<system:String x:Key="resetCustomize">Reset</system:String>
202+
<system:String x:Key="resetCustomizeToolTip">Reset to the recommended font and size settings.</system:String>
203+
<system:String x:Key="ImportThemeSize">Import Theme Size</system:String>
204+
<system:String x:Key="ImportThemeSizeToolTip">If a size value intended by the theme designer is available, it will be retrieved and applied.</system:String>
202205
<system:String x:Key="CustomizeToolTip">Customize</system:String>
203206
<system:String x:Key="windowMode">Window Mode</system:String>
204207
<system:String x:Key="opacity">Opacity</system:String>
@@ -226,6 +229,7 @@
226229
<system:String x:Key="Clock">Clock</system:String>
227230
<system:String x:Key="Date">Date</system:String>
228231
<system:String x:Key="BackdropType">Backdrop Type</system:String>
232+
<system:String x:Key="BackdropInfo">The backdrop effect is not applied in the preview.</system:String>
229233
<system:String x:Key="BackdropTypeDisabledToolTip">Backdrop supported starting from Windows 11 build 22000 and above</system:String>
230234
<system:String x:Key="BackdropTypesNone">None</system:String>
231235
<system:String x:Key="BackdropTypesAcrylic">Acrylic</system:String>

0 commit comments

Comments
 (0)