Skip to content

Commit 8de8377

Browse files
committed
Continued work on reducing async state machines
1 parent ea6331e commit 8de8377

32 files changed

+161
-169
lines changed

src/Files.App/Actions/Content/Archives/CompressIntoSevenZipAction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public CompressIntoSevenZipAction()
2525
context.PropertyChanged += Context_PropertyChanged;
2626
}
2727

28-
public async Task ExecuteAsync()
28+
public Task ExecuteAsync()
2929
{
3030
var (sources, directory, fileName) = ArchiveHelpers.GetCompressDestination(context.ShellPage);
3131

@@ -37,7 +37,7 @@ public async Task ExecuteAsync()
3737
FileFormat = ArchiveFormats.SevenZip,
3838
};
3939

40-
await ArchiveHelpers.CompressArchiveAsync(creator);
40+
return ArchiveHelpers.CompressArchiveAsync(creator);
4141
}
4242

4343
private bool IsContextPageTypeAdaptedToCommand()

src/Files.App/Actions/Content/Archives/CompressIntoZipAction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public CompressIntoZipAction()
2525
context.PropertyChanged += Context_PropertyChanged;
2626
}
2727

28-
public async Task ExecuteAsync()
28+
public Task ExecuteAsync()
2929
{
3030
var (sources, directory, fileName) = ArchiveHelpers.GetCompressDestination(context.ShellPage);
3131

@@ -37,7 +37,7 @@ public async Task ExecuteAsync()
3737
FileFormat = ArchiveFormats.Zip,
3838
};
3939

40-
await ArchiveHelpers.CompressArchiveAsync(creator);
40+
return ArchiveHelpers.CompressArchiveAsync(creator);
4141
}
4242

4343
private bool IsContextPageTypeAdaptedToCommand()

src/Files.App/Actions/Content/Archives/DecompressArchive.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public DecompressArchive()
2727
context.PropertyChanged += Context_PropertyChanged;
2828
}
2929

30-
public async Task ExecuteAsync()
30+
public Task ExecuteAsync()
3131
{
32-
await ArchiveHelpers.DecompressArchive(context.ShellPage);
32+
return ArchiveHelpers.DecompressArchive(context.ShellPage);
3333
}
3434

3535
private bool IsContextPageTypeAdaptedToCommand()

src/Files.App/Actions/Content/Archives/DecompressArchiveHere.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public DecompressArchiveHere()
2424
context.PropertyChanged += Context_PropertyChanged;
2525
}
2626

27-
public async Task ExecuteAsync()
27+
public Task ExecuteAsync()
2828
{
29-
await ArchiveHelpers.DecompressArchiveHere(context.ShellPage);
29+
return ArchiveHelpers.DecompressArchiveHere(context.ShellPage);
3030
}
3131

3232
private bool IsContextPageTypeAdaptedToCommand()

src/Files.App/Actions/Content/Archives/DecompressArchiveToChildFolderAction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public DecompressArchiveToChildFolderAction()
2626
context.PropertyChanged += Context_PropertyChanged;
2727
}
2828

29-
public async Task ExecuteAsync()
29+
public Task ExecuteAsync()
3030
{
31-
await ArchiveHelpers.DecompressArchiveToChildFolder(context.ShellPage);
31+
return ArchiveHelpers.DecompressArchiveToChildFolder(context.ShellPage);
3232
}
3333

3434
private bool IsContextPageTypeAdaptedToCommand()

src/Files.App/Actions/FileSystem/CopyItemAction.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ public CopyItemAction()
2828
context.PropertyChanged += Context_PropertyChanged;
2929
}
3030

31-
public async Task ExecuteAsync()
31+
public Task ExecuteAsync()
3232
{
3333
if (context.ShellPage is not null)
34-
await UIFilesystemHelpers.CopyItem(context.ShellPage);
34+
return UIFilesystemHelpers.CopyItem(context.ShellPage);
35+
36+
return Task.CompletedTask;
3537
}
3638

3739
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)

src/Files.App/Actions/FileSystem/CopyPathAction.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class CopyPathAction : IAction
2121

