Skip to content

Code Quality: Transition Sidebar and Tabs away from LoadIconFromPathAsync #14701

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

Merged
merged 1 commit into from
Feb 12, 2024
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
10 changes: 1 addition & 9 deletions src/Files.App/Data/Models/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,12 @@ public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
locationItem.IsInvalid = false;
if (res && res.Result is not null)
{
var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 16u, ThumbnailMode.ListView, ThumbnailOptions.UseCurrentScale);
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(res.Result.Path, 28u, true, false, true);
locationItem.IconData = iconData;

if (locationItem.IconData is not null)
locationItem.Icon = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => locationItem.IconData.ToBitmapAsync());
}

if (locationItem.IconData is null)
{
locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 48u, false, false, true);

if (locationItem.IconData is not null)
locationItem.Icon = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => locationItem.IconData.ToBitmapAsync());
}
}
else
{
Expand Down
17 changes: 1 addition & 16 deletions src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,15 @@ private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigati
iconSource.ImageSource = new BitmapImage(new Uri(Constants.FluentIconsPaths.HomeIcon));
}
else if (currentPath.Equals(Constants.UserEnvironmentPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
{
tabLocationHeader = "Desktop".GetLocalizedResource();
}
else if (currentPath.Equals(Constants.UserEnvironmentPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase))
{
tabLocationHeader = "Downloads".GetLocalizedResource();
}
else if (currentPath.Equals(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
{
tabLocationHeader = "RecycleBin".GetLocalizedResource();

// Use 48 for higher resolution, the other items look fine with 16.
var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(currentPath, 48u, Windows.Storage.FileProperties.ThumbnailMode.ListView, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale, true);
if (iconData is not null)
iconSource.ImageSource = await iconData.ToBitmapAsync();
}
else if (currentPath.Equals(Constants.UserEnvironmentPaths.MyComputerPath, StringComparison.OrdinalIgnoreCase))
{
tabLocationHeader = "ThisPC".GetLocalizedResource();
}
else if (currentPath.Equals(Constants.UserEnvironmentPaths.NetworkFolderPath, StringComparison.OrdinalIgnoreCase))
{
tabLocationHeader = "SidebarNetworkDrives".GetLocalizedResource();
}
else if (App.LibraryManager.TryGetLibrary(currentPath, out LibraryLocationItem library))
{
var libName = System.IO.Path.GetFileNameWithoutExtension(library.Path).GetLocalizedResource();
Expand Down Expand Up @@ -203,7 +188,7 @@ private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigati

if (iconSource.ImageSource is null)
{
var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(currentPath, 16u, Windows.Storage.FileProperties.ThumbnailMode.ListView, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale, true);
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(currentPath, 28u, true, false, true);
if (iconData is not null)
iconSource.ImageSource = await iconData.ToBitmapAsync();
}
Expand Down