Skip to content

Commit d0aa22b

Browse files
authored
Fix duplicate removable drives in sidebar (#1830)
1 parent bb1f5d9 commit d0aa22b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Files/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private void OnLeavingBackground(object sender, LeavingBackgroundEventArgs e)
7979
{
8080
// Need to reinitialize AppService when app is resuming
8181
InitializeAppServiceConnection();
82-
AppSettings?.DrivesManager?.StartDeviceWatcher();
82+
AppSettings?.DrivesManager?.ResumeDeviceWatcher();
8383
}
8484

8585
public static AppServiceConnection Connection;

Files/Filesystem/Drives.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public bool ShowUserConsentOnInit
3030
}
3131

3232
private DeviceWatcher _deviceWatcher;
33+
private bool _driveEnumInProgress;
3334

3435
public DrivesManager()
3536
{
@@ -38,21 +39,23 @@ public DrivesManager()
3839

3940
private async void EnumerateDrives()
4041
{
42+
_driveEnumInProgress = true;
4143
try
4244
{
4345
await GetDrives(Drives);
4446
GetVirtualDrivesList(Drives);
4547
StartDeviceWatcher();
4648
}
47-
catch (AggregateException)
49+
catch (AggregateException ex)
4850
{
51+
Logger.Warn(ex, ex.Message);
4952
ShowUserConsentOnInit = true;
5053
};
54+
_driveEnumInProgress = false;
5155
}
5256

53-
public void StartDeviceWatcher()
57+
private void StartDeviceWatcher()
5458
{
55-
this.Dispose();
5659
_deviceWatcher = DeviceInformation.CreateWatcher(StorageDevice.GetDeviceSelector());
5760
_deviceWatcher.Added += DeviceAdded;
5861
_deviceWatcher.Removed += DeviceRemoved;
@@ -358,5 +361,14 @@ public void Dispose()
358361
}
359362
}
360363
}
364+
365+
public void ResumeDeviceWatcher()
366+
{
367+
if (!_driveEnumInProgress)
368+
{
369+
this.Dispose();
370+
this.StartDeviceWatcher();
371+
}
372+
}
361373
}
362374
}

0 commit comments

Comments
 (0)