Files
LehrerApp/LehrerApp.Desktop/Views/MainWindow.axaml.cs
T
adminandClaude Sonnet 5 331033db5c feat: Dunkelmodus, Fenstergröße merken, Papierkorb für Löschvorgänge (12.4, 14.3, 14.6)
Dunkelmodus über neuen Einstellungen-Tab "Darstellung" (Systemvorgabe/Hell/Dunkel),
Fenstergröße/Maximiert-Status wird über Sitzungen hinweg gemerkt (bewusst ohne
Fensterposition), und ein generischer Snapshot-basierter Papierkorb (30 Tage) für
Sitzpläne, Noten, Notenschlüssel-Vorlagen, Aufgaben und Zeiteinträge. Details und
bewusste Scope-Entscheidungen (Spaltenbreiten zurückgestellt, Farb-Audit für
Dunkelmodus offen, welche Entitäten der Papierkorb abdeckt) in TODO.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-20 16:26:10 +02:00

79 lines
2.6 KiB
C#

using Avalonia.Controls;
using Avalonia.Input;
using LehrerApp.Desktop.Services;
using LehrerApp.Desktop.ViewModels;
using LehrerApp.Sync;
namespace LehrerApp.Desktop.Views;
public partial class MainWindow : Window
{
private static readonly TimeSpan FinalSyncDelay = TimeSpan.FromMilliseconds(350);
private SyncEngine? _syncEngine;
private bool _finalSyncStarted;
private bool _closeAfterFinalSync;
public MainWindow()
{
InitializeComponent();
PointerMoved += (_, _) => NotifyActivity();
PointerPressed += (_, _) => NotifyActivity();
KeyDown += (_, _) => NotifyActivity();
}
public void EnableFinalSync(SyncEngine syncEngine)
{
_syncEngine = syncEngine;
Closing += OnClosing;
}
/// <summary>Wendet die zuletzt gespeicherte Fenstergröße an und merkt sich die aktuelle beim
/// Schließen (14.6). Eigenständig von <see cref="EnableFinalSync"/> verdrahtet (mehrere
/// Closing-Handler sind unproblematisch) und immer aktiv, auch ohne konfigurierten
/// Sync-Server.</summary>
public void EnableWindowSizePersistence(WindowSettingsService settings)
{
var saved = settings.Load();
Width = saved.Width;
Height = saved.Height;
if (saved.IsMaximized) WindowState = WindowState.Maximized;
Closing += (_, _) =>
{
var current = settings.Load();
settings.Save(new WindowSettings
{
IsMaximized = WindowState == WindowState.Maximized,
// Im maximierten Zustand spiegeln Width/Height die Bildschirmgröße wider, nicht
// die zuletzt genutzte Normalgröße - dann den vorherigen Wert beibehalten statt
// ihn zu überschreiben.
Width = WindowState == WindowState.Normal ? Width : current.Width,
Height = WindowState == WindowState.Normal ? Height : current.Height,
});
};
}
private async void OnClosing(object? sender, WindowClosingEventArgs e)
{
if (_closeAfterFinalSync || _finalSyncStarted || _syncEngine is null)
return;
e.Cancel = true;
_finalSyncStarted = true;
await _syncEngine.SyncBeforeShutdownAsync(FinalSyncDelay);
_closeAfterFinalSync = true;
Close();
}
private void NotifyActivity()
{
if (DataContext is MainWindowViewModel vm) vm.AppLock.NotifyActivity();
}
private void OnLockScreenKeyDown(object? sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && DataContext is MainWindowViewModel vm)
vm.AppLock.UnlockCommand.Execute(null);
}
}