From b59496526722401f29cb7cc0183a1443e8dc5714 Mon Sep 17 00:00:00 2001 From: Mrcubix Date: Sun, 1 Oct 2023 05:12:23 +0200 Subject: [PATCH] Now quitting properly dependign on platforms --- ColorTiles/Views/MainView.axaml.cs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/ColorTiles/Views/MainView.axaml.cs b/ColorTiles/Views/MainView.axaml.cs index 160365e..b117a73 100644 --- a/ColorTiles/Views/MainView.axaml.cs +++ b/ColorTiles/Views/MainView.axaml.cs @@ -1,9 +1,8 @@ using System; -using Avalonia; using Avalonia.Controls; -using Avalonia.Controls.ApplicationLifetimes; +using ColorTiles.Interfaces; using ColorTiles.ViewModels; -using ColorTiles.Views.Controls; +using Splat; namespace ColorTiles.Views; @@ -15,7 +14,7 @@ public MainView() { InitializeComponent(); - Loaded += (_,_) => + Loaded += (_, _) => { _window = TopLevel.GetTopLevel(this) as Window; }; @@ -54,20 +53,17 @@ protected override void OnDataContextChanged(EventArgs e) /// private void OnGameOverMenuQuitButtonClicked(object? sender, EventArgs e) { - if (DataContext is MainViewModel viewModel) - { - viewModel.Dispose(); - } - - // TODO: might want to use DI to provide a proper implementation of quitting native to each platforms without classic desktop lifetime - //_window?.Close(); - if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) - { - desktop.Shutdown(); - } - else if (Application.Current?.ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) + // Obtain currently binded IPlatformQuit + var platformQuit = Locator.Current.GetService(); + + if (platformQuit != null) { - + if (DataContext is MainViewModel viewModel) + { + viewModel.Dispose(); + } + + platformQuit.Quit(); } } } \ No newline at end of file