Skip to content

Commit 588266c

Browse files
authored
Merge branch 'dev' into quickswitch
2 parents d443a2e + 25ae2da commit 588266c

File tree

57 files changed

+771
-590
lines changed

Some content is hidden

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

57 files changed

+771
-590
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@v4
2424
- name: Set Flow.Launcher.csproj version
2525
id: update
26-
uses: vers-one/dotnet-project-version-updater@v1.5
26+
uses: vers-one/dotnet-project-version-updater@v1.7
2727
with:
2828
file: |
2929
"**/SolutionAssemblyInfo.cs"

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;
@@ -104,6 +105,22 @@ public string Theme
104105
public bool ShowBadges { get; set; } = false;
105106
public bool ShowBadgesGlobalOnly { get; set; } = false;
106107

108+
private string _settingWindowFont { get; set; } = Win32Helper.GetSystemDefaultFont(false);
109+
public string SettingWindowFont
110+
{
111+
get => _settingWindowFont;
112+
set
113+
{
114+
if (_settingWindowFont != value)
115+
{
116+
_settingWindowFont = value;
117+
OnPropertyChanged();
118+
Application.Current.Resources["SettingWindowFont"] = new FontFamily(value);
119+
Application.Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(value);
120+
}
121+
}
122+
}
123+
107124
public bool UseClock { get; set; } = true;
108125
public bool UseDate { get; set; } = false;
109126
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
@@ -643,21 +643,33 @@ public static void OpenImeSettings()
643643
{ "pt", "Noto Sans" }
644644
};
645645

646-
public static string GetSystemDefaultFont()
646+
/// <summary>
647+
/// Gets the system default font.
648+
/// </summary>
649+
/// <param name="useNoto">
650+
/// If true, it will try to find the Noto font for the current culture.
651+
/// </param>
652+
/// <returns>
653+
/// The name of the system default font.
654+
/// </returns>
655+
public static string GetSystemDefaultFont(bool useNoto = true)
647656
{
648657
try
649658
{
650-
var culture = CultureInfo.CurrentCulture;
651-
var language = culture.Name; // e.g., "zh-TW"
652-
var langPrefix = language.Split('-')[0]; // e.g., "zh"
653-
654-
// First, try to find by full name, and if not found, fallback to prefix
655-
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
659+
if (useNoto)
656660
{
657-
// If the font is installed, return it
658-
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
661+
var culture = CultureInfo.CurrentCulture;
662+
var language = culture.Name; // e.g., "zh-TW"
663+
var langPrefix = language.Split('-')[0]; // e.g., "zh"
664+
665+
// First, try to find by full name, and if not found, fallback to prefix
666+
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
659667
{
660-
return notoFont;
668+
// If the font is installed, return it
669+
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
670+
{
671+
return notoFont;
672+
}
661673
}
662674
}
663675

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: 29 additions & 12 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;
@@ -19,6 +20,7 @@
1920
using Flow.Launcher.Infrastructure.Storage;
2021
using Flow.Launcher.Infrastructure.UserSettings;
2122
using Flow.Launcher.Plugin;
23+
using Flow.Launcher.SettingPages.ViewModels;
2224
using Flow.Launcher.ViewModel;
2325
using Microsoft.Extensions.DependencyInjection;
2426
using Microsoft.Extensions.Hosting;
@@ -30,6 +32,7 @@ public partial class App : IDisposable, ISingleInstanceApp
3032
#region Public Properties
3133

3234
public static IPublicAPI API { get; private set; }
35+
public static bool Exiting => _mainWindow.CanClose;
3336

3437
#endregion
3538

@@ -38,7 +41,7 @@ public partial class App : IDisposable, ISingleInstanceApp
3841
private static readonly string ClassName = nameof(App);
3942

4043
private static bool _disposed;
41-
private MainWindow _mainWindow;
44+
private static MainWindow _mainWindow;
4245
private readonly MainViewModel _mainVM;
4346
private readonly Settings _settings;
4447

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

148164
Log.SetLogLevel(_settings.LogLevel);
149165

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

152172
API.LogInfo(ClassName, "Begin Flow Launcher startup ----------------------------------------------------");
153-
API.LogInfo(ClassName, "Runtime info:{ErrorReporting.RuntimeInfo()}");
173+
API.LogInfo(ClassName, $"Runtime info:{ErrorReporting.RuntimeInfo()}");
154174

155175
RegisterAppDomainExceptions();
156176
RegisterDispatcherUnhandledException();
@@ -170,19 +190,16 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
170190
await PluginManager.InitializePluginsAsync();
171191

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

176195
await imageLoadertask;
177196

178197
_mainWindow = new MainWindow();
179198

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

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

188205
QuickSwitch.InitializeQuickSwitch();
@@ -203,7 +220,7 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
203220
#pragma warning restore VSTHRD100 // Avoid async void methods
204221

205222
/// <summary>
206-
/// check startup only for Release
223+
/// Check startup only for Release
207224
/// </summary>
208225
[Conditional("RELEASE")]
209226
private void AutoStartup()
@@ -269,7 +286,7 @@ private void RegisterExitEvents()
269286
}
270287

271288
/// <summary>
272-
/// let exception throw as normal is better for Debug
289+
/// Let exception throw as normal is better for Debug
273290
/// </summary>
274291
[Conditional("RELEASE")]
275292
private void RegisterDispatcherUnhandledException()
@@ -278,7 +295,7 @@ private void RegisterDispatcherUnhandledException()
278295
}
279296

280297
/// <summary>
281-
/// let exception throw as normal is better for Debug
298+
/// Let exception throw as normal is better for Debug
282299
/// </summary>
283300
[Conditional("RELEASE")]
284301
private static void RegisterAppDomainExceptions()
@@ -287,7 +304,7 @@ private static void RegisterAppDomainExceptions()
287304
}
288305

289306
/// <summary>
290-
/// let exception throw as normal is better for Debug
307+
/// Let exception throw as normal is better for Debug
291308
/// </summary>
292309
[Conditional("RELEASE")]
293310
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)