Skip to content

Commit c57a1da

Browse files
authored
Fix: Fixed COMException in UpdateDateDisplayTimer_Tick (#14051)
1 parent a106c1a commit c57a1da

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

src/Files.App/Data/Models/AppModel.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ public bool IsMainWindowClosed
6565
set => SetProperty(ref isMainWindowClosed, value);
6666
}
6767

68+
private int propertiesWindowCount = 0;
69+
public int PropertiesWindowCount
70+
{
71+
get => propertiesWindowCount;
72+
}
73+
74+
public int IncrementPropertiesWindowCount()
75+
{
76+
var result = Interlocked.Increment(ref propertiesWindowCount);
77+
OnPropertyChanged(nameof(PropertiesWindowCount));
78+
return result;
79+
}
80+
81+
public int DecrementPropertiesWindowCount()
82+
{
83+
var result = Interlocked.Decrement(ref propertiesWindowCount);
84+
OnPropertyChanged(nameof(PropertiesWindowCount));
85+
return result;
86+
}
87+
6888
private bool forceProcessTermination = false;
6989
public bool ForceProcessTermination
7090
{

src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static class FilePropertiesHelpers
3131
public static nint GetWindowHandle(Window w)
3232
=> WinRT.Interop.WindowNative.GetWindowHandle(w);
3333

34-
private static int WindowCount = 0;
3534
private static TaskCompletionSource? PropertiesWindowsClosingTCS;
3635
private static BlockingCollection<WinUIEx.WindowEx> WindowCache = new();
3736

@@ -145,7 +144,7 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
145144
+ Math.Max(0, Math.Min(displayArea.WorkArea.Height - appWindow.Size.Height, pointerPosition.Y - displayArea.WorkArea.Y)),
146145
};
147146

148-
if (Interlocked.Increment(ref WindowCount) == 1)
147+
if (App.AppModel.IncrementPropertiesWindowCount() == 1)
149148
PropertiesWindowsClosingTCS = new();
150149

151150
appWindow.Move(appWindowPos);
@@ -164,12 +163,14 @@ private static void PropertiesWindow_Closed(object sender, WindowEventArgs args)
164163
window.Content = null;
165164
WindowCache.Add(window);
166165

167-
if (Interlocked.Decrement(ref WindowCount) == 0)
166+
if (App.AppModel.DecrementPropertiesWindowCount() == 0)
168167
{
169168
PropertiesWindowsClosingTCS!.TrySetResult();
170169
PropertiesWindowsClosingTCS = null;
171170
}
172171
}
172+
else
173+
App.AppModel.DecrementPropertiesWindowCount();
173174
}
174175

175176
/// <summary>

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ private void PreviewPane_Unloaded(object sender, RoutedEventArgs e)
329329

330330
private void UpdateDateDisplayTimer_Tick(object sender, object e)
331331
{
332-
PreviewPane?.ViewModel.UpdateDateDisplay();
332+
if (!App.AppModel.IsMainWindowClosed)
333+
PreviewPane?.ViewModel.UpdateDateDisplay();
333334
}
334335

335336
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)

src/Files.App/Views/Properties/DetailsPage.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ private async void ClearPropertiesConfirmation_Click(object sender, RoutedEventA
7979

8080
private void UpdateDateDisplayTimer_Tick(object sender, object e)
8181
{
82+
if (App.AppModel.PropertiesWindowCount == 0)
83+
return;
84+
8285
ViewModel.PropertySections.ForEach(section => section.ForEach(property =>
8386
{
8487
if (property.Value is DateTimeOffset)

src/Files.App/Views/Properties/GeneralPage.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ private void ItemFileName_LosingFocus(UIElement _, LosingFocusEventArgs e)
4747

4848
private void UpdateDateDisplayTimer_Tick(object sender, object e)
4949
{
50+
if (App.AppModel.PropertiesWindowCount == 0)
51+
return;
52+
5053
// Reassign values to update date display
5154
ViewModel.ItemCreatedTimestampReal = ViewModel.ItemCreatedTimestampReal;
5255
ViewModel.ItemModifiedTimestampReal = ViewModel.ItemModifiedTimestampReal;

src/Files.App/Views/Shells/BaseShellPage.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,9 @@ private void HandleBackForwardRequest(PageStackEntry pageContent)
771771

772772
private void UpdateDateDisplayTimer_Tick(object sender, object e)
773773
{
774+
if (App.AppModel.IsMainWindowClosed)
775+
return;
776+
774777
if (userSettingsService.GeneralSettingsService.DateTimeFormat != _lastDateTimeFormats)
775778
{
776779
_lastDateTimeFormats = userSettingsService.GeneralSettingsService.DateTimeFormat;

0 commit comments

Comments
 (0)