Skip to content

Fix: Fixed network locations not appearing on the sidebar #12411

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 7 commits into from
May 22, 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
6 changes: 3 additions & 3 deletions src/Files.App/Data/Models/NetworkDrivesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ public NetworkDrivesViewModel(INetworkDrivesService networkDrivesService)
public async Task UpdateDrivesAsync()
{
var unsortedDrives = new List<ILocatableFolder>();
Drives.Clear();

unsortedDrives.Add(drives.Single(x => x is DriveItem o && o.DeviceID == "network-folder"));
await foreach (ILocatableFolder item in networkDrivesService.GetDrivesAsync())
{
unsortedDrives.Add(item);
}

var orderedDrives = unsortedDrives.Cast<DriveItem>()
.OrderByDescending(o => string.Equals(o.Text, "Network".GetLocalizedResource(), StringComparison.OrdinalIgnoreCase))
.OrderByDescending(o => o.DeviceID == "network-folder")
.ThenBy(o => o.Text);

Drives.Clear();
foreach (ILocatableFolder item in orderedDrives)
{
Drives.AddIfNotPresent(item);
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Filesystem/Cloud/CloudDrivesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CloudDrivesManager
{
private readonly ILogger _logger = Ioc.Default.GetRequiredService<ILogger<App>>();

private readonly ICloudDetector _detector = Ioc.Default.GetService<ICloudDetector>();
private readonly ICloudDetector _detector = Ioc.Default.GetRequiredService<ICloudDetector>();

public EventHandler<NotifyCollectionChangedEventArgs> DataChanged;

Expand All @@ -30,7 +30,7 @@ public IReadOnlyList<DriveItem> Drives

public async Task UpdateDrivesAsync()
{
var providers = await _detector?.DetectCloudProvidersAsync();
var providers = await _detector.DetectCloudProvidersAsync();
if (providers is null)
return;

Expand Down
10 changes: 3 additions & 7 deletions src/Files.App/Helpers/FtpHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,9 @@ public static ushort GetFtpPort(string path)
public static string GetFtpAuthority(string path)
{
path = path.Replace("\\", "/", StringComparison.Ordinal);
var schemaIndex = path.IndexOf("://", StringComparison.Ordinal) + 3;
var hostIndex = path.IndexOf("/", schemaIndex, StringComparison.Ordinal);

if (hostIndex == -1)
hostIndex = path.Length;

return path.Substring(schemaIndex, hostIndex - schemaIndex);
if (Uri.TryCreate(path, UriKind.Absolute, out var uri))
return uri.Authority;
return string.Empty;
}

public static string GetFtpPath(string path)
Expand Down
9 changes: 5 additions & 4 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public TabItem? SelectedTabItem
public IAsyncRelayCommand OpenNewWindowAcceleratorCommand { get; private set; }

public MainPageViewModel(
IUserSettingsService userSettings,
IUserSettingsService userSettings,
IAppearanceSettingsService appearanceSettings,
IResourcesService resources,
DrivesViewModel drivesViewModel,
Expand Down Expand Up @@ -267,9 +267,6 @@ public async Task OnNavigatedTo(NavigationEventArgs e)
if (e.NavigationMode == NavigationMode.Back)
return;

if (drivesViewModel.Drives.Count == 0)
await drivesViewModel.UpdateDrivesAsync();

//Initialize the static theme helper to capture a reference to this window
//to handle theme changes without restarting the app
ThemeHelper.Initialize();
Expand Down Expand Up @@ -368,6 +365,10 @@ public async Task OnNavigatedTo(NavigationEventArgs e)

// Load the app theme resources
resourcesService.LoadAppResources(appearanceSettingsService);

await Task.WhenAll(
drivesViewModel.UpdateDrivesAsync(),
networkDrivesViewModel.UpdateDrivesAsync());
}

public Task AddNewTabAsync()
Expand Down
28 changes: 20 additions & 8 deletions src/Files.App/ViewModels/UserControls/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,28 @@ await lib.CheckDefaultSaveFolderAccess() &&
}
else if (elem is DriveItem drive)
{
string drivePath = drive.Path;
IList<string> paths = section.ChildItems.Select(item => item.Path).ToList();

if (!paths.Contains(drivePath))
if (section.Section is SectionType.Network or SectionType.CloudDrives)
{
// Already sorted
if (!section.ChildItems.Any(x => x.Path == drive.Path))
{
section.ChildItems.Insert(index < 0 ? section.ChildItems.Count : Math.Min(index, section.ChildItems.Count), drive);
await drive.LoadThumbnailAsync(true);
}
}
else
{
paths.AddSorted(drivePath);
int position = paths.IndexOf(drivePath);
string drivePath = drive.Path;
IList<string> paths = section.ChildItems.Select(item => item.Path).ToList();

if (!paths.Contains(drivePath))
{
paths.AddSorted(drivePath);
int position = paths.IndexOf(drivePath);

section.ChildItems.Insert(position, drive);
await drive.LoadThumbnailAsync(true);
section.ChildItems.Insert(position, drive);
await drive.LoadThumbnailAsync(true);
}
}
}
else
Expand Down