Skip to content

Commit 7ff4753

Browse files
authored
Code Quality: Refactor service initialization (#17529)
1 parent d45ca74 commit 7ff4753

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,26 @@ public static async Task InitializeAppComponentsAsync()
105105

106106
// Start off a list of tasks we need to run before we can continue startup
107107
await Task.WhenAll(
108-
OptionalTaskAsync(CloudDrivesManager.UpdateDrivesAsync(), generalSettingsService.ShowCloudDrivesSection),
109-
App.LibraryManager.UpdateLibrariesAsync(),
110-
OptionalTaskAsync(WSLDistroManager.UpdateDrivesAsync(), generalSettingsService.ShowWslSection),
111-
OptionalTaskAsync(App.FileTagsManager.UpdateFileTagsAsync(), generalSettingsService.ShowFileTagsSection),
112108
App.QuickAccessManager.InitializeAsync()
113109
);
114110

115-
await Task.WhenAll(
116-
jumpListService.InitializeAsync(),
117-
addItemService.InitializeAsync(),
118-
ContextMenu.WarmUpQueryContextMenuAsync()
119-
);
111+
// Start non-critical tasks without waiting for them to complete
112+
_ = Task.Run(async () =>
113+
{
114+
await Task.WhenAll(
115+
OptionalTaskAsync(CloudDrivesManager.UpdateDrivesAsync(), generalSettingsService.ShowCloudDrivesSection),
116+
App.LibraryManager.UpdateLibrariesAsync(),
117+
OptionalTaskAsync(WSLDistroManager.UpdateDrivesAsync(), generalSettingsService.ShowWslSection),
118+
OptionalTaskAsync(App.FileTagsManager.UpdateFileTagsAsync(), generalSettingsService.ShowFileTagsSection),
119+
jumpListService.InitializeAsync(),
120+
addItemService.InitializeAsync(),
121+
ContextMenu.WarmUpQueryContextMenuAsync(),
122+
CheckAppUpdate()
123+
);
124+
});
120125

121126
FileTagsHelper.UpdateTagsDb();
122127

123-
await CheckAppUpdate();
124-
125128
static Task OptionalTaskAsync(Task task, bool condition)
126129
{
127130
if (condition)

src/Files.App/Utils/Cloud/CloudDrivesManager.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ namespace Files.App.Utils.Cloud
1111
public static class CloudDrivesManager
1212
{
1313
private static readonly ILogger _logger = Ioc.Default.GetRequiredService<ILogger<App>>();
14-
1514
private static readonly ICloudDetector _detector = Ioc.Default.GetRequiredService<ICloudDetector>();
16-
1715
public static EventHandler<NotifyCollectionChangedEventArgs> DataChanged;
18-
1916
private static readonly List<DriveItem> _Drives = [];
17+
2018
public static IReadOnlyList<DriveItem> Drives
2119
{
2220
get
@@ -72,6 +70,25 @@ public static async Task UpdateDrivesAsync()
7270
ShowProperties = true,
7371
};
7472

73+
_ = LoadIconAsync(cloudProviderItem, provider);
74+
lock (_Drives)
75+
{
76+
if (_Drives.Any(x => x.Path == cloudProviderItem.Path))
77+
continue;
78+
79+
_Drives.Add(cloudProviderItem);
80+
}
81+
DataChanged?.Invoke(
82+
SectionType.CloudDrives,
83+
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, cloudProviderItem)
84+
);
85+
}
86+
}
87+
88+
private static async Task LoadIconAsync(DriveItem cloudProviderItem, ICloudProvider provider)
89+
{
90+
try
91+
{
7592
var iconData = provider.IconData;
7693

7794
if (iconData is null)
@@ -92,20 +109,11 @@ public static async Task UpdateDrivesAsync()
92109
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async ()
93110
=> cloudProviderItem.Icon = await iconData.ToBitmapAsync());
94111
}
95-
96-
lock (_Drives)
97-
{
98-
if (_Drives.Any(x => x.Path == cloudProviderItem.Path))
99-
continue;
100-
101-
_Drives.Add(cloudProviderItem);
102-
}
103-
104-
DataChanged?.Invoke(
105-
SectionType.CloudDrives,
106-
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, cloudProviderItem)
107-
);
112+
}
113+
catch (Exception ex)
114+
{
115+
_logger?.LogWarning(ex, "Failed to load icon for cloud provider \"{ProviderName}\"", provider.Name);
108116
}
109117
}
110118
}
111-
}
119+
}

0 commit comments

Comments
 (0)