From 796ba9b825314b5107b0e3478bc138d336b081ab Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Fri, 21 Jul 2023 23:02:17 +0900 Subject: [PATCH] Code Quality: Reduce splash screen display time for faster startup (#13020) --- src/Files.App/App.xaml.cs | 14 +++++++++++--- src/Files.App/Views/SplashScreenPage.xaml | 2 ++ src/Files.App/Views/SplashScreenPage.xaml.cs | 11 +++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index ba41427fb636..3bbffafd19cb 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -47,6 +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 StorageHistoryWrapper HistoryWrapper { get; } = new(); public static AppModel AppModel { get; private set; } @@ -213,11 +214,9 @@ async Task ActivateAsync() // Wait for the Window to initialize await Task.Delay(10); + IsSplashScreenLoading = true; MainWindow.Instance.ShowSplashScreen(); - // Wait for the UI to update - await Task.Delay(500); - // Get AppActivationArguments var appActivationArguments = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs(); @@ -235,6 +234,15 @@ async Task ActivateAsync() Logger = Ioc.Default.GetRequiredService>(); 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; + } + _ = InitializeAppComponentsAsync().ContinueWith(t => Logger.LogWarning(t.Exception, "Error during InitializeAppComponentsAsync()"), TaskContinuationOptions.OnlyOnFaulted); _ = MainWindow.Instance.InitializeApplication(appActivationArguments.Data); diff --git a/src/Files.App/Views/SplashScreenPage.xaml b/src/Files.App/Views/SplashScreenPage.xaml index a53e3e139f0e..396245525e56 100644 --- a/src/Files.App/Views/SplashScreenPage.xaml +++ b/src/Files.App/Views/SplashScreenPage.xaml @@ -12,6 +12,8 @@