Skip to content

Commit a42ca79

Browse files
authored
Fix crash when favorites section is hidden (#8833)
1 parent 8047873 commit a42ca79

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Files.Uwp/Controllers/SidebarPinnedController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
133133
});
134134
}
135135

136-
137136
public void SaveModel()
138137
{
139138
suppressChangeEvent = true;

src/Files.Uwp/DataModels/SidebarPinnedModel.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,17 @@ public void RemoveStaleSidebarItems()
410410
{
411411
// Remove unpinned items from sidebar
412412
// Reverse iteration to avoid skipping elements while removing
413-
for (int i = favoriteSection.ChildItems.Count - 1; i >= 0; i--)
413+
if (favoriteSection != null)
414414
{
415-
var childItem = favoriteSection.ChildItems[i];
416-
if (childItem is LocationItem)
415+
for (int i = favoriteSection.ChildItems.Count - 1; i >= 0; i--)
417416
{
418-
var item = childItem as LocationItem;
419-
if (!item.IsDefaultLocation && !FavoriteItems.Contains(item.Path))
417+
var childItem = favoriteSection.ChildItems[i];
418+
if (childItem is LocationItem item)
420419
{
421-
favoriteSection.ChildItems.RemoveAt(i);
420+
if (!item.IsDefaultLocation && !FavoriteItems.Contains(item.Path))
421+
{
422+
favoriteSection.ChildItems.RemoveAt(i);
423+
}
422424
}
423425
}
424426
}

0 commit comments

Comments
 (0)