diff --git a/src/Files.App/Data/Models/AppModel.cs b/src/Files.App/Data/Models/AppModel.cs index 0381a20e2d25..7a9e7448a9f8 100644 --- a/src/Files.App/Data/Models/AppModel.cs +++ b/src/Files.App/Data/Models/AppModel.cs @@ -65,6 +65,26 @@ public bool IsMainWindowClosed set => SetProperty(ref isMainWindowClosed, value); } + private int propertiesWindowCount = 0; + public int PropertiesWindowCount + { + get => propertiesWindowCount; + } + + public int IncrementPropertiesWindowCount() + { + var result = Interlocked.Increment(ref propertiesWindowCount); + OnPropertyChanged(nameof(PropertiesWindowCount)); + return result; + } + + public int DecrementPropertiesWindowCount() + { + var result = Interlocked.Decrement(ref propertiesWindowCount); + OnPropertyChanged(nameof(PropertiesWindowCount)); + return result; + } + private bool forceProcessTermination = false; public bool ForceProcessTermination { diff --git a/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs b/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs index 4dd08cedc709..2dc48a613596 100644 --- a/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs +++ b/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs @@ -31,7 +31,6 @@ public static class FilePropertiesHelpers public static nint GetWindowHandle(Window w) => WinRT.Interop.WindowNative.GetWindowHandle(w); - private static int WindowCount = 0; private static TaskCompletionSource? PropertiesWindowsClosingTCS; private static BlockingCollection WindowCache = new(); @@ -145,7 +144,7 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan + Math.Max(0, Math.Min(displayArea.WorkArea.Height - appWindow.Size.Height, pointerPosition.Y - displayArea.WorkArea.Y)), }; - if (Interlocked.Increment(ref WindowCount) == 1) + if (App.AppModel.IncrementPropertiesWindowCount() == 1) PropertiesWindowsClosingTCS = new(); appWindow.Move(appWindowPos); @@ -164,12 +163,14 @@ private static void PropertiesWindow_Closed(object sender, WindowEventArgs args) window.Content = null; WindowCache.Add(window); - if (Interlocked.Decrement(ref WindowCount) == 0) + if (App.AppModel.DecrementPropertiesWindowCount() == 0) { PropertiesWindowsClosingTCS!.TrySetResult(); PropertiesWindowsClosingTCS = null; } } + else + App.AppModel.DecrementPropertiesWindowCount(); } /// diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 709314471dcf..96b86ea3f4e2 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -329,7 +329,8 @@ private void PreviewPane_Unloaded(object sender, RoutedEventArgs e) private void UpdateDateDisplayTimer_Tick(object sender, object e) { - PreviewPane?.ViewModel.UpdateDateDisplay(); + if (!App.AppModel.IsMainWindowClosed) + PreviewPane?.ViewModel.UpdateDateDisplay(); } private void Page_SizeChanged(object sender, SizeChangedEventArgs e) diff --git a/src/Files.App/Views/Properties/DetailsPage.xaml.cs b/src/Files.App/Views/Properties/DetailsPage.xaml.cs index 638bda3034b6..b016aa17b02d 100644 --- a/src/Files.App/Views/Properties/DetailsPage.xaml.cs +++ b/src/Files.App/Views/Properties/DetailsPage.xaml.cs @@ -79,6 +79,9 @@ private async void ClearPropertiesConfirmation_Click(object sender, RoutedEventA private void UpdateDateDisplayTimer_Tick(object sender, object e) { + if (App.AppModel.PropertiesWindowCount == 0) + return; + ViewModel.PropertySections.ForEach(section => section.ForEach(property => { if (property.Value is DateTimeOffset) diff --git a/src/Files.App/Views/Properties/GeneralPage.xaml.cs b/src/Files.App/Views/Properties/GeneralPage.xaml.cs index ad3a099d512e..b39e9ec8969f 100644 --- a/src/Files.App/Views/Properties/GeneralPage.xaml.cs +++ b/src/Files.App/Views/Properties/GeneralPage.xaml.cs @@ -47,6 +47,9 @@ private void ItemFileName_LosingFocus(UIElement _, LosingFocusEventArgs e) private void UpdateDateDisplayTimer_Tick(object sender, object e) { + if (App.AppModel.PropertiesWindowCount == 0) + return; + // Reassign values to update date display ViewModel.ItemCreatedTimestampReal = ViewModel.ItemCreatedTimestampReal; ViewModel.ItemModifiedTimestampReal = ViewModel.ItemModifiedTimestampReal; diff --git a/src/Files.App/Views/Shells/BaseShellPage.cs b/src/Files.App/Views/Shells/BaseShellPage.cs index d06c5073bc75..9995d73f0f75 100644 --- a/src/Files.App/Views/Shells/BaseShellPage.cs +++ b/src/Files.App/Views/Shells/BaseShellPage.cs @@ -771,6 +771,9 @@ private void HandleBackForwardRequest(PageStackEntry pageContent) private void UpdateDateDisplayTimer_Tick(object sender, object e) { + if (App.AppModel.IsMainWindowClosed) + return; + if (userSettingsService.GeneralSettingsService.DateTimeFormat != _lastDateTimeFormats) { _lastDateTimeFormats = userSettingsService.GeneralSettingsService.DateTimeFormat;