Skip to content

Commit 271a416

Browse files
authored
Fix: Fixed network locations not appearing on the sidebar (#12411)
1 parent c453cdc commit 271a416

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

src/Files.App/Data/Models/NetworkDrivesViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public NetworkDrivesViewModel(INetworkDrivesService networkDrivesService)
4848
public async Task UpdateDrivesAsync()
4949
{
5050
var unsortedDrives = new List<ILocatableFolder>();
51-
Drives.Clear();
52-
51+
unsortedDrives.Add(drives.Single(x => x is DriveItem o && o.DeviceID == "network-folder"));
5352
await foreach (ILocatableFolder item in networkDrivesService.GetDrivesAsync())
5453
{
5554
unsortedDrives.Add(item);
5655
}
5756

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

61+
Drives.Clear();
6262
foreach (ILocatableFolder item in orderedDrives)
6363
{
6464
Drives.AddIfNotPresent(item);

src/Files.App/Filesystem/Cloud/CloudDrivesManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CloudDrivesManager
1212
{
1313
private readonly ILogger _logger = Ioc.Default.GetRequiredService<ILogger<App>>();
1414

15-
private readonly ICloudDetector _detector = Ioc.Default.GetService<ICloudDetector>();
15+
private readonly ICloudDetector _detector = Ioc.Default.GetRequiredService<ICloudDetector>();
1616

1717
public EventHandler<NotifyCollectionChangedEventArgs> DataChanged;
1818

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

3131
public async Task UpdateDrivesAsync()
3232
{
33-
var providers = await _detector?.DetectCloudProvidersAsync();
33+
var providers = await _detector.DetectCloudProvidersAsync();
3434
if (providers is null)
3535
return;
3636

src/Files.App/Helpers/FtpHelpers.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ public static ushort GetFtpPort(string path)
6767
public static string GetFtpAuthority(string path)
6868
{
6969
path = path.Replace("\\", "/", StringComparison.Ordinal);
70-
var schemaIndex = path.IndexOf("://", StringComparison.Ordinal) + 3;
71-
var hostIndex = path.IndexOf("/", schemaIndex, StringComparison.Ordinal);
72-
73-
if (hostIndex == -1)
74-
hostIndex = path.Length;
75-
76-
return path.Substring(schemaIndex, hostIndex - schemaIndex);
70+
if (Uri.TryCreate(path, UriKind.Absolute, out var uri))
71+
return uri.Authority;
72+
return string.Empty;
7773
}
7874

7975
public static string GetFtpPath(string path)

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public TabItem? SelectedTabItem
3838
public IAsyncRelayCommand OpenNewWindowAcceleratorCommand { get; private set; }
3939

4040
public MainPageViewModel(
41-
IUserSettingsService userSettings,
41+
IUserSettingsService userSettings,
4242
IAppearanceSettingsService appearanceSettings,
4343
IResourcesService resources,
4444
DrivesViewModel drivesViewModel,
@@ -267,9 +267,6 @@ public async Task OnNavigatedTo(NavigationEventArgs e)
267267
if (e.NavigationMode == NavigationMode.Back)
268268
return;
269269

270-
if (drivesViewModel.Drives.Count == 0)
271-
await drivesViewModel.UpdateDrivesAsync();
272-
273270
//Initialize the static theme helper to capture a reference to this window
274271
//to handle theme changes without restarting the app
275272
ThemeHelper.Initialize();
@@ -368,6 +365,10 @@ public async Task OnNavigatedTo(NavigationEventArgs e)
368365

369366
// Load the app theme resources
370367
resourcesService.LoadAppResources(appearanceSettingsService);
368+
369+
await Task.WhenAll(
370+
drivesViewModel.UpdateDrivesAsync(),
371+
networkDrivesViewModel.UpdateDrivesAsync());
371372
}
372373

373374
public Task AddNewTabAsync()

src/Files.App/ViewModels/UserControls/SidebarViewModel.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,28 @@ await lib.CheckDefaultSaveFolderAccess() &&
332332
}
333333
else if (elem is DriveItem drive)
334334
{
335-
string drivePath = drive.Path;
336-
IList<string> paths = section.ChildItems.Select(item => item.Path).ToList();
337-
338-
if (!paths.Contains(drivePath))
335+
if (section.Section is SectionType.Network or SectionType.CloudDrives)
336+
{
337+
// Already sorted
338+
if (!section.ChildItems.Any(x => x.Path == drive.Path))
339+
{
340+
section.ChildItems.Insert(index < 0 ? section.ChildItems.Count : Math.Min(index, section.ChildItems.Count), drive);
341+
await drive.LoadThumbnailAsync(true);
342+
}
343+
}
344+
else
339345
{
340-
paths.AddSorted(drivePath);
341-
int position = paths.IndexOf(drivePath);
346+
string drivePath = drive.Path;
347+
IList<string> paths = section.ChildItems.Select(item => item.Path).ToList();
348+
349+
if (!paths.Contains(drivePath))
350+
{
351+
paths.AddSorted(drivePath);
352+
int position = paths.IndexOf(drivePath);
342353

343-
section.ChildItems.Insert(position, drive);
344-
await drive.LoadThumbnailAsync(true);
354+
section.ChildItems.Insert(position, drive);
355+
await drive.LoadThumbnailAsync(true);
356+
}
345357
}
346358
}
347359
else

0 commit comments

Comments
 (0)