SplashScreen
CI / build-and-test (push) Canceled after 0s

This commit is contained in:
2026-09-01 22:51:50 +02:00
parent 4af83c3e68
commit 1d9521fc60
4 changed files with 59 additions and 21 deletions
+25 -9
View File
@@ -1,7 +1,9 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.Styling;
using Avalonia.Threading;
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
using LehrerApp.Core.Services;
@@ -37,6 +39,21 @@ public class App : Application
ApplyTheme(new AppearanceSettingsService(AppBootstrapper.ResolveAppDataPath()).Load());
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
// Erst den Splashscreen anzeigen und die synchrone Initialisierung in den ersten
// Dispatcher-Durchlauf verschieben, damit das Ladebild vorher gezeichnet wird.
var splash = new SplashWindow();
desktop.MainWindow = splash;
Dispatcher.UIThread.Post(
() => ContinueStartup(desktop, splash),
DispatcherPriority.Background);
}
base.OnFrameworkInitializationCompleted();
}
private static void ContinueStartup(
IClassicDesktopStyleApplicationLifetime desktop, SplashWindow splash)
{
// Verschlüsselte Datenbank (13.3.4): Passwort abfragen, bevor die Datenbank
// (und damit BuildServices, das sie öffnet) angefasst wird.
@@ -48,22 +65,20 @@ public class App : Application
promptVm.OnUnlocked = password =>
{
AppBootstrapper.DbPassword = password;
StartMainApp(desktop, showImmediately: true);
StartMainApp(desktop, splash);
promptWindow.Close();
};
desktop.MainWindow = promptWindow;
}
else
{
StartMainApp(desktop, showImmediately: false);
}
promptWindow.Show();
splash.Close();
return;
}
base.OnFrameworkInitializationCompleted();
StartMainApp(desktop, splash);
}
private static void StartMainApp(
IClassicDesktopStyleApplicationLifetime desktop, bool showImmediately)
IClassicDesktopStyleApplicationLifetime desktop, Window? windowToClose = null)
{
_serviceProvider = AppBootstrapper.BuildServices();
Services = _serviceProvider;
@@ -96,7 +111,8 @@ public class App : Application
if (Services.GetService<SyncEngine>() is { } syncEngine)
main.EnableFinalSync(syncEngine);
desktop.MainWindow = main;
if (showImmediately) main.Show();
main.Show();
windowToClose?.Close();
}
/// <summary>Wechselt die Darstellung sofort, ohne Neustart (12.4) — Avalonia stylt den
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

@@ -0,0 +1,14 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="LehrerApp.Desktop.Views.SplashWindow"
Title="LehrerPlaner Organizer wird geladen"
Width="450" Height="600"
CanResize="False"
ShowInTaskbar="False"
WindowDecorations="None"
WindowStartupLocation="CenterScreen">
<Image Source="/Assets/SplashScreen.png"
Stretch="UniformToFill"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
</Window>
@@ -0,0 +1,8 @@
using Avalonia.Controls;
namespace LehrerApp.Desktop.Views;
public partial class SplashWindow : Window
{
public SplashWindow() => InitializeComponent();
}