Skip to content

Improve Setting Window Font & Format xaml styles & Fix log message & Improve code quality #3487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f50f2ff
Implement dynamic font settings for the setting window
onesounds Apr 24, 2025
25f39f6
Add dynamic font support for the setting window
onesounds Apr 24, 2025
8432fa3
Add SettingWindowFont definition to CustomControlTemplate
onesounds Apr 24, 2025
02252c2
Add SettingWindowFont to CustomControlTemplate for improved font styling
onesounds Apr 24, 2025
2d1e9ec
Add ContentControlThemeFontFamily to support dynamic font styling
onesounds Apr 24, 2025
82f23e5
Update ContentControlThemeFontFamily when setting changes
Jack251970 Apr 24, 2025
d867875
Format xaml styles
Jack251970 Apr 24, 2025
d01c67f
Improve code quality
Jack251970 Apr 24, 2025
94ff72c
Check startup only for Release
Jack251970 Apr 24, 2025
4df9c04
Update dynamic resource earilier
Jack251970 Apr 24, 2025
71ab7a6
Fix log message & Improve code comments
Jack251970 Apr 24, 2025
8912789
Use http client for code quality
Jack251970 Apr 24, 2025
8463304
Fix clock panel font issue & Improve preview performance & Improve co…
Jack251970 Apr 24, 2025
82d97fd
Improve code quality
Jack251970 Apr 24, 2025
686d106
Add todo
Jack251970 Apr 24, 2025
192e2ef
Remove property change
Jack251970 Apr 24, 2025
22fb5b1
Remove unused binding
Jack251970 Apr 24, 2025
cbcebad
Improve code quality
Jack251970 Apr 24, 2025
84b0393
Use dependency injection for setting page view models
Jack251970 Apr 24, 2025
7945292
Update context menu font when setting is changed
Jack251970 Apr 24, 2025
5665758
Add property change back
Jack251970 Apr 24, 2025
197e9c4
Improve code comments
Jack251970 Apr 25, 2025
e3573f3
Improve code quality
Jack251970 Apr 25, 2025
856346a
Always update main window position when window is loaded
Jack251970 Apr 25, 2025
defb283
Change setting window position & window state faster & Do not save se…
Jack251970 Apr 25, 2025
f0512d7
Add blank line
Jack251970 Apr 25, 2025
755ddb4
Fix typo
Jack251970 Apr 25, 2025
c35eca2
Fix logon task issue message box & Improve startup path check
Jack251970 Apr 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
// If can parse the default value to bool, use it, otherwise use false
: value is string stringValue && bool.TryParse(stringValue, out var boolValueFromString)
&& boolValueFromString;
checkBox.Dispatcher.Invoke(() =>checkBox.IsChecked = isChecked);
checkBox.Dispatcher.Invoke(() => checkBox.IsChecked = isChecked);
break;
}
}
Expand Down Expand Up @@ -154,8 +154,7 @@ public bool NeedCreateSettingPanel()

