Skip to content

Commit

Permalink
Now quitting properly dependign on platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrcubix committed Oct 1, 2023
1 parent 08ac7d4 commit b594965
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions ColorTiles/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,7 +14,7 @@ public MainView()
{
InitializeComponent();

Loaded += (_,_) =>
Loaded += (_, _) =>
{
_window = TopLevel.GetTopLevel(this) as Window;
};
Expand Down Expand Up @@ -54,20 +53,17 @@ protected override void OnDataContextChanged(EventArgs e)
/// </summary>
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<IPlatformQuit>();

if (platformQuit != null)
{

if (DataContext is MainViewModel viewModel)
{
viewModel.Dispose();
}

platformQuit.Quit();
}
}
}

0 comments on commit b594965

Please sign in to comment.