Skip to content

Commit c4b9922

Browse files
authored
Merge branch 'dev' into 250422-FixClockwhenStartUp
2 parents 31ec4ea + 25ae2da commit c4b9922

File tree

56 files changed

+774
-589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+774
-589
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
113113
// If can parse the default value to bool, use it, otherwise use false
114114
: value is string stringValue && bool.TryParse(stringValue, out var boolValueFromString)
115115
&& boolValueFromString;
116-
checkBox.Dispatcher.Invoke(() =>checkBox.IsChecked = isChecked);
116+
checkBox.Dispatcher.Invoke(() => checkBox.IsChecked = isChecked);
117117
break;
118118
}
119119
}
@@ -154,8 +154,7 @@ public bool NeedCreateSettingPanel()
154154

155155
public Control CreateSettingPanel()
156156
{
157-
// No need to check if NeedCreateSettingPanel is true because CreateSettingPanel will only be called if it's true
158-
// if (!NeedCreateSettingPanel()) return null;
157+
if (!NeedCreateSettingPanel()) return null!;
159158

160159
// Create main grid with two columns (Column 1: Auto, Column 2: *)
161160
var mainPanel = new Grid { Margin = SettingPanelMargin, VerticalAlignment = VerticalAlignment.Center };

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.ObjectModel;
33
using System.Text.Json.Serialization;
44
using System.Windows;
5+
using System.Windows.Media;
56
using CommunityToolkit.Mvvm.DependencyInjection;
67
using Flow.Launcher.Infrastructure.Hotkey;
78
using Flow.Launcher.Infrastructure.Logger;
@@ -31,7 +32,7 @@ public void Save()
3132
{
3233
_storage.Save();
3334
}
34-
35+
3536
private string _theme = Constant.DefaultTheme;
3637
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
3738
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
@@ -103,6 +104,22 @@ public string Theme
103104
public bool ShowBadges { get; set; } = false;
104105
public bool ShowBadgesGlobalOnly { get; set; } = false;
105106

107+
private string _settingWindowFont { get; set; } = Win32Helper.GetSystemDefaultFont(false);
108+
public string SettingWindowFont
109+
{
110+
get => _settingWindowFont;
111+
set
112+
{
113+
if (_settingWindowFont != value)
114+
{
115+
_settingWindowFont = value;
116+
OnPropertyChanged();
117+
Application.Current.Resources["SettingWindowFont"] = new FontFamily(value);
118+
Application.Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(value);
119+
}
120+
}
121+
}
122+
106123
public bool UseClock { get; set; } = true;
107124
public bool UseDate { get; set; } = false;
108125
public string TimeFormat { get; set; } = "hh:mm tt";

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -628,21 +628,33 @@ public static void OpenImeSettings()
628628
{ "pt", "Noto Sans" }
629629
};
630630

631-
public static string GetSystemDefaultFont()
631+
/// <summary>
632+
/// Gets the system default font.
633+
/// </summary>
634+
/// <param name="useNoto">
635+
/// If true, it will try to find the Noto font for the current culture.
636+
/// </param>
637+
/// <returns>
638+
/// The name of the system default font.
639+
/// </returns>
640+
public static string GetSystemDefaultFont(bool useNoto = true)
632641
{
633642
try
634643
{
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))
644+
if (useNoto)
641645
{
642-
// If the font is installed, return it
643-
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
646+
var culture = CultureInfo.CurrentCulture;
647+
var language = culture.Name; // e.g., "zh-TW"
648+
var langPrefix = language.Split('-')[0]; // e.g., "zh"
649+
650+
// First, try to find by full name, and if not found, fallback to prefix
651+
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
644652
{
645-
return notoFont;
653+
// If the font is installed, return it
654+
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
655+
{
656+
return notoFont;
657+
}
646658
}
647659
}
648660

Flow.Launcher/ActionKeywords.xaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@
5353
</Button>
5454
</Grid>
5555
</StackPanel>
56-
<StackPanel Margin="26,12,26,0">
57-
<StackPanel Grid.Row="0" Margin="0,0,0,12">
56+
<StackPanel Margin="26 12 26 0">
57+
<StackPanel Grid.Row="0" Margin="0 0 0 12">
5858
<TextBlock
5959
Grid.Column="0"
60-
Margin="0,0,0,0"
60+
Margin="0 0 0 0"
6161
FontSize="20"
6262
FontWeight="SemiBold"
6363
Text="{DynamicResource actionKeywordsTitle}"
@@ -71,7 +71,7 @@
7171
TextWrapping="WrapWithOverflow" />
7272
</StackPanel>
7373

