Added application session services, along with initial restore and tracker implementations.

This commit is contained in:
2026-08-06 02:11:47 -04:00
parent 75f820ed7b
commit c262ee4caa
13 changed files with 245 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
using Harmonia.WinUI.Session;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
namespace Harmonia.WinUI;
@@ -6,10 +8,17 @@ public sealed partial class MainWindow : Window
{
private const string ApplicationTitle = "Harmonia";
public MainWindow()
private readonly ISessionService _sessionService;
private bool _isSaved;
public MainWindow(ISessionService sessionService)
{
_sessionService = sessionService;
InitializeComponent();
InitializeTitleBar();
InitializeWindowState();
}
private void InitializeTitleBar()
@@ -18,4 +27,39 @@ public sealed partial class MainWindow : Window
ExtendsContentIntoTitleBar = true;
SetTitleBar(AppTitleBar);
}
private void InitializeWindowState()
{
if (AppWindow.Presenter is OverlappedPresenter presenter && _sessionService.Session.Window.IsMaximized)
{
presenter.Maximize();
}
AppWindow.Changed += OnAppWindowChanged;
}
private void OnAppWindowChanged(AppWindow sender, AppWindowChangedEventArgs args)
{
if (sender.Presenter is not OverlappedPresenter presenter)
return;
// Ignore the minimized state so a minimize-then-close doesn't lose the maximized flag.
if (presenter.State is OverlappedPresenterState.Minimized)
return;
_sessionService.Session.Window.IsMaximized = presenter.State == OverlappedPresenterState.Maximized;
}
private async void OnMainWindowClosed(object sender, WindowEventArgs args)
{
if (_isSaved)
return;
args.Handled = true;
await _sessionService.SaveAsync();
_isSaved = true;
Close();
}
}