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 issue where the tab sometimes had the wrong icon #12190

Merged
9 changes: 2 additions & 7 deletions src/Files.App/Filesystem/WSLDistroManager.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Data.Items;
using Files.App.Helpers;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
using Windows.Storage;
using static Files.App.Constants;

Expand Down Expand Up @@ -63,7 +58,7 @@ public async Task UpdateDrivesAsync()
}
}

public bool TryGetDistro(string path, out WslDistroItem? distro)
public bool TryGetDistro(string path, [NotNullWhen(true)] out WslDistroItem? distro)
{
var normalizedPath = PathNormalization.NormalizePath(path);
distro = Distros.FirstOrDefault(x => normalizedPath.StartsWith(PathNormalization.NormalizePath(x.Path), StringComparison.OrdinalIgnoreCase));
Expand Down
14 changes: 11 additions & 3 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using Files.App.UserControls.MultitaskingControl;
using Files.App.Views;
using Files.Backend.Services;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Xaml.Navigation;
using System.Windows.Input;
using Windows.System;
Expand Down Expand Up @@ -187,16 +189,16 @@ public async Task UpdateTabInfo(TabItem tabItem, object navigationArg)
}
}

public async Task<(string tabLocationHeader, Microsoft.UI.Xaml.Controls.IconSource tabIcon, string toolTipText)> GetSelectedTabInfoAsync(string currentPath)
public async Task<(string tabLocationHeader, IconSource tabIcon, string toolTipText)> GetSelectedTabInfoAsync(string currentPath)
{
string? tabLocationHeader;
var iconSource = new Microsoft.UI.Xaml.Controls.ImageIconSource();
var iconSource = new ImageIconSource();
string toolTipText = currentPath;

if (string.IsNullOrEmpty(currentPath) || currentPath == "Home")
{
tabLocationHeader = "Home".GetLocalizedResource();
iconSource.ImageSource = new Microsoft.UI.Xaml.Media.Imaging.BitmapImage(new Uri(Constants.FluentIconsPaths.HomeIcon));
iconSource.ImageSource = new BitmapImage(new Uri(Constants.FluentIconsPaths.HomeIcon));
}
else if (currentPath.Equals(Constants.UserEnvironmentPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -224,12 +226,18 @@ public async Task UpdateTabInfo(TabItem tabItem, object navigationArg)
// If localized string is empty use the library name.
tabLocationHeader = string.IsNullOrEmpty(libName) ? library.Text : libName;
}
else if (App.WSLDistroManager.TryGetDistro(currentPath, out WslDistroItem? wslDistro) && currentPath.Equals(wslDistro.Path))
{
tabLocationHeader = wslDistro.Text;
iconSource.ImageSource = new BitmapImage(wslDistro.Logo);
}
else
{
var normalizedCurrentPath = PathNormalization.NormalizePath(currentPath);
var matchingCloudDrive = App.CloudDrivesManager.Drives.FirstOrDefault(x => normalizedCurrentPath.Equals(PathNormalization.NormalizePath(x.Path), StringComparison.OrdinalIgnoreCase));
if (matchingCloudDrive is not null)
{
iconSource.ImageSource = matchingCloudDrive.Icon;
tabLocationHeader = matchingCloudDrive.Text;
}
else if (PathNormalization.NormalizePath(PathNormalization.GetPathRoot(currentPath)) == normalizedCurrentPath) // If path is a drive's root
Expand Down