Skip to content

Commit d9c9bbb

Browse files
authored
Fix: Fixed an issue where ejecting drives would sometimes fail (#16124)
1 parent 1d61dd6 commit d9c9bbb

File tree

6 files changed

+17
-27
lines changed

6 files changed

+17
-27
lines changed

src/Files.App/Data/Items/DriveItem.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,9 @@ public FrameworkElement? ItemDecorator
216216
}
217217
}
218218

219-
private async void ItemDecorator_Click(object sender, RoutedEventArgs e)
219+
private void ItemDecorator_Click(object sender, RoutedEventArgs e)
220220
{
221-
var result = await DriveHelpers.EjectDeviceAsync(Path);
222-
await UIHelpers.ShowDeviceEjectResultAsync(Type, result);
221+
DriveHelpers.EjectDeviceAsync(Path);
223222
}
224223

225224
public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root, string deviceId, string label, DriveType type, IRandomAccessStream imageStream = null)

src/Files.App/Utils/Storage/Helpers/DriveHelpers.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ namespace Files.App.Utils.Storage
1313
{
1414
public static class DriveHelpers
1515
{
16-
public static Task<bool> EjectDeviceAsync(string path)
16+
public static async void EjectDeviceAsync(string path)
1717
{
18-
var removableDevice = new RemovableDevice(path);
19-
return removableDevice.EjectAsync();
18+
await ContextMenu.InvokeVerb("eject", path);
2019
}
2120

2221
public static string GetVolumeId(string driveName)
@@ -47,10 +46,7 @@ public static async Task<bool> CheckEmptyDrive(string? drivePath)
4746
"InsertDiscDialog/OpenDriveButton".GetLocalizedResource(),
4847
"Close".GetLocalizedResource());
4948
if (ejectButton)
50-
{
51-
var result = await EjectDeviceAsync(matchingDrive.Path);
52-
await UIHelpers.ShowDeviceEjectResultAsync(matchingDrive.Type, result);
53-
}
49+
EjectDeviceAsync(matchingDrive.Path);
5450
return true;
5551
}
5652

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,7 @@ await DialogDisplayHelper.ShowDialogAsync("CommandNotExecutable".GetLocalizedRes
754754
{
755755
bool ejectButton = await DialogDisplayHelper.ShowDialogAsync("InsertDiscDialog/Title".GetLocalizedResource(), string.Format("InsertDiscDialog/Text".GetLocalizedResource(), matchingDrive.Path), "InsertDiscDialog/OpenDriveButton".GetLocalizedResource(), "Close".GetLocalizedResource());
756756
if (ejectButton)
757-
{
758-
var result = await DriveHelpers.EjectDeviceAsync(matchingDrive.Path);
759-
await UIHelpers.ShowDeviceEjectResultAsync(matchingDrive.Type, result);
760-
}
757+
DriveHelpers.EjectDeviceAsync(matchingDrive.Path);
761758
return;
762759
}
763760
var pathToNavigate = resFolder.Result?.Path ?? normalizedInput;
@@ -958,7 +955,8 @@ public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPag
958955
return true;
959956
}))
960957
{
961-
SafetyExtensions.IgnoreExceptions(() => {
958+
SafetyExtensions.IgnoreExceptions(() =>
959+
{
962960
NavigationBarSuggestions.Clear();
963961
NavigationBarSuggestions.Add(new NavigationBarSuggestionItem()
964962
{

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public SidebarViewModel()
260260
OpenInNewTabCommand = new AsyncRelayCommand(OpenInNewTabAsync);
261261
OpenInNewWindowCommand = new AsyncRelayCommand(OpenInNewWindowAsync);
262262
OpenInNewPaneCommand = new AsyncRelayCommand(OpenInNewPaneAsync);
263-
EjectDeviceCommand = new AsyncRelayCommand(EjectDeviceAsync);
263+
EjectDeviceCommand = new RelayCommand(EjectDevice);
264264
FormatDriveCommand = new RelayCommand(FormatDrive);
265265
OpenPropertiesCommand = new RelayCommand<CommandBarFlyout>(OpenProperties);
266266
ReorderItemsCommand = new AsyncRelayCommand(ReorderItemsAsync);
@@ -953,10 +953,9 @@ private void OpenProperties(CommandBarFlyout menu)
953953
menu.Closed += flyoutClosed;
954954
}
955955

956-
private async Task EjectDeviceAsync()
956+
private void EjectDevice()
957957
{
958-
var result = await DriveHelpers.EjectDeviceAsync(rightClickedItem.Path);
959-
await UIHelpers.ShowDeviceEjectResultAsync(rightClickedItem is DriveItem driveItem ? driveItem.Type : Data.Items.DriveType.Unknown, result);
958+
DriveHelpers.EjectDeviceAsync(rightClickedItem.Path);
960959
}
961960

962961
private void FormatDrive()

src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public DrivesWidgetViewModel()
4646
PinToSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecutePinToSidebarCommand);
4747
UnpinFromSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteUnpinFromSidebarCommand);
4848
FormatDriveCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteFormatDriveCommand);
49-
EjectDeviceCommand = new AsyncRelayCommand<WidgetDriveCardItem>(ExecuteEjectDeviceCommand);
49+
EjectDeviceCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteEjectDeviceCommand);
5050
OpenInNewPaneCommand = new AsyncRelayCommand<WidgetDriveCardItem>(ExecuteOpenInNewPaneCommand);
5151
OpenPropertiesCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteOpenPropertiesCommand);
5252
DisconnectNetworkDriveCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteDisconnectNetworkDriveCommand);
@@ -171,13 +171,12 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
171171

