Skip to content

Commit 25ae2da

Browse files
authored
Merge pull request #3487 from onesounds/250424-ImproveFontFamilyinControl
Improve Setting Window Font & Format xaml styles & Fix log message & Improve code quality
2 parents 3da3c59 + c35eca2 commit 25ae2da

File tree

56 files changed

+633
-527
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

+633
-527
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

+2-3
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

+3
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;
@@ -113,6 +114,8 @@ public string SettingWindowFont
113114
{
114115
_settingWindowFont = value;
115116
OnPropertyChanged();
117+
Application.Current.Resources["SettingWindowFont"] = new FontFamily(value);
118+
Application.Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(value);
116119
}
117120
}
118121
}

Flow.Launcher/ActionKeywords.xaml

+10-10
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

+32-11
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

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Width="530"
99
Background="{DynamicResource PopuBGColor}"
1010
DataContext="{Binding RelativeSource={RelativeSource Self}}"
11-
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
1211
Foreground="{DynamicResource PopupTextColor}"
1312
Icon="Images\app.png"
1413
MouseDown="window_MouseDown"

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ namespace Flow.Launcher
1010
{
1111
public partial class CustomQueryHotkeySetting : Window
1212
{
13-
public Settings Settings { get; }
13+
private readonly Settings _settings;
1414

1515
private bool update;
1616
private CustomPluginHotkey updateCustomHotkey;
1717

1818
public CustomQueryHotkeySetting(Settings settings)
1919
{
20-
Settings = settings;
20+
_settings = settings;
2121
InitializeComponent();
2222
}
2323

@@ -30,13 +30,13 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
3030
{
3131
if (!update)
3232
{
33-
Settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
33+
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
3434

3535
var pluginHotkey = new CustomPluginHotkey
3636
{
3737
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
3838
};
39-
Settings.CustomPluginHotkeys.Add(pluginHotkey);
39+
_settings.CustomPluginHotkeys.Add(pluginHotkey);
4040

4141
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
4242
}
@@ -55,7 +55,7 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
5555

5656
public void UpdateItem(CustomPluginHotkey item)
5757
{
58-
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
58+
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
5959
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
6060
if (updateCustomHotkey == null)
6161
{

Flow.Launcher/CustomShortcutSetting.xaml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Width="530"
88
Background="{DynamicResource PopuBGColor}"
99
DataContext="{Binding RelativeSource={RelativeSource Self}}"
10-
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
1110
Foreground="{DynamicResource PopupTextColor}"
1211
Icon="Images\app.png"
1312
ResizeMode="NoResize"

Flow.Launcher/CustomShortcutSetting.xaml.cs

-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
using System.Windows;
22
using System.Windows.Input;
3-
using CommunityToolkit.Mvvm.DependencyInjection;
4-
using Flow.Launcher.Infrastructure.UserSettings;
53
using Flow.Launcher.SettingPages.ViewModels;
64

75
namespace Flow.Launcher
86
{
97
public partial class CustomShortcutSetting : Window
108
{
11-
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();
12-
139
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
1410
public string Key { get; set; } = string.Empty;
1511
public string Value { get; set; } = string.Empty;

0 commit comments

Comments
 (0)