Skip to content

Commit 1079a3d

Browse files
authored
Streamlined app close method. (#1394)
1 parent f4a703f commit 1079a3d

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

Files/App.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Windows.ApplicationModel.DataTransfer;
2020
using Windows.Storage;
2121
using Windows.UI.Core;
22+
using Windows.UI.ViewManagement;
2223
using Windows.UI.Xaml;
2324
using Windows.UI.Xaml.Controls;
2425
using Windows.UI.Xaml.Media.Animation;
@@ -407,6 +408,11 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
407408
AppSettings?.Dispose();
408409
deferral.Complete();
409410
}
411+
412+
public static async void CloseApp()
413+
{
414+
if (!await ApplicationView.GetForCurrentView().TryConsolidateAsync()) Application.Current.Exit();
415+
}
410416
}
411417

412418
public class WSLDistroItem : INavigationControlItem

Files/Dialogs/ExceptionDialog.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialo
2020
{
2121
if (InstanceTabsView.tabView.TabItems.Count == 1)
2222
{
23-
Application.Current.Exit();
23+
App.CloseApp();
2424
}
2525
else if (InstanceTabsView.tabView.TabItems.Count > 1)
2626
{
@@ -30,7 +30,7 @@ private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialo
3030

3131
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
3232
{
33-
Application.Current.Exit();
33+
App.CloseApp();
3434
}
3535

3636
private void ExpandMoreInfo_Click(object sender, RoutedEventArgs e)

Files/Interacts/Interaction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,11 @@ private async void OpenSelectedItems(bool displayApplicationPicker)
463463
}
464464
}
465465

466-
public async void CloseTab()
466+
public void CloseTab()
467467
{
468468
if (((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.TabItems.Count == 1)
469469
{
470-
await ApplicationView.GetForCurrentView().TryConsolidateAsync();
470+
App.CloseApp();
471471
}
472472
else if (((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.TabItems.Count > 1)
473473
{

Files/Views/InstanceTabsView.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ private void NavigateToNumberedTabKeyboardAccelerator_Invoked(KeyboardAccelerato
425425
args.Handled = true;
426426
}
427427

428-
private async void CloseSelectedTabKeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
428+
private void CloseSelectedTabKeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
429429
{
430430
var InvokedTabView = (args.Element as TabView);
431431

@@ -434,7 +434,7 @@ private async void CloseSelectedTabKeyboardAccelerator_Invoked(KeyboardAccelerat
434434
{
435435
if (TabStrip.TabItems.Count == 1)
436436
{
437-
await ApplicationView.GetForCurrentView().TryConsolidateAsync();
437+
App.CloseApp();
438438
}
439439
else
440440
{
@@ -500,11 +500,11 @@ public void TabStrip_SelectionChanged(object sender, SelectionChangedEventArgs e
500500
}
501501
}
502502

503-
private async void TabStrip_TabCloseRequested(Microsoft.UI.Xaml.Controls.TabView sender, Microsoft.UI.Xaml.Controls.TabViewTabCloseRequestedEventArgs args)
503+
private void TabStrip_TabCloseRequested(Microsoft.UI.Xaml.Controls.TabView sender, Microsoft.UI.Xaml.Controls.TabViewTabCloseRequestedEventArgs args)
504504
{
505505
if (TabStrip.TabItems.Count == 1)
506506
{
507-
await ApplicationView.GetForCurrentView().TryConsolidateAsync();
507+
App.CloseApp();
508508
}
509509
else if (TabStrip.TabItems.Count > 1)
510510
{

0 commit comments

Comments
 (0)