mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Refactor UI thread checks in Theme async methods
Refactored RefreshFrameAsync and SetBlurForWindowAsync to check Dispatcher access before invoking UI updates, ensuring thread safety and reducing unnecessary Dispatcher calls. Also removed redundant code and unused using directive.
This commit is contained in:
parent
5635783973
commit
966bcdd5ec
1 changed files with 27 additions and 22 deletions
|
|
@ -11,7 +11,6 @@ using System.Windows.Markup;
|
|||
using System.Windows.Media;
|
||||
using System.Windows.Media.Effects;
|
||||
using System.Windows.Shell;
|
||||
using System.Windows.Threading;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
|
@ -638,26 +637,29 @@ namespace Flow.Launcher.Core.Resource
|
|||
/// </summary>
|
||||
public async Task RefreshFrameAsync()
|
||||
{
|
||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
if (Application.Current?.Dispatcher.CheckAccess() != true)
|
||||
{
|
||||
// Get the actual backdrop type and drop shadow effect settings
|
||||
var (backdropType, useDropShadowEffect) = GetActualValue();
|
||||
await Application.Current?.Dispatcher.InvokeAsync(RefreshFrameAsync);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove OS minimizing/maximizing animation
|
||||
// Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, 3);
|
||||
// Get the actual backdrop type and drop shadow effect settings
|
||||
var (backdropType, useDropShadowEffect) = GetActualValue();
|
||||
|
||||
// The timing of adding the shadow effect should vary depending on whether the theme is transparent.
|
||||
if (BlurEnabled)
|
||||
{
|
||||
AutoDropShadow(useDropShadowEffect);
|
||||
}
|
||||
SetBlurForWindow(_settings.Theme, backdropType);
|
||||
// Remove OS minimizing/maximizing animation
|
||||
// Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, 3);
|
||||
|
||||
if (!BlurEnabled)
|
||||
{
|
||||
AutoDropShadow(useDropShadowEffect);
|
||||
}
|
||||
}, DispatcherPriority.Render);
|
||||
// The timing of adding the shadow effect should vary depending on whether the theme is transparent.
|
||||
if (BlurEnabled)
|
||||
{
|
||||
AutoDropShadow(useDropShadowEffect);
|
||||
}
|
||||
SetBlurForWindow(_settings.Theme, backdropType);
|
||||
|
||||
if (!BlurEnabled)
|
||||
{
|
||||
AutoDropShadow(useDropShadowEffect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -665,13 +667,16 @@ namespace Flow.Launcher.Core.Resource
|
|||
/// </summary>
|
||||
public async Task SetBlurForWindowAsync()
|
||||
{
|
||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
if (Application.Current?.Dispatcher.CheckAccess() != true)
|
||||
{
|
||||
// Get the actual backdrop type and drop shadow effect settings
|
||||
var (backdropType, _) = GetActualValue();
|
||||
await Application.Current?.Dispatcher.InvokeAsync(RefreshFrameAsync);
|
||||
return;
|
||||
}
|
||||
|
||||
SetBlurForWindow(_settings.Theme, backdropType);
|
||||
}, DispatcherPriority.Render);
|
||||
// Get the actual backdrop type and drop shadow effect settings
|
||||
var (backdropType, _) = GetActualValue();
|
||||
|
||||
SetBlurForWindow(_settings.Theme, backdropType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue