From 46e11d05ae3ea49dc584a1ad9f21e5f002b0202a Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Fri, 24 Nov 2023 18:41:03 +0900 Subject: [PATCH 1/3] Fixed COMException --- src/Files.App/Data/Models/AppModel.cs | 18 ++++++++++++++++++ .../Storage/Helpers/FilePropertiesHelpers.cs | 7 ++++--- src/Files.App/Views/MainPage.xaml.cs | 3 ++- .../Views/Properties/DetailsPage.xaml.cs | 3 +++ .../Views/Properties/GeneralPage.xaml.cs | 3 +++ src/Files.App/Views/Shells/BaseShellPage.cs | 3 +++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Files.App/Data/Models/AppModel.cs b/src/Files.App/Data/Models/AppModel.cs index 0381a20e2d25..6b956681ebc8 100644 --- a/src/Files.App/Data/Models/AppModel.cs +++ b/src/Files.App/Data/Models/AppModel.cs @@ -65,6 +65,24 @@ 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; From e789dc6260992599bf04f4d664aded7303535f38 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:48:19 -0500 Subject: [PATCH 2/3] Update src/Files.App/Data/Models/AppModel.cs --- src/Files.App/Data/Models/AppModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App/Data/Models/AppModel.cs b/src/Files.App/Data/Models/AppModel.cs index 6b956681ebc8..95e8bc76cebd 100644 --- a/src/Files.App/Data/Models/AppModel.cs +++ b/src/Files.App/Data/Models/AppModel.cs @@ -70,6 +70,7 @@ public int PropertiesWindowCount { get => propertiesWindowCount; } + public int IncrementPropertiesWindowCount() { var result = Interlocked.Increment(ref propertiesWindowCount); From e01c3be3e070b79db5b172ab01f5d5a7e66d258a Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:48:24 -0500 Subject: [PATCH 3/3] Update src/Files.App/Data/Models/AppModel.cs --- src/Files.App/Data/Models/AppModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App/Data/Models/AppModel.cs b/src/Files.App/Data/Models/AppModel.cs index 95e8bc76cebd..7a9e7448a9f8 100644 --- a/src/Files.App/Data/Models/AppModel.cs +++ b/src/Files.App/Data/Models/AppModel.cs @@ -77,6 +77,7 @@ public int IncrementPropertiesWindowCount() OnPropertyChanged(nameof(PropertiesWindowCount)); return result; } + public int DecrementPropertiesWindowCount() { var result = Interlocked.Decrement(ref propertiesWindowCount);