172172
// Command methods
173173

174-
private async Task ExecuteEjectDeviceCommand(WidgetDriveCardItem? item)
174+
private void ExecuteEjectDeviceCommand(WidgetDriveCardItem? item)
175175
{
176176
if (item is null)
177177
return;
178178

179-
var result = await DriveHelpers.EjectDeviceAsync(item.Item.Path);
180-
await UIHelpers.ShowDeviceEjectResultAsync(item.Item.Type, result);
179+
DriveHelpers.EjectDeviceAsync(item.Item.Path);
181180
}
182181

183182
private async Task ExecuteOpenInNewPaneCommand(WidgetDriveCardItem? item)

src/Files.App/ViewModels/UserControls/Widgets/NetworkLocationsWidgetViewModel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public NetworkLocationsWidgetViewModel()
6161
PinToSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecutePinToSidebarCommand);
6262
UnpinFromSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteUnpinFromSidebarCommand);
6363
FormatDriveCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteFormatDriveCommand);
64-
EjectDeviceCommand = new AsyncRelayCommand<WidgetDriveCardItem>(ExecuteEjectDeviceCommand);
64+
EjectDeviceCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteEjectDeviceCommand);
6565
OpenInNewPaneCommand = new AsyncRelayCommand<WidgetDriveCardItem>(ExecuteOpenInNewPaneCommand);
6666
OpenPropertiesCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteOpenPropertiesCommand);
6767
DisconnectNetworkDriveCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteDisconnectNetworkDriveCommand);
@@ -203,13 +203,12 @@ public void DisableWidget()
203203

204204
// Command methods
205205

206-
private async Task ExecuteEjectDeviceCommand(WidgetDriveCardItem? item)
206+
private void ExecuteEjectDeviceCommand(WidgetDriveCardItem? item)
207207
{
208208
if (item is null)
209209
return;
210210

211-
var result = await DriveHelpers.EjectDeviceAsync(item.Item.Path);
212-
await UIHelpers.ShowDeviceEjectResultAsync(item.Item.Type, result);
211+
DriveHelpers.EjectDeviceAsync(item.Item.Path);
213212
}
214213

215214
private async Task ExecuteOpenInNewPaneCommand(WidgetDriveCardItem? item)

0 commit comments

Comments
 (0)