86 lines
2.9 KiB
C#
86 lines
2.9 KiB
C#
using CommunityToolkit.Mvvm.Messaging;
|
|
using MaterialDesignThemes.Wpf;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System.Windows;
|
|
using System.Windows.Threading;
|
|
|
|
namespace LD_SysInfo;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
[STAThread]
|
|
private static void Main(string[] args)
|
|
{
|
|
// Show splash screen with fade-in effect
|
|
var splash = new SplashScreen("Assets/splash.png");
|
|
splash.Show(false, true); // autoClose=false, topMost=true
|
|
|
|
// Allow 1 second for fade-in to complete
|
|
System.Threading.Thread.Sleep(1000);
|
|
|
|
MainAsync(args, splash).GetAwaiter().GetResult();
|
|
}
|
|
|
|
private static async Task MainAsync(string[] args, SplashScreen splash)
|
|
{
|
|
using IHost host = CreateHostBuilder(args).Build();
|
|
await host.StartAsync().ConfigureAwait(true);
|
|
|
|
App app = new();
|
|
app.InitializeComponent();
|
|
|
|
var mainWindow = host.Services.GetRequiredService<MainWindow>();
|
|
app.MainWindow = mainWindow;
|
|
|
|
// Keep MainWindow hidden until system info loads
|
|
mainWindow.Visibility = Visibility.Hidden;
|
|
|
|
// When system info finishes loading, show MainWindow and close splash
|
|
mainWindow.SystemInfoLoaded += (s, e) =>
|
|
{
|
|
// Use dispatcher to handle UI thread timing
|
|
mainWindow.Dispatcher.BeginInvoke(async () =>
|
|
{
|
|
// Wait 1 second before starting fade-out
|
|
await Task.Delay(1000);
|
|
|
|
// Show the main window
|
|
mainWindow.Visibility = Visibility.Visible;
|
|
|
|
// Close splash with fade-out effect (1 second)
|
|
splash.Close(TimeSpan.FromMilliseconds(1000));
|
|
});
|
|
};
|
|
|
|
app.Run();
|
|
|
|
await host.StopAsync().ConfigureAwait(true);
|
|
}
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureAppConfiguration((hostBuilderContext, configurationBuilder)
|
|
=> configurationBuilder.AddUserSecrets(typeof(App).Assembly))
|
|
.ConfigureServices((hostContext, services) =>
|
|
{
|
|
services.AddSingleton<MainWindow>();
|
|
services.AddSingleton<MainWindowViewModel>();
|
|
|
|
services.AddSingleton<WeakReferenceMessenger>();
|
|
services.AddSingleton<IMessenger, WeakReferenceMessenger>(provider => provider.GetRequiredService<WeakReferenceMessenger>());
|
|
|
|
services.AddSingleton(_ => Current.Dispatcher);
|
|
|
|
services.AddTransient<ISnackbarMessageQueue>(provider =>
|
|
{
|
|
Dispatcher dispatcher = provider.GetRequiredService<Dispatcher>();
|
|
return new SnackbarMessageQueue(TimeSpan.FromSeconds(3.0), dispatcher);
|
|
});
|
|
});
|
|
}
|