Optimierung des Startvorgangs, lazy load, async im thread pool oder während des Startbildschirms vor dem Mainwindow.
CI / build-and-test (push) Canceled after 0s
CI / build-and-test (push) Canceled after 0s
This commit is contained in:
@@ -52,7 +52,7 @@ public class App : Application
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
private static void ContinueStartup(
|
||||
private static async void ContinueStartup(
|
||||
IClassicDesktopStyleApplicationLifetime desktop, SplashWindow splash)
|
||||
{
|
||||
// Verschlüsselte Datenbank (13.3.4): Passwort abfragen, bevor die Datenbank
|
||||
@@ -62,11 +62,10 @@ public class App : Application
|
||||
var promptVm = new DbPasswordPromptViewModel(
|
||||
new DatabaseEncryptionService(), AppBootstrapper.ResolveDbPath());
|
||||
var promptWindow = new DbPasswordPromptWindow { DataContext = promptVm };
|
||||
promptVm.OnUnlocked = password =>
|
||||
promptVm.OnUnlocked = async password =>
|
||||
{
|
||||
AppBootstrapper.DbPassword = password;
|
||||
StartMainApp(desktop, splash);
|
||||
promptWindow.Close();
|
||||
await StartMainAppAsync(desktop, promptWindow);
|
||||
};
|
||||
desktop.MainWindow = promptWindow;
|
||||
promptWindow.Show();
|
||||
@@ -74,10 +73,10 @@ public class App : Application
|
||||
return;
|
||||
}
|
||||
|
||||
StartMainApp(desktop, splash);
|
||||
await StartMainAppAsync(desktop, splash);
|
||||
}
|
||||
|
||||
private static void StartMainApp(
|
||||
private static async Task StartMainAppAsync(
|
||||
IClassicDesktopStyleApplicationLifetime desktop, Window? windowToClose = null)
|
||||
{
|
||||
_serviceProvider = AppBootstrapper.BuildServices();
|
||||
@@ -98,13 +97,16 @@ public class App : Application
|
||||
var mainVm = Services.GetRequiredService<MainWindowViewModel>();
|
||||
WireCallbacks(mainVm);
|
||||
|
||||
// DI-Singletons werden erst beim ersten Auflösen erzeugt. Ohne dieses explizite
|
||||
// Auflösen entstand der Timer des optionalen WebUntis-Abgleichs erst, wenn die
|
||||
// Einstellungen geöffnet oder ein manueller Abruf gestartet wurde. Den Dienst beim
|
||||
// Anwendungsstart aktivieren und wie den Jahresplan sofort einmal abgleichen; danach
|
||||
// übernimmt sein stündlicher Timer.
|
||||
// Beide optionalen Erstabgleiche noch unter dem Splashscreen abschließen. Ihre
|
||||
// CPU-/Datenbankarbeit läuft innerhalb der Dienste im Threadpool; dadurch öffnet das
|
||||
// Hauptfenster mit fertigem Datenstand und friert nicht kurz danach ein. Das Auflösen
|
||||
// aktiviert zugleich die periodischen Timer.
|
||||
var initialPolls = new List<Task>();
|
||||
if (Services.GetService<UntisSyncService>() is { } untisSync)
|
||||
_ = untisSync.PollAsync();
|
||||
initialPolls.Add(untisSync.PollAsync());
|
||||
if (Services.GetService<AnnualPlanSyncService>() is { } annualPlanSync)
|
||||
initialPolls.Add(annualPlanSync.PollAsync());
|
||||
await Task.WhenAll(initialPolls);
|
||||
|
||||
var main = new MainWindow { DataContext = mainVm };
|
||||
main.EnableWindowSizePersistence(Services.GetRequiredService<WindowSettingsService>());
|
||||
|
||||
Reference in New Issue
Block a user