diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs b/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs index e0a21725135..ed9c130e9e0 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs @@ -215,7 +215,7 @@ public Control CreateSettingPanel() TextWrapping = TextWrapping.WrapWithOverflow }; - desc.SetResourceReference(TextBlock.StyleProperty, "SettingPanelTextBlockDescriptionStyle"); // for theme change + desc.SetResourceReference(FrameworkElement.StyleProperty, "SettingPanelTextBlockDescriptionStyle"); // for theme change } // Add the name and description to the panel @@ -251,6 +251,8 @@ public Control CreateSettingPanel() ToolTip = attributes.Description }; + textBox.SetResourceReference(Control.FontFamilyProperty, "SettingWindowFont"); // for theme change + textBox.TextChanged += (_, _) => { Settings[attributes.Name] = textBox.Text; @@ -273,12 +275,14 @@ public Control CreateSettingPanel() ToolTip = attributes.Description }; + textBox.SetResourceReference(Control.FontFamilyProperty, "SettingWindowFont"); // for theme change + textBox.TextChanged += (_, _) => { Settings[attributes.Name] = textBox.Text; }; - var Btn = new Button() + var btn = new Button() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, @@ -286,7 +290,9 @@ public Control CreateSettingPanel() Content = API.GetTranslation("select") }; - Btn.Click += (_, _) => + btn.SetResourceReference(Control.FontFamilyProperty, "SettingWindowFont"); // for theme change + + btn.Click += (_, _) => { using System.Windows.Forms.CommonDialog dialog = type switch { @@ -320,7 +326,7 @@ public Control CreateSettingPanel() // Create a stack panel to wrap the button and text box stackPanel.Children.Add(textBox); - stackPanel.Children.Add(Btn); + stackPanel.Children.Add(btn); contentControl = stackPanel; @@ -340,6 +346,8 @@ public Control CreateSettingPanel() ToolTip = attributes.Description }; + textBox.SetResourceReference(Control.FontFamilyProperty, "SettingWindowFont"); // for theme change + textBox.TextChanged += (sender, _) => { Settings[attributes.Name] = ((TextBox)sender).Text; @@ -362,6 +370,8 @@ public Control CreateSettingPanel() ToolTip = attributes.Description, }; + passwordBox.SetResourceReference(Control.FontFamilyProperty, "SettingWindowFont"); // for theme change + passwordBox.PasswordChanged += (sender, _) => { Settings[attributes.Name] = ((PasswordBox)sender).Password; @@ -383,6 +393,8 @@ public Control CreateSettingPanel() ToolTip = attributes.Description }; + comboBox.SetResourceReference(Control.FontFamilyProperty, "SettingWindowFont"); // for theme change + comboBox.SelectionChanged += (sender, _) => { Settings[attributes.Name] = (string)((ComboBox)sender).SelectedItem; @@ -409,6 +421,8 @@ Settings[attributes.Name] is bool isChecked ToolTip = attributes.Description }; + checkBox.SetResourceReference(Control.FontFamilyProperty, "SettingWindowFont"); // for theme change + checkBox.Click += (sender, _) => { Settings[attributes.Name] = ((CheckBox)sender).IsChecked ?? defaultValue; @@ -451,7 +465,7 @@ Settings[attributes.Name] is bool isChecked { var sep = new Separator(); - sep.SetResourceReference(Separator.StyleProperty, "SettingPanelSeparatorStyle"); + sep.SetResourceReference(FrameworkElement.StyleProperty, "SettingPanelSeparatorStyle"); contentControl = sep; diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 0f878151e72..ca015fd70ca 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -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; @@ -113,6 +114,7 @@ public string SettingWindowFont { _settingWindowFont = value; OnPropertyChanged(); + Application.Current.Resources["SettingWindowFont"] = new FontFamily(value); } } } diff --git a/Flow.Launcher/ActionKeywords.xaml b/Flow.Launcher/ActionKeywords.xaml index 740b0d40254..87f803d9841 100644 --- a/Flow.Launcher/ActionKeywords.xaml +++ b/Flow.Launcher/ActionKeywords.xaml @@ -5,6 +5,7 @@ Title="{DynamicResource actionKeywordsTitle}" Width="450" Background="{DynamicResource PopuBGColor}" + FontFamily="{DynamicResource SettingWindowFont}" Foreground="{DynamicResource PopupTextColor}" Icon="Images\app.png" Loaded="ActionKeyword_OnLoaded" @@ -53,11 +54,11 @@ - - + + - + - + @@ -112,21 +113,23 @@ Grid.Row="1" Background="{DynamicResource PopupButtonAreaBGColor}" BorderBrush="{DynamicResource PopupButtonAreaBorderColor}" - BorderThickness="0,1,0,0"> + BorderThickness="0 1 0 0"> diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 87698a54571..84c900c538a 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -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; @@ -149,7 +150,7 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () => Ioc.Default.GetRequiredService().PreStartCleanUpAfterPortabilityUpdate(); API.LogInfo(ClassName, "Begin Flow Launcher startup ----------------------------------------------------"); - API.LogInfo(ClassName, "Runtime info:{ErrorReporting.RuntimeInfo()}"); + API.LogInfo(ClassName, $"Runtime info:{ErrorReporting.RuntimeInfo()}"); RegisterAppDomainExceptions(); RegisterDispatcherUnhandledException(); @@ -169,19 +170,18 @@ 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().InitializeLanguageAsync(); - await imageLoadertask; - _mainWindow = new MainWindow(); + // Update dynamic resources base on settings + Current.Resources["SettingWindowFont"] = new FontFamily(_settings.SettingWindowFont); - API.LogInfo(ClassName, "Dependencies Info:{ErrorReporting.DependenciesInfo()}"); + _mainWindow = new MainWindow(); 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().ChangeTheme(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); @@ -198,6 +198,10 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () => #pragma warning restore VSTHRD100 // Avoid async void methods + /// + /// check startup only for Release + /// + [Conditional("RELEASE")] private void AutoStartup() { // we try to enable auto-startup on first launch, or reenable if it was removed diff --git a/Flow.Launcher/CustomQueryHotkeySetting.xaml b/Flow.Launcher/CustomQueryHotkeySetting.xaml index d3c31c6da5c..647f015f098 100644 --- a/Flow.Launcher/CustomQueryHotkeySetting.xaml +++ b/Flow.Launcher/CustomQueryHotkeySetting.xaml @@ -8,7 +8,7 @@ Width="530" Background="{DynamicResource PopuBGColor}" DataContext="{Binding RelativeSource={RelativeSource Self}}" - FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}" + FontFamily="{DynamicResource SettingWindowFont}" Foreground="{DynamicResource PopupTextColor}" Icon="Images\app.png" MouseDown="window_MouseDown" @@ -120,7 +120,8 @@ Grid.Column="1" Margin="10" HorizontalAlignment="Stretch" - VerticalAlignment="Center" /> + VerticalAlignment="Center" + FontFamily="{DynamicResource SettingWindowFont}" /> diff --git a/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs b/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs index cc07caaa21e..77febde9d5b 100644 --- a/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs +++ b/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs @@ -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(); } @@ -30,13 +30,13 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e) { if (!update) { - Settings.CustomPluginHotkeys ??= new ObservableCollection(); + _settings.CustomPluginHotkeys ??= new ObservableCollection(); var pluginHotkey = new CustomPluginHotkey { Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text }; - Settings.CustomPluginHotkeys.Add(pluginHotkey); + _settings.CustomPluginHotkeys.Add(pluginHotkey); HotKeyMapper.SetCustomQueryHotkey(pluginHotkey); } @@ -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) { diff --git a/Flow.Launcher/CustomShortcutSetting.xaml b/Flow.Launcher/CustomShortcutSetting.xaml index cbdcecea6a9..0d68f64de08 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml +++ b/Flow.Launcher/CustomShortcutSetting.xaml @@ -7,7 +7,7 @@ Width="530" Background="{DynamicResource PopuBGColor}" DataContext="{Binding RelativeSource={RelativeSource Self}}" - FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}" + FontFamily="{DynamicResource SettingWindowFont}" Foreground="{DynamicResource PopupTextColor}" Icon="Images\app.png" ResizeMode="NoResize" @@ -109,6 +109,7 @@ Width="180" Margin="10" HorizontalAlignment="Left" + FontFamily="{DynamicResource SettingWindowFont}" Text="{Binding Key}" /> + DockPanel.Dock="Right" + FontFamily="{DynamicResource SettingWindowFont}" /> @@ -153,12 +156,14 @@ MinWidth="140" Margin="10 0 5 0" Click="BtnCancel_OnClick" - Content="{DynamicResource cancel}" /> + Content="{DynamicResource cancel}" + FontFamily="{DynamicResource SettingWindowFont}" /> diff --git a/Flow.Launcher/CustomShortcutSetting.xaml.cs b/Flow.Launcher/CustomShortcutSetting.xaml.cs index fcee0c96196..e180f657024 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml.cs +++ b/Flow.Launcher/CustomShortcutSetting.xaml.cs @@ -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(); - private readonly SettingsPaneHotkeyViewModel _hotkeyVm; public string Key { get; set; } = string.Empty; public string Value { get; set; } = string.Empty; diff --git a/Flow.Launcher/HotkeyControl.xaml b/Flow.Launcher/HotkeyControl.xaml index 02c625da558..632d354e7a1 100644 --- a/Flow.Launcher/HotkeyControl.xaml +++ b/Flow.Launcher/HotkeyControl.xaml @@ -7,15 +7,15 @@ mc:Ignorable="d">