/
App.xaml.cs
195 lines (173 loc) · 6.81 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using UnityPlayer;
using System.Diagnostics;
using MarkerMetro.Unity.WinIntegration.Logging;
using UnityProject.Config;
using UnityProject.Logging;
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
namespace UnityProject
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
private AppCallbacks appCallbacks;
internal SplashScreen SplashScreen { get; private set; }
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
appCallbacks = new AppCallbacks();
UnhandledException += LogUnhandledException;
// Prevents display to dim while the app is visible:
var displayRequest = new Windows.System.Display.DisplayRequest();
displayRequest.RequestActive();
InitializeExceptionLogger();
#if DEBUG
DebugSettings.EnableFrameRateCounter = true;
#endif
}
void InitializeExceptionLogger()
{
if (AppConfig.Instance.ExceptionLoggingEnabled)
{
var apiKey = AppConfig.Instance.ExceptionLoggingApiKey;
if (!string.IsNullOrEmpty(apiKey))
{
try
{
// swap this out with an IExceptionLogger implementation as required
ExceptionLogger.Initialize(new RaygunExceptionLogger(apiKey));
ExceptionLogger.IsEnabled = AppConfig.Instance.ExceptionLoggingAllowed;
}
catch (Exception ex)
{
Debug.WriteLine("Failed initializing exception logger.");
Debug.WriteLine(ex.Message);
}
}
}
}
void LogUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
else
{
if (ExceptionLogger.IsEnabled)
{
ExceptionLogger.Send(e.Exception);
ExceptionLogger.IsEnabled = AppConfig.Instance.ExceptionLoggingAllowed;
}
}
}
catch (Exception ex)
{
Debug.WriteLine("FAILED to report unhandled exception:");
Debug.WriteLine(ex.ToString());
}
}
/// <summary>
/// Invoked when application is launched through protocol.
/// Read more - http://msdn.microsoft.com/library/windows/apps/br224742
/// </summary>
/// <param name="args"></param>
protected override void OnActivated(IActivatedEventArgs args)
{
string appArgs = "";
switch (args.Kind)
{
case ActivationKind.Protocol:
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
SplashScreen = eventArgs.SplashScreen;
appArgs += string.Format("Uri={0}", eventArgs.Uri.AbsoluteUri);
#if UNITY_WP_8_1
MarkerMetro.Unity.WinIntegration.Facebook.FBNative.MapUri(eventArgs.Uri);
#endif
break;
}
InitializeUnity(appArgs);
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
SplashScreen = args.SplashScreen;
InitializeUnity(args.Arguments);
}
private void InitializeUnity(string args)
{
#if UNITY_WP_8_1
ApplicationView.GetForCurrentView().SuppressSystemOverlays = true;
#pragma warning disable 4014
StatusBar.GetForCurrentView().HideAsync();
#pragma warning restore 4014
#endif
appCallbacks.SetAppArguments(args);
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null && !appCallbacks.IsInitialized())
{
// Initialise Store system
#if QA || DEBUG
MarkerMetro.Unity.WinIntegration.Store.StoreManager.Instance.Initialise(true);
#else
MarkerMetro.Unity.WinIntegration.Store.StoreManager.Instance.Initialise(false);
#endif
rootFrame = new Frame();
Window.Current.Content = rootFrame;
Window.Current.Activate();
rootFrame.Navigate(typeof(MainPage));
AppCallBacksInitialized();
}
Window.Current.Activate();
}
void AppCallBacksInitialized()
{
// wire up dispatcher for plugins
MarkerMetro.Unity.WinLegacy.Dispatcher.InvokeOnAppThread = InvokeOnAppThread;
MarkerMetro.Unity.WinLegacy.Dispatcher.InvokeOnUIThread = InvokeOnUIThread;
MarkerMetro.Unity.WinIntegration.Dispatcher.InvokeOnAppThread = InvokeOnAppThread;
MarkerMetro.Unity.WinIntegration.Dispatcher.InvokeOnUIThread = InvokeOnUIThread;
}
public void InvokeOnAppThread(Action callback)
{
appCallbacks.InvokeOnAppThread(() => callback(), false);
}
public void InvokeOnUIThread(Action callback)
{
appCallbacks.InvokeOnUIThread(() => callback(), false);
}
}
}