Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Use TaskCompletionSource for splash screen loading #13038

Merged
merged 5 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public partial class App : Application
private static bool ShowErrorNotification = false;
public static string OutputPath { get; set; }
public static CommandBarFlyout? LastOpenedFlyout { get; set; }
public static bool IsSplashScreenLoading { get; set; }
public static TaskCompletionSource IsSplashScreenLoading { get; set; }
gave92 marked this conversation as resolved.
Show resolved Hide resolved

public static StorageHistoryWrapper HistoryWrapper { get; } = new();
public static AppModel AppModel { get; private set; }
Expand Down Expand Up @@ -214,7 +214,7 @@ async Task ActivateAsync()
// Wait for the Window to initialize
await Task.Delay(10);

IsSplashScreenLoading = true;
IsSplashScreenLoading = new TaskCompletionSource();
gave92 marked this conversation as resolved.
Show resolved Hide resolved
MainWindow.Instance.ShowSplashScreen();

// Get AppActivationArguments
Expand All @@ -235,13 +235,7 @@ async Task ActivateAsync()
Logger.LogInformation($"App launched. Launch args type: {appActivationArguments.Data.GetType().Name}");

// Wait for the UI to update
for (var i = 0; i < 50; i++)
{
if (IsSplashScreenLoading)
await Task.Delay(10);
else
break;
}
await IsSplashScreenLoading.Task.WithTimeoutAsync(TimeSpan.FromMilliseconds(500));
gave92 marked this conversation as resolved.
Show resolved Hide resolved

_ = InitializeAppComponentsAsync().ContinueWith(t => Logger.LogWarning(t.Exception, "Error during InitializeAppComponentsAsync()"), TaskContinuationOptions.OnlyOnFaulted);

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Views/SplashScreenPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public SplashScreenPage()

private void Image_ImageOpened(object sender, RoutedEventArgs e)
{
App.IsSplashScreenLoading = false;
App.IsSplashScreenLoading.TrySetResult();
gave92 marked this conversation as resolved.
Show resolved Hide resolved
}

private void Image_ImageFailed(object sender, RoutedEventArgs e)
{
App.IsSplashScreenLoading = false;
App.IsSplashScreenLoading.TrySetResult();
gave92 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}