|
1 |
| -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Collections.ObjectModel;
|
4 | 4 | using System.Diagnostics;
|
@@ -51,37 +51,25 @@ public DrivesManager()
|
51 | 51 | });
|
52 | 52 | }
|
53 | 53 |
|
54 |
| - private async void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args) |
| 54 | + private void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args) |
55 | 55 | {
|
56 |
| - // Only update collection from UI-thread |
57 |
| - try |
| 56 | + if (App.sideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == ResourceController.GetTranslation("SidebarDrives")) == null) |
| 57 | + { |
| 58 | + App.sideBarItems.Add(new HeaderTextItem() { Text = ResourceController.GetTranslation("SidebarDrives") }); |
| 59 | + } |
| 60 | + foreach (DriveItem drive in Drives) |
58 | 61 | {
|
59 |
| - await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => |
| 62 | + if (!App.sideBarItems.Contains(drive)) |
60 | 63 | {
|
61 |
| - if (App.sideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == ResourceController.GetTranslation("SidebarDrives")) == null) |
62 |
| - { |
63 |
| - App.sideBarItems.Add(new HeaderTextItem() { Text = ResourceController.GetTranslation("SidebarDrives") }); |
64 |
| - } |
65 |
| - foreach (DriveItem drive in Drives) |
66 |
| - { |
67 |
| - if (!App.sideBarItems.Contains(drive)) |
68 |
| - { |
69 |
| - App.sideBarItems.Add(drive); |
70 |
| - } |
71 |
| - } |
72 |
| - |
73 |
| - foreach (INavigationControlItem item in App.sideBarItems.ToList()) |
74 |
| - { |
75 |
| - if (item is DriveItem && !Drives.Contains(item)) |
76 |
| - { |
77 |
| - App.sideBarItems.Remove(item); |
78 |
| - } |
79 |
| - } |
80 |
| - }); |
| 64 | + App.sideBarItems.Add(drive); |
| 65 | + } |
81 | 66 | }
|
82 |
| - catch (Exception) |
| 67 | + foreach (INavigationControlItem item in App.sideBarItems.ToList()) |
83 | 68 | {
|
84 |
| - // UI thread not created yet? |
| 69 | + if (item is DriveItem && !Drives.Contains(item)) |
| 70 | + { |
| 71 | + App.sideBarItems.Remove(item); |
| 72 | + } |
85 | 73 | }
|
86 | 74 | }
|
87 | 75 |
|
|
0 commit comments