Skip to content

Commit

Permalink
Fix: Fixed issue where the app would crash when opening the propertie…
Browse files Browse the repository at this point in the history
…s window twice (files-community#14386)
  • Loading branch information
hishitetsu committed Jan 8, 2024
1 parent 35cc6ad commit a1d0bc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Files.App/Helpers/UI/DragZoneHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public static void RaiseSetTitleBarDragRegion(this Window window, SetTitleBarDra
// UIElement.RasterizationScale is always 1
var source = InputNonClientPointerSource.GetForWindowId(window.AppWindow.Id);
var uiElement = window.Content;
var scaleFactor = uiElement.XamlRoot.RasterizationScale;
var xamlRoot = uiElement?.XamlRoot;

if (xamlRoot is null)
return;

var scaleFactor = xamlRoot.RasterizationScale;
var size = window.AppWindow.Size;
// If the number of regions is 0 or 1, AppWindow will automatically reset to the default region next time, but if it is >=2, it will not and need to be manually cleared
source.ClearRegionRects(NonClientRegionKind.Passthrough);
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e)

UpdatePageLayout();
Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
Window.AppWindow.Changed += (_, _) => Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
Window.AppWindow.Changed += AppWindow_Changed;
}

private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
Expand Down Expand Up @@ -116,6 +116,7 @@ private void Window_Closed(object sender, WindowEventArgs args)
{
AppSettings.ThemeModeChanged -= AppSettings_ThemeModeChanged;
Window.Closed -= Window_Closed;
Window.AppWindow.Changed -= AppWindow_Changed;

if (MainPropertiesViewModel.ChangedPropertiesCancellationTokenSource is not null &&
!MainPropertiesViewModel.ChangedPropertiesCancellationTokenSource.IsCancellationRequested)
Expand All @@ -124,6 +125,11 @@ private void Window_Closed(object sender, WindowEventArgs args)
}
}

private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs e)
{
Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
}

public override async Task<bool> SaveChangesAsync()
=> await Task.FromResult(false);

Expand Down

0 comments on commit a1d0bc7

Please sign in to comment.