Skip to content

Fix: Fixed a crash that would occur when closing the main window #16140

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 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ async Task ActivateAsync()
}

await AppLifecycleHelper.InitializeAppComponentsAsync();

AppLifecycleHelper.IsLaunchInitialized = true;
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/Files.App/Data/Items/WindowEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public unsafe WindowEx(int minWidth = 400, int minHeight = 300)
_oldWndProc = Marshal.GetDelegateForFunctionPointer<WNDPROC>(pOldWndProc);

Closed += WindowEx_Closed;
Activated += WindowEx_Activated; ;
}

private unsafe void StoreWindowPlacementData()
Expand Down Expand Up @@ -298,16 +297,9 @@ private void WindowEx_Closed(object sender, WindowEventArgs args)
StoreWindowPlacementData();
}

private void WindowEx_Activated(object sender, WindowActivatedEventArgs args)
{
if (AppLifecycleHelper.IsLaunchInitialized && SystemBackdrop is AppSystemBackdrop appSystemBackdrop)
appSystemBackdrop.SystemBackdropConfiguration.IsInputActive = args.WindowActivationState is not WindowActivationState.Deactivated;
}

public void Dispose()
{
Closed -= WindowEx_Closed;
Activated -= WindowEx_Activated;
}
}
}
7 changes: 0 additions & 7 deletions src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using CommunityToolkit.WinUI.Helpers;
using Files.App.Helpers.Application;
using Files.App.Services.SizeProvider;
using Files.App.Storage.Storables;
using Files.App.Utils.Logger;
using Files.App.ViewModels.Settings;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -58,12 +57,6 @@ public static class AppLifecycleHelper
_ => Constants.AssetPaths.StableLogo
});

/// <summary>
/// Gets or sets a value that indicates whether the application is ready to be interacted with.
/// This is primarily used for DI container initialization check.
/// </summary>
public static bool IsLaunchInitialized { get; set; }

/// <summary>
/// Initializes the app components.
/// </summary>
Expand Down
22 changes: 10 additions & 12 deletions src/Files.App/Helpers/UI/AppSystemBackdrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ internal sealed class AppSystemBackdrop : SystemBackdrop
private XamlRoot root;
private SystemBackdropTheme? prevTheme = null;

public SystemBackdropConfiguration SystemBackdropConfiguration { get; set; }

public AppSystemBackdrop(bool isSecondaryWindow = false)
{
this.isSecondaryWindow = isSecondaryWindow;
Expand All @@ -34,21 +32,21 @@ protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop con
base.OnTargetConnected(connectedTarget, xamlRoot);
this.target = connectedTarget;
this.root = xamlRoot;
SystemBackdropConfiguration = GetDefaultSystemBackdropConfiguration(connectedTarget, xamlRoot);
controller = GetSystemBackdropController(userSettingsService.AppearanceSettingsService.AppThemeBackdropMaterial, SystemBackdropConfiguration.Theme);
controller?.SetSystemBackdropConfiguration(SystemBackdropConfiguration);
var configuration = GetDefaultSystemBackdropConfiguration(connectedTarget, xamlRoot);
controller = GetSystemBackdropController(userSettingsService.AppearanceSettingsService.AppThemeBackdropMaterial, configuration.Theme);
controller?.SetSystemBackdropConfiguration(configuration);
controller?.AddSystemBackdropTarget(connectedTarget);
}

protected override void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
{
base.OnDefaultSystemBackdropConfigurationChanged(target, xamlRoot);
SystemBackdropConfiguration = GetDefaultSystemBackdropConfiguration(target, xamlRoot);
if (controller is not DesktopAcrylicController acrylicController || acrylicController.Kind != DesktopAcrylicKind.Thin || SystemBackdropConfiguration.Theme == prevTheme)
var configuration = GetDefaultSystemBackdropConfiguration(target, xamlRoot);
if (controller is not DesktopAcrylicController acrylicController || acrylicController.Kind != DesktopAcrylicKind.Thin || configuration.Theme == prevTheme)
return;

prevTheme = SystemBackdropConfiguration.Theme;
SetThinAcrylicBackdropProperties(acrylicController, SystemBackdropConfiguration.Theme);
prevTheme = configuration.Theme;
SetThinAcrylicBackdropProperties(acrylicController, configuration.Theme);
}

protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget)
Expand Down Expand Up @@ -81,9 +79,9 @@ private void OnSettingChanged(object? sender, SettingChangedEventArgs e)
case nameof(IAppearanceSettingsService.AppThemeBackdropMaterial):
controller?.RemoveAllSystemBackdropTargets();
controller?.Dispose();
SystemBackdropConfiguration = GetDefaultSystemBackdropConfiguration(target, root);
var newController = GetSystemBackdropController((BackdropMaterialType)e.NewValue!, SystemBackdropConfiguration.Theme);
newController?.SetSystemBackdropConfiguration(SystemBackdropConfiguration);
var configuration = GetDefaultSystemBackdropConfiguration(target, root);
var newController = GetSystemBackdropController((BackdropMaterialType)e.NewValue!, configuration.Theme);
newController?.SetSystemBackdropConfiguration(configuration);
newController?.AddSystemBackdropTarget(target);
controller = newController;
break;
Expand Down