74-
<StackPanel Margin="0,18,0,0" Orientation="Horizontal">
74+
<StackPanel Margin="0 18 0 0" Orientation="Horizontal">
7575
<TextBlock
7676
Grid.Row="0"
7777
Grid.Column="1"
@@ -83,14 +83,14 @@
8383
x:Name="tbOldActionKeyword"
8484
Grid.Row="0"
8585
Grid.Column="1"
86-
Margin="14,10,10,10"
86+
Margin="14 10 10 10"
8787
HorizontalAlignment="Left"
8888
VerticalAlignment="Center"
8989
FontSize="14"
9090
FontWeight="SemiBold"
9191
Foreground="{DynamicResource Color05B}" />
9292
</StackPanel>
93-
<StackPanel Margin="0,0,0,10" Orientation="Horizontal">
93+
<StackPanel Margin="0 0 0 10" Orientation="Horizontal">
9494
<TextBlock
9595
Grid.Row="1"
9696
Grid.Column="1"
@@ -101,7 +101,7 @@
101101
<TextBox
102102
x:Name="tbAction"
103103
Width="105"
104-
Margin="10,10,15,10"
104+
Margin="10 10 15 10"
105105
HorizontalAlignment="Left"
106106
VerticalAlignment="Center" />
107107
</StackPanel>
@@ -112,20 +112,20 @@
112112
Grid.Row="1"
113113
Background="{DynamicResource PopupButtonAreaBGColor}"
114114
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
115-
BorderThickness="0,1,0,0">
115+
BorderThickness="0 1 0 0">
116116
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
117117
<Button
118118
x:Name="btnCancel"
119119
Width="145"
120120
Height="30"
121-
Margin="10,0,5,0"
121+
Margin="10 0 5 0"
122122
Click="BtnCancel_OnClick"
123123
Content="{DynamicResource cancel}" />
124124
<Button
125125
x:Name="btnDone"
126126
Width="145"
127127
Height="30"
128-
Margin="5,0,10,0"
128+
Margin="5 0 10 0"
129129
Click="btnDone_OnClick"
130130
Style="{StaticResource AccentButtonStyle}">
131131
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />

Flow.Launcher/App.xaml.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using System.Windows;
7+
using System.Windows.Media;
78
using CommunityToolkit.Mvvm.DependencyInjection;
89
using Flow.Launcher.Core;
910
using Flow.Launcher.Core.Configuration;
@@ -18,6 +19,7 @@
1819
using Flow.Launcher.Infrastructure.Storage;
1920
using Flow.Launcher.Infrastructure.UserSettings;
2021
using Flow.Launcher.Plugin;
22+
using Flow.Launcher.SettingPages.ViewModels;
2123
using Flow.Launcher.ViewModel;
2224
using Microsoft.Extensions.DependencyInjection;
2325
using Microsoft.Extensions.Hosting;
@@ -29,6 +31,7 @@ public partial class App : IDisposable, ISingleInstanceApp
2931
#region Public Properties
3032

3133
public static IPublicAPI API { get; private set; }
34+
public static bool Exiting => _mainWindow.CanClose;
3235

3336
#endregion
3437

@@ -37,7 +40,7 @@ public partial class App : IDisposable, ISingleInstanceApp
3740
private static readonly string ClassName = nameof(App);
3841

3942
private static bool _disposed;
40-
private MainWindow _mainWindow;
43+
private static MainWindow _mainWindow;
4144
private readonly MainViewModel _mainVM;
4245
private readonly Settings _settings;
4346

@@ -73,14 +76,27 @@ public App()
7376
.AddSingleton(_ => _settings)
7477
.AddSingleton(sp => new Updater(sp.GetRequiredService<IPublicAPI>(), Launcher.Properties.Settings.Default.GithubRepo))
7578
.AddSingleton<Portable>()
76-
.AddSingleton<SettingWindowViewModel>()
7779
.AddSingleton<IAlphabet, PinyinAlphabet>()
7880
.AddSingleton<StringMatcher>()
7981
.AddSingleton<Internationalization>()
8082
.AddSingleton<IPublicAPI, PublicAPIInstance>()
81-
.AddSingleton<MainViewModel>()
8283
.AddSingleton<Theme>()
84+
// Use one instance for main window view model because we only have one main window
85+
.AddSingleton<MainViewModel>()
86+
// Use one instance for welcome window view model & setting window view model because
87+
// pages in welcome window & setting window need to share the same instance and
88+
// these two view models do not need to be reset when creating new windows
8389
.AddSingleton<WelcomeViewModel>()
90+
.AddSingleton<SettingWindowViewModel>()
91+
// Use transient instance for setting window page view models because
92+
// pages in setting window need to be recreated when setting window is closed
93+
.AddTransient<SettingsPaneAboutViewModel>()
94+
.AddTransient<SettingsPaneGeneralViewModel>()
95+
.AddTransient<SettingsPaneHotkeyViewModel>()
96+
.AddTransient<SettingsPanePluginsViewModel>()
97+
.AddTransient<SettingsPanePluginStoreViewModel>()
98+
.AddTransient<SettingsPaneProxyViewModel>()
99+
.AddTransient<SettingsPaneThemeViewModel>()
84100
).Build();
85101
Ioc.Default.ConfigureServices(host.Services);
86102
}
@@ -146,10 +162,14 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
146162

