@@ -160,23 +160,39 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
160
160
break ;
161
161
162
162
case IFileActivatedEventArgs fileArgs :
163
- var index = 0 ;
164
- if ( rootFrame . Content is null || rootFrame . Content is SplashScreenPage || ! MainPageViewModel . AppInstances . Any ( ) )
163
+ try
165
164
{
166
- // When the navigation stack isn't restored navigate to the first page,
167
- // configuring the new page by passing required information as a navigation parameter
168
- rootFrame . Navigate ( typeof ( MainPage ) , fileArgs . Files . First ( ) . Path , new SuppressNavigationTransitionInfo ( ) ) ;
169
- index = 1 ;
170
- }
171
- else
172
- {
173
- // Bring to foreground (#14730)
174
- Win32Helper . BringToForegroundEx ( new ( WindowHandle ) ) ;
175
- }
165
+ if ( fileArgs . Files is null || fileArgs . Files . Count == 0 )
166
+ {
167
+ break ;
168
+ }
169
+
170
+ var index = 0 ;
171
+ if ( rootFrame . Content is null || rootFrame . Content is SplashScreenPage || ! MainPageViewModel . AppInstances . Any ( ) )
172
+ {
173
+ // When the navigation stack isn't restored navigate to the first page,
174
+ // configuring the new page by passing required information as a navigation parameter
175
+ rootFrame . Navigate ( typeof ( MainPage ) , fileArgs . Files . First ( ) . Path , new SuppressNavigationTransitionInfo ( ) ) ;
176
+ index = 1 ;
177
+ }
178
+ else
179
+ {
180
+ // Bring to foreground (#14730)
181
+ Win32Helper . BringToForegroundEx ( new ( WindowHandle ) ) ;
182
+ }
176
183
177
- for ( ; index < fileArgs . Files . Count ; index ++ )
184
+ for ( ; index < fileArgs . Files . Count ; index ++ )
185
+ {
186
+ await NavigationHelpers . AddNewTabByPathAsync ( typeof ( ShellPanesPage ) , fileArgs . Files [ index ] . Path , true ) ;
187
+ }
188
+ }
189
+ catch ( Exception ex )
178
190
{
179
- await NavigationHelpers . AddNewTabByPathAsync ( typeof ( ShellPanesPage ) , fileArgs . Files [ index ] . Path , true ) ;
191
+ App . Logger . LogWarning ( ex , "Failed to open files." ) ;
192
+ if ( rootFrame . Content is null || rootFrame . Content is SplashScreenPage || ! MainPageViewModel . AppInstances . Any ( ) )
193
+ rootFrame . Navigate ( typeof ( MainPage ) , null , new SuppressNavigationTransitionInfo ( ) ) ;
194
+ else
195
+ Win32Helper . BringToForegroundEx ( new ( WindowHandle ) ) ;
180
196
}
181
197
break ;
182
198
0 commit comments