Skip to content
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
3 changes: 3 additions & 0 deletions Files/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ sealed partial class App : Application
public static CloudDrivesManager CloudDrivesManager { get; private set; }
public static NetworkDrivesManager NetworkDrivesManager { get; private set; }
public static DrivesManager DrivesManager { get; private set; }
public static WSLDistroManager WSLDistroManager { get; private set; }

private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

Expand Down Expand Up @@ -92,13 +93,15 @@ private static async Task EnsureSettingsAndConfigurationAreBootstrapped()
DrivesManager ??= new DrivesManager();
NetworkDrivesManager ??= new NetworkDrivesManager();
CloudDrivesManager ??= new CloudDrivesManager();
WSLDistroManager ??= new WSLDistroManager();

// Start off a list of tasks we need to run before we can continue startup
_ = Task.Factory.StartNew(async () =>
{
await DrivesManager.EnumerateDrivesAsync();
await CloudDrivesManager.EnumerateDrivesAsync();
await NetworkDrivesManager.EnumerateDrivesAsync();
await WSLDistroManager.EnumerateDrivesAsync();
});
}

Expand Down
1 change: 1 addition & 0 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<Compile Include="Enums\FolderLayoutModes.cs" />
<Compile Include="Extensions\TaskExtensions.cs" />
<Compile Include="Filesystem\FolderHelpers.cs" />
<Compile Include="Filesystem\WSLDistroManager.cs" />
<Compile Include="Filesystem\StorageEnumerators\UniversalStorageEnumerator.cs" />
<Compile Include="Filesystem\StorageEnumerators\Win32StorageEnumerator.cs" />
<Compile Include="Enums\FileSystemStatusCode.cs" />
Expand Down
120 changes: 120 additions & 0 deletions Files/Filesystem/WSLDistroManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using Files.Views;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Storage;
using Windows.UI.Core;

