Skip to content

Commit 796ba9b

Browse files
authored
Code Quality: Reduce splash screen display time for faster startup (#13020)
1 parent a1cf0db commit 796ba9b

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/Files.App/App.xaml.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public partial class App : Application
4747
private static bool ShowErrorNotification = false;
4848
public static string OutputPath { get; set; }
4949
public static CommandBarFlyout? LastOpenedFlyout { get; set; }
50+
public static bool IsSplashScreenLoading { get; set; }
5051

5152
public static StorageHistoryWrapper HistoryWrapper { get; } = new();
5253
public static AppModel AppModel { get; private set; }
@@ -213,11 +214,9 @@ async Task ActivateAsync()
213214
// Wait for the Window to initialize
214215
await Task.Delay(10);
215216

217+
IsSplashScreenLoading = true;
216218
MainWindow.Instance.ShowSplashScreen();
217219

218-
// Wait for the UI to update
219-
await Task.Delay(500);
220-
221220
// Get AppActivationArguments
222221
var appActivationArguments = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
223222

@@ -235,6 +234,15 @@ async Task ActivateAsync()
235234
Logger = Ioc.Default.GetRequiredService<ILogger<App>>();
236235
Logger.LogInformation($"App launched. Launch args type: {appActivationArguments.Data.GetType().Name}");
237236

237+
// Wait for the UI to update
238+
for (var i = 0; i < 50; i++)
239+
{
240+
if (IsSplashScreenLoading)
241+
await Task.Delay(10);
242+
else
243+
break;
244+
}
245+
238246
_ = InitializeAppComponentsAsync().ContinueWith(t => Logger.LogWarning(t.Exception, "Error during InitializeAppComponentsAsync()"), TaskContinuationOptions.OnlyOnFaulted);
239247

240248
_ = MainWindow.Instance.InitializeApplication(appActivationArguments.Data);

src/Files.App/Views/SplashScreenPage.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<Image
1313
x:Name="MainSplashScreenImage"
1414
Width="420"
15+
ImageFailed="Image_ImageFailed"
16+
ImageOpened="Image_ImageOpened"
1517
Source="\Assets\AppTiles\Dev\SplashScreen.png" />
1618

1719
<ProgressRing

src/Files.App/Views/SplashScreenPage.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Microsoft.UI.Xaml;
45
using Microsoft.UI.Xaml.Controls;
56

67
namespace Files.App.Views
@@ -14,5 +15,15 @@ public SplashScreenPage()
1415
{
1516
InitializeComponent();
1617
}
18+
19+
private void Image_ImageOpened(object sender, RoutedEventArgs e)
20+
{
21+
App.IsSplashScreenLoading = false;
22+
}
23+
24+
private void Image_ImageFailed(object sender, RoutedEventArgs e)
25+
{
26+
App.IsSplashScreenLoading = false;
27+
}
1728
}
1829
}

0 commit comments

Comments
 (0)