Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Files/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public static class Bundles
{
public const int MaxAmountOfItemsPerBundle = 8;
}

public static class Drives
{
public const float LowStorageSpacePercentageThreshold = 90.0f;
}
}

public static class LocalSettings
Expand Down
38 changes: 37 additions & 1 deletion Files/Filesystem/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ public string SpaceText

public SectionType Section { get; set; }


private float percentageUsed = 0.0f;
public float PercentageUsed
{
get => percentageUsed;
set
{
if (SetProperty(ref percentageUsed, value))
{
if (Type == DriveType.Fixed)
{
if (percentageUsed >= Constants.Widgets.Drives.LowStorageSpacePercentageThreshold)
{
ShowStorageSense = true;
}
else
{
ShowStorageSense = false;
}
}
}
}
}

private bool showStorageSense = false;
public bool ShowStorageSense
{
get => showStorageSense;
set => SetProperty(ref showStorageSense, value);
}

public DriveItem()
{
ItemType = NavigationControlItemType.CloudDrive;
Expand All @@ -107,7 +138,7 @@ public DriveItem(StorageFolder root, string deviceId, DriveType type)
DeviceID = deviceId;
Root = root;

CoreApplication.MainView.ExecuteOnUIThreadAsync(() => UpdatePropertiesAsync());
CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UpdatePropertiesAsync());
}

public async Task UpdateLabelAsync()
Expand Down Expand Up @@ -140,6 +171,11 @@ public async Task UpdatePropertiesAsync()
"DriveFreeSpaceAndCapacity".GetLocalized(),
FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
MaxSpace.ToBinaryString().ConvertSizeAbbreviation());

if (FreeSpace.Bytes > 0 && MaxSpace.Bytes > 0) // Make sure we don't divide by 0
{
PercentageUsed = 100.0f - ((float)(FreeSpace.Bytes / MaxSpace.Bytes) * 100.0f);
}
}
}
catch (Exception)
Expand Down
9 changes: 6 additions & 3 deletions Files/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1950,10 +1950,10 @@
<data name="PinItemToStart.Text" xml:space="preserve">
<value>Pin to the Start Menu</value>
</data>
<data name="UnpinItemFromStart.Text" xml:space="preserve">
<data name="UnpinItemFromStart.Text" xml:space="preserve">
<value>Unpin from the Start Menu</value>
</data>
<data name="BaseLayoutContextFlyoutColumn.Text" xml:space="preserve">
<data name="BaseLayoutContextFlyoutColumn.Text" xml:space="preserve">
<value>Column View</value>
</data>
<data name="ItemTypeLibrary" xml:space="preserve">
Expand Down Expand Up @@ -2031,4 +2031,7 @@
<data name="DialogDeleteLibraryButtonText" xml:space="preserve">
<value>Delete</value>
</data>
</root>
<data name="DrivesWidgetOpenStorageSenseButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Open Storage Sense</value>
</data>
</root>
46 changes: 38 additions & 8 deletions Files/UserControls/Widgets/DrivesWidget.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,44 @@
Margin="12,0,0,0"
VerticalAlignment="Center"
Orientation="Vertical">
<TextBlock
x:Name="ItemLocationName"
Margin="0,0,0,8"
VerticalAlignment="Center"
FontSize="14"
FontWeight="Medium"
Text="{x:Bind Text, Mode=OneWay}"
TextWrapping="NoWrap" />
<Grid Margin="0,0,0,8" HorizontalAlignment="Stretch">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<TextBlock
x:Name="ItemLocationName"
VerticalAlignment="Center"
FontSize="14"
FontWeight="Medium"
Text="{x:Bind Text, Mode=OneWay}"
TextWrapping="NoWrap" />

<Button
x:Uid="DrivesWidgetOpenStorageSenseButton"
Grid.Column="1"
HorizontalAlignment="Right"
x:Name="GoToStorageSense"
x:Load="{x:Bind ShowStorageSense}"
Click="GoToStorageSense_Click"
Background="Transparent"
BorderThickness="0"
Width="30"
Height="30"
ToolTipService.ToolTip="Open Storage Sense"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
Padding="0">
<FontIcon
Glyph="&#xEA41;"
FontSize="18"
FontFamily="{StaticResource OldFluentUIGlyphs}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Button>
</Grid>
<muxc:ProgressBar
Margin="0,0,0,8"
AutomationProperties.AccessibilityView="Raw"
Expand Down
6 changes: 6 additions & 0 deletions Files/UserControls/Widgets/DrivesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using Windows.Foundation.Collections;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
Expand Down Expand Up @@ -169,5 +170,10 @@ await AppInstance.ServiceConnection.SendMessageAsync(new ValueSet()
});
}
}

private async void GoToStorageSense_Click(object sender, RoutedEventArgs e)
{
await Launcher.LaunchUriAsync(new Uri("ms-settings:storagesense"));
}
}
}