|
| 1 | +// |
| 2 | +// App.xaml.cpp |
| 3 | +// Implementation of the App class. |
| 4 | +// |
| 5 | + |
| 6 | +#include "pch.h" |
| 7 | +#include "MainPage.xaml.h" |
| 8 | + |
| 9 | +using namespace OAuth2Live; |
| 10 | + |
| 11 | +using namespace Platform; |
| 12 | +using namespace Windows::ApplicationModel; |
| 13 | +using namespace Windows::ApplicationModel::Activation; |
| 14 | +using namespace Windows::Foundation; |
| 15 | +using namespace Windows::Foundation::Collections; |
| 16 | +using namespace Windows::UI::Xaml; |
| 17 | +using namespace Windows::UI::Xaml::Controls; |
| 18 | +using namespace Windows::UI::Xaml::Controls::Primitives; |
| 19 | +using namespace Windows::UI::Xaml::Data; |
| 20 | +using namespace Windows::UI::Xaml::Input; |
| 21 | +using namespace Windows::UI::Xaml::Interop; |
| 22 | +using namespace Windows::UI::Xaml::Media; |
| 23 | +using namespace Windows::UI::Xaml::Navigation; |
| 24 | + |
| 25 | +// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227 |
| 26 | + |
| 27 | +/// <summary> |
| 28 | +/// Initializes the singleton application object. This is the first line of authored code |
| 29 | +/// executed, and as such is the logical equivalent of main() or WinMain(). |
| 30 | +/// </summary> |
| 31 | +App::App() |
| 32 | +{ |
| 33 | + InitializeComponent(); |
| 34 | + Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); |
| 35 | +} |
| 36 | + |
| 37 | +/// <summary> |
| 38 | +/// Invoked when the application is launched normally by the end user. Other entry points |
| 39 | +/// will be used when the application is launched to open a specific file, to display |
| 40 | +/// search results, and so forth. |
| 41 | +/// </summary> |
| 42 | +/// <param name="args">Details about the launch request and process.</param> |
| 43 | +void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args) |
| 44 | +{ |
| 45 | + auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content); |
| 46 | + |
| 47 | + // Do not repeat app initialization when the Window already has content, |
| 48 | + // just ensure that the window is active |
| 49 | + if (rootFrame == nullptr) |
| 50 | + { |
| 51 | + // Create a Frame to act as the navigation context and associate it with |
| 52 | + // a SuspensionManager key |
| 53 | + rootFrame = ref new Frame(); |
| 54 | + |
| 55 | + if (args->PreviousExecutionState == ApplicationExecutionState::Terminated) |
| 56 | + { |
| 57 | + // TODO: Restore the saved session state only when appropriate, scheduling the |
| 58 | + // final launch steps after the restore is complete |
| 59 | + } |
| 60 | + |
| 61 | + if (rootFrame->Content == nullptr) |
| 62 | + { |
| 63 | + // When the navigation stack isn't restored navigate to the first page, |
| 64 | + // configuring the new page by passing required information as a navigation |
| 65 | + // parameter |
| 66 | + if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments)) |
| 67 | + { |
| 68 | + throw ref new FailureException("Failed to create initial page"); |
| 69 | + } |
| 70 | + } |
| 71 | + // Place the frame in the current Window |
| 72 | + Window::Current->Content = rootFrame; |
| 73 | + // Ensure the current window is active |
| 74 | + Window::Current->Activate(); |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + if (rootFrame->Content == nullptr) |
| 79 | + { |
| 80 | + // When the navigation stack isn't restored navigate to the first page, |
| 81 | + // configuring the new page by passing required information as a navigation |
| 82 | + // parameter |
| 83 | + if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments)) |
| 84 | + { |
| 85 | + throw ref new FailureException("Failed to create initial page"); |
| 86 | + } |
| 87 | + } |
| 88 | + // Ensure the current window is active |
| 89 | + Window::Current->Activate(); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +/// <summary> |
| 94 | +/// Invoked when application execution is being suspended. Application state is saved |
| 95 | +/// without knowing whether the application will be terminated or resumed with the contents |
| 96 | +/// of memory still intact. |
| 97 | +/// </summary> |
| 98 | +/// <param name="sender">The source of the suspend request.</param> |
| 99 | +/// <param name="e">Details about the suspend request.</param> |
| 100 | +void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e) |
| 101 | +{ |
| 102 | + (void) sender; // Unused parameter |
| 103 | + (void) e; // Unused parameter |
| 104 | + |
| 105 | + //TODO: Save application state and stop any background activity |
| 106 | +} |
0 commit comments