147163
Log.SetLogLevel(_settings.LogLevel);
148164

165+
// Update dynamic resources base on settings
166+
Current.Resources["SettingWindowFont"] = new FontFamily(_settings.SettingWindowFont);
167+
Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(_settings.SettingWindowFont);
168+
149169
Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();
150170

151171
API.LogInfo(ClassName, "Begin Flow Launcher startup ----------------------------------------------------");
152-
API.LogInfo(ClassName, "Runtime info:{ErrorReporting.RuntimeInfo()}");
172+
API.LogInfo(ClassName, $"Runtime info:{ErrorReporting.RuntimeInfo()}");
153173

154174
RegisterAppDomainExceptions();
155175
RegisterDispatcherUnhandledException();
@@ -169,19 +189,16 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
169189
await PluginManager.InitializePluginsAsync();
170190

171191
// Change language after all plugins are initialized because we need to update plugin title based on their api
172-
// TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future
173192
await Ioc.Default.GetRequiredService<Internationalization>().InitializeLanguageAsync();
174193

175194
await imageLoadertask;
176195

177196
_mainWindow = new MainWindow();
178197

179-
API.LogInfo(ClassName, "Dependencies Info:{ErrorReporting.DependenciesInfo()}");
180-
181198
Current.MainWindow = _mainWindow;
182199
Current.MainWindow.Title = Constant.FlowLauncher;
183200

184-
// main windows needs initialized before theme change because of blur settings
201+
// Main windows needs initialized before theme change because of blur settings
185202
Ioc.Default.GetRequiredService<Theme>().ChangeTheme();
186203

187204
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
@@ -198,6 +215,10 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
198215

199216
#pragma warning restore VSTHRD100 // Avoid async void methods
200217

218+
/// <summary>
219+
/// Check startup only for Release
220+
/// </summary>
221+
[Conditional("RELEASE")]
201222
private void AutoStartup()
202223
{
203224
// we try to enable auto-startup on first launch, or reenable if it was removed
@@ -261,7 +282,7 @@ private void RegisterExitEvents()
261282
}
262283

263284
/// <summary>
264-
/// let exception throw as normal is better for Debug
285+
/// Let exception throw as normal is better for Debug
265286
/// </summary>
266287
[Conditional("RELEASE")]
267288
private void RegisterDispatcherUnhandledException()
@@ -270,7 +291,7 @@ private void RegisterDispatcherUnhandledException()
270291
}
271292

272293
/// <summary>
273-
/// let exception throw as normal is better for Debug
294+
/// Let exception throw as normal is better for Debug
274295
/// </summary>
275296
[Conditional("RELEASE")]
276297
private static void RegisterAppDomainExceptions()
@@ -279,7 +300,7 @@ private static void RegisterAppDomainExceptions()
279300
}
280301

281302
/// <summary>
282-
/// let exception throw as normal is better for Debug
303+
/// Let exception throw as normal is better for Debug
283304
/// </summary>
284305
[Conditional("RELEASE")]
285306
private static void RegisterTaskSchedulerUnhandledException()

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
using Flow.Launcher.Helper;
2-
using Flow.Launcher.Infrastructure.UserSettings;
3-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
42
using System.Linq;
53
using System.Windows;
64
using System.Windows.Input;
75
using System.Windows.Controls;
6+
using Flow.Launcher.Helper;
7+
using Flow.Launcher.Infrastructure.UserSettings;
88

99
namespace Flow.Launcher
1010
{
1111
public partial class CustomQueryHotkeySetting : Window
1212
{
1313
private readonly Settings _settings;
14+
1415
private bool update;
1516
private CustomPluginHotkey updateCustomHotkey;
1617

0 commit comments

Comments
 (0)