69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using System;
|
|
using Avalonia;
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
using Avalonia.Markup.Xaml;
|
|
using Project_Periodensystem.Model;
|
|
using Project_Periodensystem.Persistence;
|
|
|
|
namespace Project_Periodensystem.View
|
|
{
|
|
public partial class App : Application
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
{
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
{
|
|
// Settings laden und Theme setzen
|
|
var settings = DataManager.LoadSettings();
|
|
|
|
// Theme aus Settings setzen
|
|
if (settings.LastTheme == "Light")
|
|
{
|
|
RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Light;
|
|
}
|
|
else
|
|
{
|
|
RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Dark;
|
|
}
|
|
|
|
desktop.MainWindow = new MainWindow();
|
|
Logger.Log($"Application initialized with {settings.LastTheme} theme from settings");
|
|
|
|
// Settings beim Beenden speichern
|
|
desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnMainWindowClose;
|
|
desktop.Exit += OnApplicationExit;
|
|
}
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Speichert Settings beim Beenden der App
|
|
/// </summary>
|
|
private void OnApplicationExit(object? sender, ControlledApplicationLifetimeExitEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var settings = new AppSettings
|
|
{
|
|
LastTheme = RequestedThemeVariant?.ToString() ?? "Dark",
|
|
LastUsed = DateTime.Now,
|
|
PreferredLanguage = "German"
|
|
};
|
|
|
|
DataManager.SaveSettings(settings);
|
|
Logger.Log("Settings beim App-Exit gespeichert");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Log($"EXCEPTION in OnApplicationExit: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|