Skip to content
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

Fix: Fixed COMException in UpdateDateDisplayTimer_Tick #14051

Merged
merged 3 commits into from
Nov 24, 2023
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
20 changes: 20 additions & 0 deletions src/Files.App/Data/Models/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ public bool IsMainWindowClosed
set => SetProperty(ref isMainWindowClosed, value);
}

private int propertiesWindowCount = 0;
public int PropertiesWindowCount
{
get => propertiesWindowCount;
}

public int IncrementPropertiesWindowCount()
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
var result = Interlocked.Increment(ref propertiesWindowCount);
OnPropertyChanged(nameof(PropertiesWindowCount));
return result;
}

public int DecrementPropertiesWindowCount()
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
var result = Interlocked.Decrement(ref propertiesWindowCount);
OnPropertyChanged(nameof(PropertiesWindowCount));
return result;
}

private bool forceProcessTermination = false;
public bool ForceProcessTermination
{
Expand Down
7 changes: 4 additions & 3 deletions src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WinUIEx.WindowEx> WindowCache = new();

Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/Properties/DetailsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/Properties/GeneralPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/Shells/BaseShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down