-
Notifications
You must be signed in to change notification settings - Fork 7
/
App.xaml.cs
90 lines (76 loc) · 3.08 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using Chat.ContentDialogs;
using System;
using System.Globalization;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
namespace Chat
{
public sealed partial class App : Application
{
public App()
{
InitializeComponent();
Suspending += OnSuspending;
UnhandledException += App_UnhandledException;
}
private async void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
e.Handled = true;
string ExceptionDesc = e.Exception.Message + "\nHRESULT: 0x" + e.Exception.HResult.ToString("X4", new CultureInfo("en-US")) + "\n" + e.Exception.StackTrace + "\n" + e.Exception.Source;
if (e.Exception.InnerException != null)
{
ExceptionDesc += "\n\n" + e.Exception.InnerException.Message + "\nHRESULT: 0x" + e.Exception.InnerException.HResult.ToString("X4", new CultureInfo("en-US")) + "\n" + e.Exception.InnerException.StackTrace + "\n" + e.Exception.InnerException.Source;
}
else
{
ExceptionDesc += "\n\nNo inner exception was thrown";
}
_ = await new UnhandledExceptionContentDialog(ExceptionDesc).ShowAsync();
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
if (Window.Current.Content is not Shell rootShell)
{
rootShell = new Shell();
if (e != null && e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
if (e != null)
{
rootShell.HandleArguments(e);
}
Window.Current.Content = rootShell;
}
if (e != null && e.PrelaunchActivated == false)
{
rootShell.HandleArguments(e);
Window.Current.Activate();
}
}
protected override void OnActivated(IActivatedEventArgs e)
{
if ((e != null && e.Kind == ActivationKind.Protocol) || (e != null && e.Kind == ActivationKind.ToastNotification))
{
if (Window.Current.Content is not Shell rootShell)
{
rootShell = new Shell();
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
Window.Current.Content = rootShell;
}
rootShell.HandleArguments(e);
Window.Current.Activate();
}
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}