Skip to content

Commit a1802c0

Browse files
Fix: Fixed issue where the tab sometimes had the wrong icon (#12190)
1 parent 3d638ce commit a1802c0

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Files.App/Filesystem/WSLDistroManager.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.Data.Items;
5-
using Files.App.Helpers;
6-
using System;
7-
using System.Collections.Generic;
84
using System.Collections.Specialized;
9-
using System.Linq;
10-
using System.Threading.Tasks;
5+
using System.Diagnostics.CodeAnalysis;
116
using Windows.Storage;
127
using static Files.App.Constants;
138

@@ -63,7 +58,7 @@ public async Task UpdateDrivesAsync()
6358
}
6459
}
6560

66-
public bool TryGetDistro(string path, out WslDistroItem? distro)
61+
public bool TryGetDistro(string path, [NotNullWhen(true)] out WslDistroItem? distro)
6762
{
6863
var normalizedPath = PathNormalization.NormalizePath(path);
6964
distro = Distros.FirstOrDefault(x => normalizedPath.StartsWith(PathNormalization.NormalizePath(x.Path), StringComparison.OrdinalIgnoreCase));

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using Files.App.UserControls.MultitaskingControl;
77
using Files.App.Views;
88
using Files.Backend.Services;
9+
using Microsoft.UI.Xaml.Controls;
910
using Microsoft.UI.Xaml.Input;
11+
using Microsoft.UI.Xaml.Media.Imaging;
1012
using Microsoft.UI.Xaml.Navigation;
1113
using System.Windows.Input;
1214
using Windows.System;
@@ -187,16 +189,16 @@ public async Task UpdateTabInfo(TabItem tabItem, object navigationArg)
187189
}
188190
}
189191

190-
public async Task<(string tabLocationHeader, Microsoft.UI.Xaml.Controls.IconSource tabIcon, string toolTipText)> GetSelectedTabInfoAsync(string currentPath)
192+
public async Task<(string tabLocationHeader, IconSource tabIcon, string toolTipText)> GetSelectedTabInfoAsync(string currentPath)
191193
{
192194
string? tabLocationHeader;
193-
var iconSource = new Microsoft.UI.Xaml.Controls.ImageIconSource();
195+
var iconSource = new ImageIconSource();
194196
string toolTipText = currentPath;
195197

196198
if (string.IsNullOrEmpty(currentPath) || currentPath == "Home")
197199
{
198200
tabLocationHeader = "Home".GetLocalizedResource();
199-
iconSource.ImageSource = new Microsoft.UI.Xaml.Media.Imaging.BitmapImage(new Uri(Constants.FluentIconsPaths.HomeIcon));
201+
iconSource.ImageSource = new BitmapImage(new Uri(Constants.FluentIconsPaths.HomeIcon));
200202
}
201203
else if (currentPath.Equals(Constants.UserEnvironmentPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
202204
{
@@ -224,12 +226,18 @@ public async Task UpdateTabInfo(TabItem tabItem, object navigationArg)
224226
// If localized string is empty use the library name.
225227
tabLocationHeader = string.IsNullOrEmpty(libName) ? library.Text : libName;
226228
}
229+
else if (App.WSLDistroManager.TryGetDistro(currentPath, out WslDistroItem? wslDistro) && currentPath.Equals(wslDistro.Path))
230+
{
231+
tabLocationHeader = wslDistro.Text;
232+
iconSource.ImageSource = new BitmapImage(wslDistro.Logo);
233+
}
227234
else
228235
{
229236
var normalizedCurrentPath = PathNormalization.NormalizePath(currentPath);
230237
var matchingCloudDrive = App.CloudDrivesManager.Drives.FirstOrDefault(x => normalizedCurrentPath.Equals(PathNormalization.NormalizePath(x.Path), StringComparison.OrdinalIgnoreCase));
231238
if (matchingCloudDrive is not null)
232239
{
240+
iconSource.ImageSource = matchingCloudDrive.Icon;
233241
tabLocationHeader = matchingCloudDrive.Text;
234242
}
235243
else if (PathNormalization.NormalizePath(PathNormalization.GetPathRoot(currentPath)) == normalizedCurrentPath) // If path is a drive's root

0 commit comments

Comments
 (0)