public Control CreateSettingPanel()
{
// No need to check if NeedCreateSettingPanel is true because CreateSettingPanel will only be called if it's true
// if (!NeedCreateSettingPanel()) return null;
if (!NeedCreateSettingPanel()) return null!;

// Create main grid with two columns (Column 1: Auto, Column 2: *)
var mainPanel = new Grid { Margin = SettingPanelMargin, VerticalAlignment = VerticalAlignment.Center };
Expand Down
3 changes: 3 additions & 0 deletions Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
using System.Windows;
using System.Windows.Media;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.Logger;
Expand Down Expand Up @@ -113,6 +114,8 @@ public string SettingWindowFont
{
_settingWindowFont = value;
OnPropertyChanged();
Application.Current.Resources["SettingWindowFont"] = new FontFamily(value);
Application.Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(value);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions Flow.Launcher/ActionKeywords.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
</Button>
</Grid>
</StackPanel>
<StackPanel Margin="26,12,26,0">
<StackPanel Grid.Row="0" Margin="0,0,0,12">
<StackPanel Margin="26 12 26 0">
<StackPanel Grid.Row="0" Margin="0 0 0 12">
<TextBlock
Grid.Column="0"
Margin="0,0,0,0"
Margin="0 0 0 0"
FontSize="20"
FontWeight="SemiBold"
Text="{DynamicResource actionKeywordsTitle}"
Expand All @@ -71,7 +71,7 @@
TextWrapping="WrapWithOverflow" />
</StackPanel>

<StackPanel Margin="0,18,0,0" Orientation="Horizontal">
<StackPanel Margin="0 18 0 0" Orientation="Horizontal">
<TextBlock
Grid.Row="0"
Grid.Column="1"
Expand All @@ -83,14 +83,14 @@
x:Name="tbOldActionKeyword"
Grid.Row="0"
Grid.Column="1"
Margin="14,10,10,10"
Margin="14 10 10 10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
FontWeight="SemiBold"
Foreground="{DynamicResource Color05B}" />
</StackPanel>
<StackPanel Margin="0,0,0,10" Orientation="Horizontal">
<StackPanel Margin="0 0 0 10" Orientation="Horizontal">
<TextBlock
Grid.Row="1"
Grid.Column="1"
Expand All @@ -101,7 +101,7 @@
<TextBox
x:Name="tbAction"
Width="105"
Margin="10,10,15,10"
Margin="10 10 15 10"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
</StackPanel>
Expand All @@ -112,20 +112,20 @@
Grid.Row="1"
Background="{DynamicResource PopupButtonAreaBGColor}"
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
BorderThickness="0,1,0,0">
BorderThickness="0 1 0 0">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button
x:Name="btnCancel"
Width="145"
Height="30"
Margin="10,0,5,0"
Margin="10 0 5 0"
Click="BtnCancel_OnClick"
Content="{DynamicResource cancel}" />
<Button
x:Name="btnDone"
Width="145"
Height="30"
Margin="5,0,10,0"
Margin="5 0 10 0"
Click="btnDone_OnClick"
Style="{StaticResource AccentButtonStyle}">
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
Expand Down
43 changes: 32 additions & 11 deletions Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core;
using Flow.Launcher.Core.Configuration;
Expand All @@ -18,6 +19,7 @@
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -29,6 +31,7 @@ public partial class App : IDisposable, ISingleInstanceApp
#region Public Properties

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

#endregion

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

private static bool _disposed;
private MainWindow _mainWindow;
private static MainWindow _mainWindow;
private readonly MainViewModel _mainVM;
private readonly Settings _settings;

Expand Down Expand Up @@ -73,14 +76,27 @@ public App()
.AddSingleton(_ => _settings)
.AddSingleton(sp => new Updater(sp.GetRequiredService<IPublicAPI>(), Launcher.Properties.Settings.Default.GithubRepo))
.AddSingleton<Portable>()
.AddSingleton<SettingWindowViewModel>()
.AddSingleton<IAlphabet, PinyinAlphabet>()
.AddSingleton<StringMatcher>()
.AddSingleton<Internationalization>()
.AddSingleton<IPublicAPI, PublicAPIInstance>()
.AddSingleton<MainViewModel>()
.AddSingleton<Theme>()
// Use one instance for main window view model because we only have one main window
.AddSingleton<MainViewModel>()
// Use one instance for welcome window view model & setting window view model because
// pages in welcome window & setting window need to share the same instance and
// these two view models do not need to be reset when creating new windows
.AddSingleton<WelcomeViewModel>()
.AddSingleton<SettingWindowViewModel>()
// Use transient instance for setting window page view models because
// pages in setting window need to be recreated when setting window is closed
.AddTransient<SettingsPaneAboutViewModel>()
.AddTransient<SettingsPaneGeneralViewModel>()
.AddTransient<SettingsPaneHotkeyViewModel>()
.AddTransient<SettingsPanePluginsViewModel>()
.AddTransient<SettingsPanePluginStoreViewModel>()
.AddTransient<SettingsPaneProxyViewModel>()
.AddTransient<SettingsPaneThemeViewModel>()
).Build();
Ioc.Default.ConfigureServices(host.Services);
}
Expand Down Expand Up @@ -146,10 +162,14 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>

