Skip to content

Commit 3359556

Browse files
Fixes unmount iso/virtual drives after ejecting (#9770)
1 parent 714a48d commit 3359556

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Files.App/Helpers/DriveHelpers.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
using Files.App.Interacts;
1+
using Files.App.Interacts;
22
using Files.App.Extensions;
33
using System.Diagnostics;
44
using System.Threading.Tasks;
55
using Windows.UI.Notifications;
66
using CommunityToolkit.WinUI.Notifications;
7+
using Files.App.Shell;
78

89
namespace Files.App.Helpers
910
{
1011
public static class DriveHelpers
1112
{
12-
public static async Task EjectDeviceAsync(string path)
13+
// Eject using Shell Verb (fixes #6072, #6439)
14+
public static Task EjectDeviceAsync(string path)
15+
=> ContextMenu.InvokeVerb("eject", path);
16+
17+
// Eject using DeviceIoControl
18+
/*public static async Task EjectDeviceAsync(string path)
1319
{
1420
var removableDevice = new RemovableDevice(path);
1521
bool result = await removableDevice.EjectAsync();
@@ -57,6 +63,6 @@ await DialogDisplayHelper.ShowDialogAsync(
5763
"EjectNotificationErrorDialogHeader".GetLocalizedResource(),
5864
"EjectNotificationErrorDialogBody".GetLocalizedResource());
5965
}
60-
}
66+
}*/
6167
}
6268
}

src/Files.App/ViewModels/ItemViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ public async Task SetWorkingDirectoryAsync(string value)
166166

167167
WorkingDirectory = value;
168168
OnPropertyChanged(nameof(WorkingDirectory));
169+
170+
if (value == "Home".GetLocalizedResource())
171+
{
172+
// Initialize connection to receive drive notifications
173+
_ = InitializeConnectionAsync(); // fire and forget
174+
}
169175
}
170176

171177
public async Task<FilesystemResult<BaseStorageFolder>> GetFolderFromPathAsync(string value)
@@ -493,6 +499,11 @@ await dispatcherQueue.EnqueueAsync(() =>
493499
}
494500
}
495501

502+
private async Task InitializeConnectionAsync()
503+
{
504+
Connection ??= await AppServiceConnectionHelper.Instance;
505+
}
506+
496507
private async void AppServiceConnectionHelper_ConnectionChanged(object sender, Task<NamedPipeAsAppServiceConnection> e)
497508
{
498509
Connection = await e;
@@ -1311,7 +1322,7 @@ private async void RapidAddItemsToCollectionAsync(string path, string previousDi
13111322

13121323
ItemLoadStatusChanged?.Invoke(this, new ItemLoadStatusChangedEventArgs() { Status = ItemLoadStatusChangedEventArgs.ItemLoadStatus.InProgress });
13131324

1314-
Connection ??= await AppServiceConnectionHelper.Instance;
1325+
await InitializeConnectionAsync();
13151326

13161327
if (path.ToLowerInvariant().EndsWith(ShellLibraryItem.EXTENSION, StringComparison.Ordinal))
13171328
{

0 commit comments

Comments
 (0)