LoadingPage.xaml.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Microsoft.CmdPal.Core.ViewModels; 6 using Microsoft.UI.Dispatching; 7 using Microsoft.UI.Xaml.Controls; 8 using Microsoft.UI.Xaml.Navigation; 9 10 namespace Microsoft.CmdPal.UI.Pages; 11 12 /// <summary> 13 /// We use this page to do initialization of our extensions and cache loading to hydrate our ViewModels. 14 /// </summary> 15 public sealed partial class LoadingPage : Page 16 { 17 private readonly DispatcherQueue _queue = DispatcherQueue.GetForCurrentThread(); 18 19 public LoadingPage() 20 { 21 this.InitializeComponent(); 22 } 23 24 protected override void OnNavigatedTo(NavigationEventArgs e) 25 { 26 if (e.Parameter is not AsyncNavigationRequest request) 27 { 28 throw new InvalidOperationException($"Invalid navigation parameter: {nameof(e.Parameter)} must be {nameof(AsyncNavigationRequest)}"); 29 } 30 31 if (request.TargetViewModel is not ShellViewModel shellVM) 32 { 33 throw new InvalidOperationException($"Invalid navigation target: AsyncNavigationRequest.{nameof(AsyncNavigationRequest.TargetViewModel)} must be {nameof(ShellViewModel)}"); 34 } 35 36 // This will load the built-in commands, then navigate to the main page. 37 // Once the mainpage loads, we'll start loading extensions. 38 shellVM.LoadCommand.Execute(null); 39 40 _ = Task.Run(async () => 41 { 42 await shellVM.LoadCommand.ExecutionTask!; 43 44 if (shellVM.LoadCommand.ExecutionTask.Status != TaskStatus.RanToCompletion) 45 { 46 // TODO: Handle failure case 47 } 48 }); 49 50 base.OnNavigatedTo(e); 51 } 52 }