Log.SetLogLevel(_settings.LogLevel);

// Update dynamic resources base on settings
Current.Resources["SettingWindowFont"] = new FontFamily(_settings.SettingWindowFont);
Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(_settings.SettingWindowFont);

Comment on lines +165 to +168
Copy link
Preview

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamic resource updates for font families are performed both here and in the Settings property setter. Consider consolidating this logic to a single location to avoid redundant or conflicting updates.

Suggested change
// Update dynamic resources base on settings
Current.Resources["SettingWindowFont"] = new FontFamily(_settings.SettingWindowFont);
Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(_settings.SettingWindowFont);
// Update dynamic resources based on settings
UpdateFontFamilyResources();

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do so

Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();

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

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

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

await imageLoadertask;

_mainWindow = new MainWindow();

API.LogInfo(ClassName, "Dependencies Info:{ErrorReporting.DependenciesInfo()}");

Current.MainWindow = _mainWindow;
Current.MainWindow.Title = Constant.FlowLauncher;

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

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

#pragma warning restore VSTHRD100 // Avoid async void methods

/// <summary>
/// Check startup only for Release
/// </summary>
[Conditional("RELEASE")]
private void AutoStartup()
{
// we try to enable auto-startup on first launch, or reenable if it was removed
Expand Down Expand Up @@ -261,7 +282,7 @@ private void RegisterExitEvents()
}

/// <summary>
/// let exception throw as normal is better for Debug
/// Let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private void RegisterDispatcherUnhandledException()
Expand All @@ -270,7 +291,7 @@ private void RegisterDispatcherUnhandledException()
}

/// <summary>
/// let exception throw as normal is better for Debug
/// Let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private static void RegisterAppDomainExceptions()
Expand All @@ -279,7 +300,7 @@ private static void RegisterAppDomainExceptions()
}

/// <summary>
/// let exception throw as normal is better for Debug
/// Let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private static void RegisterTaskSchedulerUnhandledException()
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/CustomQueryHotkeySetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Width="530"
Background="{DynamicResource PopuBGColor}"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
Foreground="{DynamicResource PopupTextColor}"
Icon="Images\app.png"
MouseDown="window_MouseDown"
Expand Down
10 changes: 5 additions & 5 deletions Flow.Launcher/CustomQueryHotkeySetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ namespace Flow.Launcher
{
public partial class CustomQueryHotkeySetting : Window
{
public Settings Settings { get; }
private readonly Settings _settings;

private bool update;
private CustomPluginHotkey updateCustomHotkey;

public CustomQueryHotkeySetting(Settings settings)
{
Settings = settings;
_settings = settings;
InitializeComponent();
}

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

var pluginHotkey = new CustomPluginHotkey
{
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
};
Settings.CustomPluginHotkeys.Add(pluginHotkey);
_settings.CustomPluginHotkeys.Add(pluginHotkey);

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

public void UpdateItem(CustomPluginHotkey item)
{
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
{
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/CustomShortcutSetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Width="530"
Background="{DynamicResource PopuBGColor}"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
Foreground="{DynamicResource PopupTextColor}"
Icon="Images\app.png"
ResizeMode="NoResize"
Expand Down
4 changes: 0 additions & 4 deletions Flow.Launcher/CustomShortcutSetting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System.Windows;
using System.Windows.Input;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.SettingPages.ViewModels;

namespace Flow.Launcher
{
public partial class CustomShortcutSetting : Window
{
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();

private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
public string Key { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
Expand Down
Loading
Loading