Skip to content

Commit

Permalink
Code Quality: Reduce splash screen display time for faster startup (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu committed Jul 21, 2023
1 parent a1cf0db commit 796ba9b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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();

Expand All @@ -235,6 +234,15 @@ async Task ActivateAsync()
Logger = Ioc.Default.GetRequiredService<ILogger<App>>();
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);
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Views/SplashScreenPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<Image
x:Name="MainSplashScreenImage"
Width="420"
ImageFailed="Image_ImageFailed"
ImageOpened="Image_ImageOpened"
Source="\Assets\AppTiles\Dev\SplashScreen.png" />

<ProgressRing
Expand Down
11 changes: 11 additions & 0 deletions src/Files.App/Views/SplashScreenPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.Views
Expand All @@ -14,5 +15,15 @@ public SplashScreenPage()
{
InitializeComponent();
}

private void Image_ImageOpened(object sender, RoutedEventArgs e)
{
App.IsSplashScreenLoading = false;
}

private void Image_ImageFailed(object sender, RoutedEventArgs e)
{
App.IsSplashScreenLoading = false;
}
}
}

0 comments on commit 796ba9b

Please sign in to comment.