2222
public HotKey HotKey { get; } = new(Keys.C, KeyModifiers.CtrlShift);
2323

24-
public async Task ExecuteAsync()
24+
public Task ExecuteAsync()
2525
{
2626
if (context.ShellPage?.SlimContentPage is not null)
2727
{
@@ -38,6 +38,8 @@ public async Task ExecuteAsync()
3838
Clipboard.SetContent(data);
3939
Clipboard.Flush();
4040
}
41+
42+
return Task.CompletedTask;
4143
}
4244
}
4345
}

src/Files.App/Actions/FileSystem/CreateShortcutFromDialogAction.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ internal class CreateShortcutFromDialogAction : ObservableObject, IAction
1818

1919
public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconShortcut");
2020

21-
public async Task ExecuteAsync()
21+
public Task ExecuteAsync()
2222
{
2323
if (context.ShellPage is not null)
24-
await UIFilesystemHelpers.CreateShortcutFromDialogAsync(context.ShellPage);
24+
return UIFilesystemHelpers.CreateShortcutFromDialogAsync(context.ShellPage);
25+
26+
return Task.CompletedTask;
2527
}
2628
}
2729
}

src/Files.App/Actions/FileSystem/DeleteItemAction.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public DeleteItemAction()
3535
context.PropertyChanged += Context_PropertyChanged;
3636
}
3737

38-
public async Task ExecuteAsync()
38+
public Task ExecuteAsync()
3939
{
4040
if (context.ShellPage is null || !IsExecutable)
41-
return;
41+
return Task.CompletedTask;
4242

4343
var items = context.SelectedItems.Select(item => StorageHelpers.FromPathAndType(item.ItemPath,
4444
item.PrimaryItemAttribute is StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
4545

46-
await context.ShellPage.FilesystemHelpers.DeleteItemsAsync(items, settings.DeleteConfirmationPolicy, false, true);
47-
await context.ShellPage.FilesystemViewModel.ApplyFilesAndFoldersChangesAsync();
46+
return context.ShellPage.FilesystemHelpers.DeleteItemsAsync(items, settings.DeleteConfirmationPolicy, false, true)
47+
.ContinueWith(async _ => await context.ShellPage.FilesystemViewModel.ApplyFilesAndFoldersChangesAsync());
4848
}
4949

5050
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)

src/Files.App/App.xaml.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ private static Task StartAppCenter()
118118
return Task.CompletedTask;
119119
}
120120

121-
private static async Task InitializeAppComponentsAsync()
121+
private static Task InitializeAppComponentsAsync()
122122
{
123123
var userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
124124
var addItemService = Ioc.Default.GetRequiredService<IAddItemService>();
125125
var preferencesSettingsService = userSettingsService.PreferencesSettingsService;
126126

127127
// Start off a list of tasks we need to run before we can continue startup
128-
await Task.Run(async () =>
128+
return Task.Run(async () =>
129129
{
130130
await Task.WhenAll(
131131
StartAppCenter(),
@@ -145,15 +145,16 @@ await Task.WhenAll(
145145
);
146146

147147
FileTagsHelper.UpdateTagsDb();
148+
}).ContinueWith(async _ =>
149+
{
150+
// Check for required updates
151+
var updateService = Ioc.Default.GetRequiredService<IUpdateService>();
152+
await updateService.CheckForUpdates();
153+
await updateService.DownloadMandatoryUpdates();
154+
await updateService.CheckAndUpdateFilesLauncherAsync();
155+
await updateService.CheckLatestReleaseNotesAsync();
148156
});
149157

150-
// Check for required updates
151-
var updateService = Ioc.Default.GetRequiredService<IUpdateService>();
152-
await updateService.CheckForUpdates();
153-
await updateService.DownloadMandatoryUpdates();
154-
await updateService.CheckAndUpdateFilesLauncherAsync();
155-
await updateService.CheckLatestReleaseNotesAsync();
156-
157158
static async Task OptionalTask(Task task, bool condition)
158159
{
159160
if (condition)

0 commit comments

Comments
 (0)