namespace Files.Filesystem
{
public class WSLDistroManager : ObservableObject
{
public WSLDistroManager()
{

}

public async Task EnumerateDrivesAsync()
{
try
{
await SyncSideBarItemsUI();
}
catch (Exception) // UI Thread not ready yet, so we defer the pervious operation until it is.
{
System.Diagnostics.Debug.WriteLine($"RefreshUI Exception");
// Defer because UI-thread is not ready yet (and DriveItem requires it?)
CoreApplication.MainView.Activated += EnumerateDrivesAsync;
}
}

private async void EnumerateDrivesAsync(CoreApplicationView sender, Windows.ApplicationModel.Activation.IActivatedEventArgs args)
{
await SyncSideBarItemsUI();
CoreApplication.MainView.Activated -= EnumerateDrivesAsync;
}

private async Task SyncSideBarItemsUI()
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await MainPage.SideBarItemsSemaphore.WaitAsync();
try
{
MainPage.SideBarItems.BeginBulkOperation();

try
{
var distroFolder = await StorageFolder.GetFolderFromPathAsync(@"\\wsl$\");
if ((await distroFolder.GetFoldersAsync()).Count != 0)
{
var section = MainPage.SideBarItems.FirstOrDefault(x => x.Text == "WSL") as LocationItem;

section = new LocationItem()
{
Text = "WSL",
Font = App.Current.Resources["FluentUIGlyphs"] as Windows.UI.Xaml.Media.FontFamily,
Glyph = "\uec34",
SelectsOnInvoked = false,
ChildItems = new ObservableCollection<INavigationControlItem>()
};
MainPage.SideBarItems.Add(section);


foreach (StorageFolder folder in await distroFolder.GetFoldersAsync())
{
Uri logoURI = null;
if (folder.DisplayName.Contains("ubuntu", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/ubuntupng.png");
}
else if (folder.DisplayName.Contains("kali", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/kalipng.png");
}
else if (folder.DisplayName.Contains("debian", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/debianpng.png");
}
else if (folder.DisplayName.Contains("opensuse", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/opensusepng.png");
}
else if (folder.DisplayName.Contains("alpine", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/alpinepng.png");
}
else
{
logoURI = new Uri("ms-appx:///Assets/WSL/genericpng.png");
}

section.ChildItems.Add(new WSLDistroItem()
{
Text = folder.DisplayName,
Path = folder.Path,
Logo = logoURI
});
}

}
}
catch (Exception)
{
// WSL Not Supported/Enabled
}


MainPage.SideBarItems.EndBulkOperation();
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
}
});
}
}
}
1 change: 1 addition & 0 deletions Files/UserControls/SidebarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
DataContext="{x:Bind}"
DragEnter="NavigationViewItem_DragEnter"
DragLeave="NavigationViewItem_DragLeave"
RightTapped="NavigationViewWSLItem_RightTapped"
Tag="{x:Bind Path}"
ToolTipService.ToolTip="{x:Bind HoverDisplayText, Mode=OneWay}">
<muxc:NavigationViewItem.Icon>
Expand Down
19 changes: 19 additions & 0 deletions Files/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private void NavigationViewLocationItem_RightTapped(object sender, RightTappedRo
if (!item.Text.Equals("SidebarDrives".GetLocalized()) &&
!item.Text.Equals("SidebarNetworkDrives".GetLocalized()) &&
!item.Text.Equals("SidebarCloudDrives".GetLocalized()) &&
!item.Text.Equals("WSL") &&
!item.Text.Equals("SidebarFavorites".GetLocalized()))
{
ShowEmptyRecycleBin = false;
Expand Down Expand Up @@ -272,6 +273,24 @@ private void NavigationViewDriveItem_RightTapped(object sender, RightTappedRoute
e.Handled = true;
}

private void NavigationViewWSLItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
{

Microsoft.UI.Xaml.Controls.NavigationViewItem sidebarItem = (Microsoft.UI.Xaml.Controls.NavigationViewItem)sender;
var item = sidebarItem.DataContext as WSLDistroItem;

ShowEjectDevice = false;
ShowUnpinItem = false;
ShowEmptyRecycleBin = false;
ShowProperties = true;

SideBarItemContextFlyout.ShowAt(sidebarItem, e.GetPosition(sidebarItem));

App.RightClickedItem = item;

e.Handled = true;
}

private void OpenInNewTab_Click(object sender, RoutedEventArgs e)
{
Interaction.OpenPathInNewTab(App.RightClickedItem.Path);
Expand Down
63 changes: 0 additions & 63 deletions Files/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ private async Task<SettingsViewModel> Initialize()
DefaultLanguages.Add(new DefaultLanguageModel(lang));
}

//DetectWSLDistros();
TerminalController = await TerminalController.CreateInstance();

// Send analytics to AppCenter
Expand Down Expand Up @@ -144,59 +143,6 @@ public async void DetectQuickLook()
}
}

private async void DetectWSLDistros()
{
try
{
var distroFolder = await StorageFolder.GetFolderFromPathAsync(@"\\wsl$\");
if ((await distroFolder.GetFoldersAsync()).Count > 0)
{
AreLinuxFilesSupported = false;
}

foreach (StorageFolder folder in await distroFolder.GetFoldersAsync())
{
Uri logoURI = null;
if (folder.DisplayName.Contains("ubuntu", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/ubuntupng.png");
}
else if (folder.DisplayName.Contains("kali", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/kalipng.png");
}
else if (folder.DisplayName.Contains("debian", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/debianpng.png");
}
else if (folder.DisplayName.Contains("opensuse", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/opensusepng.png");
}
else if (folder.DisplayName.Contains("alpine", StringComparison.OrdinalIgnoreCase))
{
logoURI = new Uri("ms-appx:///Assets/WSL/alpinepng.png");
}
else
{
logoURI = new Uri("ms-appx:///Assets/WSL/genericpng.png");
}

MainPage.SideBarItems.Add(new WSLDistroItem()
{
Text = folder.DisplayName,
Path = folder.Path,
Logo = logoURI
});
}
}
catch (Exception)
{
// WSL Not Supported/Enabled
AreLinuxFilesSupported = false;
}
}

private void DetectDateTimeFormat()
{
if (localSettings.Values[Constants.LocalSettings.DateTimeFormat] != null)
Expand Down Expand Up @@ -694,15 +640,6 @@ public string[] LastSessionPages

#endregion Startup

/// <summary>
/// Gets or sets a value indicating whether or not WSL is supported.
/// </summary>
public bool AreLinuxFilesSupported
{
get => Get(false);
set => Set(value);
}

/// <summary>
/// Gets or sets a value indicating whether or not to show a teaching tip informing the user about the status center.
/// </summary>
Expand Down