33//#define DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
44
55
6- using CommunityToolkit . WinUI ;
76using electrifier . Activation ;
87using electrifier . Contracts . Services ;
98using electrifier . Models . Configuration . Global ;
10- using electrifier . Models ;
119using electrifier . Services ;
1210using electrifier . ViewModels ;
1311using electrifier . Views ;
14- using Microsoft . AppCenter . Analytics ;
15- using Microsoft . AppCenter . Crashes ;
16- using Microsoft . AppCenter ;
1712using Microsoft . Extensions . DependencyInjection ;
1813using Microsoft . Extensions . Hosting ;
1914using Microsoft . UI . Xaml ;
2015using System . Diagnostics ;
2116using System . Text ;
17+ using Microsoft . UI . Xaml . Controls ;
18+ using WinRT ;
2219
2320namespace electrifier ;
2421
@@ -63,8 +60,6 @@ public App()
6360 {
6461 InitializeComponent ( ) ;
6562
66- //UnhandledException += App_UnhandledException;
67-
6863 Host = Microsoft . Extensions . Hosting . Host .
6964 CreateDefaultBuilder ( ) .
7065 UseContentRoot ( AppContext . BaseDirectory ) .
@@ -77,16 +72,15 @@ public App()
7772 services . AddTransient < IActivationHandler , AppNotificationActivationHandler > ( ) ;
7873
7974 // Services
75+ services . AddSingleton < IActivationService , ActivationService > ( ) ;
8076 services . AddSingleton < IAppNotificationService , AppNotificationService > ( ) ;
8177 services . AddSingleton < ILocalSettingsService , LocalSettingsService > ( ) ;
78+ services . AddSingleton < INavigationService , NavigationService > ( ) ;
79+ services . AddSingleton < IPageService , PageService > ( ) ;
8280 services . AddSingleton < IThemeSelectorService , ThemeSelectorService > ( ) ;
8381 services . AddTransient < INavigationViewService , NavigationViewService > ( ) ;
8482 services . AddTransient < IWebViewService , WebViewService > ( ) ;
8583
86- services . AddSingleton < IActivationService , ActivationService > ( ) ;
87- services . AddSingleton < INavigationService , NavigationService > ( ) ;
88- services . AddSingleton < IPageService , PageService > ( ) ;
89-
9084 // Core Services
9185 services . AddSingleton < IFileService , FileService > ( ) ;
9286
@@ -97,6 +91,8 @@ public App()
9791 services . AddTransient < DevicesViewModel > ( ) ;
9892 services . AddTransient < FileManagerPage > ( ) ;
9993 services . AddTransient < FileManagerViewModel > ( ) ;
94+ services . AddTransient < Microsoft365Page > ( ) ;
95+ services . AddTransient < Microsoft365ViewModel > ( ) ;
10096 services . AddTransient < NetworkDevicesPage > ( ) ;
10197 services . AddTransient < NetworkDevicesViewModel > ( ) ;
10298 services . AddTransient < SettingsPage > ( ) ;
@@ -119,7 +115,7 @@ public App()
119115 GetService < IAppNotificationService > ( ) ?
120116 . Initialize ( ) ;
121117
122- UnhandledException += App_UnhandledException ;
118+ // UnhandledException += App_UnhandledException;
123119 }
124120
125121 //private void App_StartAppCenter()
@@ -128,11 +124,22 @@ public App()
128124 //}
129125
130126
131- private void App_UnhandledException ( object sender , Microsoft . UI . Xaml . UnhandledExceptionEventArgs args )
127+ // private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs args)
128+ // {
129+ // App_UnhandledException(sender, args, false);
130+ // }
131+
132+ protected async override void OnLaunched ( LaunchActivatedEventArgs args )
132133 {
133- App_UnhandledException ( sender , args , false ) ;
134+ base . OnLaunched ( args ) ;
135+
136+ //GetService<IAppNotificationService>()?
137+ // .Show(string.Format("AppNotificationSamplePayload".GetLocalized(), AppContext.BaseDirectory));
138+
139+ await GetService < IActivationService > ( ) ? . ActivateAsync ( args ) ;
134140 }
135141
142+
136143 /// <summary>
137144 /// Log and handle exceptions as appropriate.
138145 ///
@@ -154,43 +161,41 @@ private void App_UnhandledException(
154161 Microsoft . UI . Xaml . UnhandledExceptionEventArgs args ,
155162 bool itIsComplicated )
156163 {
164+ // TODO: Try to make an backup of current configuration and mark as "dirty".
165+ // TODO: Log and handle exceptions as appropriate.
166+
157167 try
158168 {
159169 StringBuilder sb = new ( ) ;
170+ sb . Append ( $ "{ nameof ( App_UnhandledException ) } :") ;
171+ sb . Append ( $ "Sender: { sender . As < string > ( ) } ") ;
172+ sb . Append ( $ "args: { args . As < string > ( ) } ") ;
160173
161- sb . AppendJoin ( "\n " , "Exception happened!" , "line 1" , "line 2" ) ;
162-
163- // TODO: Try to make an backup of current configuration and mark as "dirty".
164- // TODO: Log and handle exceptions as appropriate.
165-
166- //guru?.ThrowGuruMeditation(sender, args);
174+ // TODO: guru?.ThrowGuruMeditation(sender, args);
167175
168176 /*
169-
170- private async void ShowDialog_Click(object sender, RoutedEventArgs e)
171- {
172- ContentDialog dialog = new ContentDialog();
173-
174- // XamlRoot must be set in the case of a ContentDialog running in a Desktop app
175- dialog.XamlRoot = this.XamlRoot;
176- dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style;
177- dialog.Title = "Save your work?";
178- dialog.PrimaryButtonText = "Save";
179- dialog.SecondaryButtonText = "Don't Save";
180- dialog.CloseButtonText = "Cancel";
181- dialog.DefaultButton = ContentDialogButton.Primary;
182- dialog.Content = new ContentDialogContent();
183-
184- var result = await dialog.ShowAsync();
185- }
186-
187- */
188-
189-
177+ private async void ShowDialog_Click(object sender, RoutedEventArgs e)
178+ {
179+ ContentDialog dialog = new ContentDialog();
180+
181+ // XamlRoot must be set in the case of a ContentDialog running in a Desktop app
182+ dialog.XamlRoot = this.XamlRoot;
183+ dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style;
184+ dialog.Title = "Save your work?";
185+ dialog.PrimaryButtonText = "Save";
186+ dialog.SecondaryButtonText = "Don't Save";
187+ dialog.CloseButtonText = "Cancel";
188+ dialog.DefaultButton = ContentDialogButton.Primary;
189+ dialog.Content = new ContentDialogContent();
190+ var result = await dialog.ShowAsync();
191+ }
192+ */
193+
194+
195+ // sb.AppendJoin("\n", "Exception happened!", "line 1", "line 2");
190196 // if (args is not null)
191197 // {
192198 // // TODO: Exception happened!
193- //
194199 // args.Handled = true;
195200 // }
196201 // else
@@ -201,29 +206,34 @@ private async void ShowDialog_Click(object sender, RoutedEventArgs e)
201206 // {
202207 // args?.Handled = true;
203208 // }
204- // }
205209 }
206210 catch ( Exception ex )
207211 {
208212 var dummy = ex . ToString ( ) ;
209-
210-
211213 // TODO: Log inner exception
212214 }
213215 finally
214216 {
215- args . Handled = true ; // TODO: For test purposes only
216- //args.Handled = !itIsComplicated; // TODO
217+ args . Handled = true ; // TODO: For test purposes only
218+ //args.Handled = !itIsComplicated; // TODO
217219 }
218220 }
219221
220- protected async override void OnLaunched ( LaunchActivatedEventArgs args )
222+ private async void ShowDialog_Click ( object sender , RoutedEventArgs e )
221223 {
222- base . OnLaunched ( args ) ;
223-
224- //GetService<IAppNotificationService>()?
225- // .Show(string.Format("AppNotificationSamplePayload".GetLocalized(), AppContext.BaseDirectory));
226-
227- await GetService < IActivationService > ( ) ? . ActivateAsync ( args ) ;
224+ var dialog = new ContentDialog
225+ {
226+ CloseButtonText = "Cancel" ,
227+ DefaultButton = ContentDialogButton . Primary ,
228+ PrimaryButtonText = "Save all changes made." ,
229+ SecondaryButtonText = "Don't save changes. Any progress made will be lost." ,
230+ Style = Application . Current . Resources [ "DefaultContentDialogStyle" ] as Style ,
231+ Title = "Save your work?" ,
232+ } ;
233+
234+ // XamlRoot must be set in the case of a ContentDialog running in a Desktop app
235+ //dialog.XamlRoot = this.XamlRoot;
236+ //dialog.Content = new ContentDialogContent();
237+ _ = await dialog . ShowAsync ( ) ;
228238 }
229239}
0 commit comments