Add null checks and fix dispatcher invocation in Theme

Added early returns if Application.Current is null in RefreshFrameAsync and SetBlurForWindowAsync to prevent null reference exceptions. Updated dispatcher access checks and ensured the correct method is invoked asynchronously for each case, improving robustness and reliability.
This commit is contained in:
Jack251970 2026-02-28 23:22:06 +08:00
parent a83da2b00f
commit 84ed1fa1e1

View file

@ -644,7 +644,8 @@ namespace Flow.Launcher.Core.Resource
/// </summary>
public async Task RefreshFrameAsync()
{
if (Application.Current?.Dispatcher.CheckAccess() != true)
if (Application.Current == null) return;
if (!Application.Current.Dispatcher.CheckAccess())
{
await Application.Current?.Dispatcher.InvokeAsync(RefreshFrameAsync);
return;
@ -676,9 +677,10 @@ namespace Flow.Launcher.Core.Resource
/// </summary>
public async Task SetBlurForWindowAsync()
{
if (Application.Current?.Dispatcher.CheckAccess() != true)
if (Application.Current == null) return;
if (!Application.Current.Dispatcher.CheckAccess())
{
await Application.Current?.Dispatcher.InvokeAsync(RefreshFrameAsync);
await Application.Current?.Dispatcher.InvokeAsync(SetBlurForWindowAsync);
return;
}