diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 4169f3534..17fb698b4 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -416,21 +416,24 @@ namespace Flow.Launcher.Core.Resource /// public async Task RefreshFrameAsync() { - await Application.Current.Dispatcher.InvokeAsync(async () => + await Application.Current.Dispatcher.InvokeAsync(() => { + // Get the actual backdrop type and drop shadow effect settings + var (backdropType, useDropShadowEffect) = GetActualValue(); + // Remove OS minimizing/maximizing animation // Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, 3); - + // The timing of adding the shadow effect should vary depending on whether the theme is transparent. if (BlurEnabled) { - AutoDropShadow(); + AutoDropShadow(useDropShadowEffect); } - await SetBlurForWindowAsync(); + SetBlurForWindow(backdropType); if (!BlurEnabled) { - AutoDropShadow(); + AutoDropShadow(useDropShadowEffect); } }, DispatcherPriority.Normal); } @@ -440,61 +443,87 @@ namespace Flow.Launcher.Core.Resource /// public async Task SetBlurForWindowAsync() { - await Application.Current.Dispatcher.InvokeAsync(async () => + await Application.Current.Dispatcher.InvokeAsync(() => { - var dict = GetThemeResourceDictionary(_settings.Theme); - if (dict == null) - return; + // Get the actual backdrop type and drop shadow effect settings + var (backdropType, _) = GetActualValue(); - var windowBorderStyle = dict.Contains("WindowBorderStyle") ? dict["WindowBorderStyle"] as Style : null; - if (windowBorderStyle == null) - return; - - Window mainWindow = Application.Current.MainWindow; - if (mainWindow == null) - return; - - // Check if the theme supports blur - bool hasBlur = dict.Contains("ThemeBlurEnabled") && dict["ThemeBlurEnabled"] is bool b && b; - if (!hasBlur) - { - _settings.BackdropType = BackdropTypes.None; - } - - if (BlurEnabled && hasBlur && Win32Helper.IsBackdropSupported()) - { - // If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent - if (_settings.BackdropType == BackdropTypes.Mica || _settings.BackdropType == BackdropTypes.MicaAlt) - { - windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background")); - windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)))); - } - else if (_settings.BackdropType == BackdropTypes.Acrylic) - { - windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background")); - windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent))); - } - - // Apply the blur effect - Win32Helper.DWMSetBackdropForWindow(mainWindow, _settings.BackdropType); - ColorizeWindow(); - } - else - { - // Apply default style when Blur is disabled - Win32Helper.DWMSetBackdropForWindow(mainWindow, BackdropTypes.None); - ColorizeWindow(); - } - - UpdateResourceDictionary(dict); + SetBlurForWindow(backdropType); }, DispatcherPriority.Normal); } - private void AutoDropShadow() + /// + /// Gets the actual backdrop type and drop shadow effect settings based on the current theme status. + /// + public (BackdropTypes BackdropType, bool UseDropShadowEffect) GetActualValue() + { + var backdropType = _settings.BackdropType; + var useDropShadowEffect = _settings.UseDropShadowEffect; + + // When changed non-blur theme, change to backdrop to none + if (!BlurEnabled) + { + backdropType = BackdropTypes.None; + } + + // Dropshadow on and control disabled.(user can't change dropshadow with blur theme) + if (BlurEnabled) + { + useDropShadowEffect = true; + } + + return (backdropType, useDropShadowEffect); + } + + private void SetBlurForWindow(BackdropTypes backdropType) + { + var dict = GetThemeResourceDictionary(_settings.Theme); + if (dict == null) + return; + + var windowBorderStyle = dict.Contains("WindowBorderStyle") ? dict["WindowBorderStyle"] as Style : null; + if (windowBorderStyle == null) + return; + + Window mainWindow = Application.Current.MainWindow; + if (mainWindow == null) + return; + + // Check if the theme supports blur + bool hasBlur = dict.Contains("ThemeBlurEnabled") && dict["ThemeBlurEnabled"] is bool b && b; + if (BlurEnabled && hasBlur && Win32Helper.IsBackdropSupported()) + { + // If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent + if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt) + { + windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background")); + windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)))); + } + else if (backdropType == BackdropTypes.Acrylic) + { + windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background")); + windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent))); + } + + // Apply the blur effect + Win32Helper.DWMSetBackdropForWindow(mainWindow, backdropType); + ColorizeWindow(backdropType); + } + else + { + // Apply default style when Blur is disabled + Win32Helper.DWMSetBackdropForWindow(mainWindow, BackdropTypes.None); + ColorizeWindow(backdropType); + } + + UpdateResourceDictionary(dict); + } + + private void AutoDropShadow(bool useDropShadowEffect) { SetWindowCornerPreference("Default"); RemoveDropShadowEffectFromCurrentTheme(); - if (_settings.UseDropShadowEffect) + if (useDropShadowEffect) { if (BlurEnabled && Win32Helper.IsBackdropSupported()) { @@ -605,7 +634,7 @@ namespace Flow.Launcher.Core.Resource Application.Current.Resources["PreviewWindowBorderStyle"] = previewStyle; } - private void ColorizeWindow() + private void ColorizeWindow(BackdropTypes backdropType) { var dict = GetThemeResourceDictionary(_settings.Theme); if (dict == null) return; @@ -688,7 +717,7 @@ namespace Flow.Launcher.Core.Resource else { // Only set the background to transparent if the theme supports blur - if (_settings.BackdropType == BackdropTypes.Mica || _settings.BackdropType == BackdropTypes.MicaAlt) + if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt) { mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); } diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 8277e8e0b..63debfb47 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -76,7 +76,6 @@ namespace Flow.Launcher.Infrastructure.UserSettings } } public bool UseDropShadowEffect { get; set; } = true; - public BackdropTypes BackdropType{ get; set; } = BackdropTypes.None; /* Appearance Settings. It should be separated from the setting later.*/ diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 550b1bdae..7d094a0af 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -137,8 +137,7 @@ namespace Flow.Launcher await PluginManager.InitializePluginsAsync(); await imageLoadertask; - var mainVM = Ioc.Default.GetRequiredService(); - var window = new MainWindow(_settings, mainVM); + var window = new MainWindow(); Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index aa77d64f3..3bc9be83f 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -36,6 +36,7 @@ namespace Flow.Launcher #region Private Fields private readonly Settings _settings; + private readonly Theme _theme; private NotifyIcon _notifyIcon; private readonly ContextMenu contextMenu = new(); private readonly MainViewModel _viewModel; @@ -58,11 +59,12 @@ namespace Flow.Launcher #region Constructor - public MainWindow(Settings settings, MainViewModel mainVM) + public MainWindow() { - DataContext = mainVM; - _viewModel = mainVM; - _settings = settings; + _settings = Ioc.Default.GetRequiredService(); + _theme = Ioc.Default.GetRequiredService(); + _viewModel = Ioc.Default.GetRequiredService(); + DataContext = _viewModel; InitializeComponent(); UpdatePosition(true); @@ -390,7 +392,8 @@ namespace Flow.Launcher if (_initialHeight != (int)Height) { var shadowMargin = 0; - if (_settings.UseDropShadowEffect) + var (_, useDropShadowEffect) = _theme.GetActualValue(); + if (useDropShadowEffect) { shadowMargin = 32; } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 1036d321c..f8c0fa642 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -35,18 +35,6 @@ public partial class SettingsPaneThemeViewModel : BaseModel _selectedTheme = value; ThemeManager.Instance.ChangeTheme(value.FileNameWithoutExtension); - // when changed non-blur theme, change to backdrop to none - if (!ThemeManager.Instance.BlurEnabled) - { - Settings.BackdropType = BackdropTypes.None; - } - - // dropshadow on and control disabled.(user can't change dropshadow with blur theme) - if (ThemeManager.Instance.BlurEnabled) - { - Settings.UseDropShadowEffect = true; - } - // Update UI state OnPropertyChanged(nameof(BackdropType)); OnPropertyChanged(nameof(IsBackdropEnabled)); @@ -235,8 +223,8 @@ public partial class SettingsPaneThemeViewModel : BaseModel public BackdropTypes BackdropType { get => Enum.IsDefined(typeof(BackdropTypes), Settings.BackdropType) - ? Settings.BackdropType - : BackdropTypes.None; + ? Settings.BackdropType + : BackdropTypes.None; set { if (!Enum.IsDefined(typeof(BackdropTypes), value)) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index 913c313de..b467aefee 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -2,7 +2,6 @@ using System.Linq; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Core.Resource; -using FLSettings = Flow.Launcher.Infrastructure.UserSettings.Settings; namespace Flow.Launcher.Plugin.Sys { @@ -10,7 +9,6 @@ namespace Flow.Launcher.Plugin.Sys { public const string Keyword = "fltheme"; - private readonly FLSettings _settings; private readonly Theme _theme; private readonly PluginInitContext _context; @@ -27,18 +25,6 @@ namespace Flow.Launcher.Plugin.Sys _selectedTheme = value; _theme.ChangeTheme(value.FileNameWithoutExtension); - // when changed non-blur theme, change to backdrop to none - if (!_theme.BlurEnabled) - { - _settings.BackdropType = 0; // Change to 0 instead of BackdropTypes.None - } - - // dropshadow on and control disabled.(user can't change dropshadow with blur theme) - if (_theme.BlurEnabled) - { - _settings.UseDropShadowEffect = true; - } - _ = _theme.RefreshFrameAsync(); } } @@ -51,7 +37,6 @@ namespace Flow.Launcher.Plugin.Sys { _context = context; _theme = Ioc.Default.GetRequiredService(); - _settings = Ioc.Default.GetRequiredService(); } public List Query(Query query)