|
1 | 1 | #include "pch.h" |
2 | 2 |
|
3 | 3 | #include "App.h" |
4 | | -#include "MainPage.h" |
| 4 | +#include "ReactPackageProvider.h" |
5 | 5 |
|
6 | | -using namespace winrt; |
7 | | -using namespace Windows::ApplicationModel; |
8 | | -using namespace Windows::ApplicationModel::Activation; |
9 | | -using namespace Windows::Foundation; |
10 | | -using namespace Windows::UI::Xaml; |
11 | | -using namespace Windows::UI::Xaml::Controls; |
12 | | -using namespace Windows::UI::Xaml::Navigation; |
13 | 6 |
|
14 | 7 |
|
15 | | -using namespace TodosFeed; |
16 | | -using namespace TodosFeed::implementation; |
| 8 | +using namespace winrt::TodosFeed; |
| 9 | +using namespace winrt::TodosFeed::implementation; |
17 | 10 |
|
18 | 11 | /// <summary> |
19 | | -/// Initializes the singleton application object. This is the first line of authored code |
20 | | -/// executed, and as such is the logical equivalent of main() or WinMain(). |
| 12 | +/// Initializes the singleton application object. This is the first line of |
| 13 | +/// authored code executed, and as such is the logical equivalent of main() or |
| 14 | +/// WinMain(). |
21 | 15 | /// </summary> |
22 | | -App::App() |
| 16 | +App::App() noexcept |
23 | 17 | { |
24 | | - InitializeComponent(); |
25 | | - Suspending({ this, &App::OnSuspending }); |
26 | | - |
27 | | -#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION |
28 | | - UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e) |
29 | | - { |
30 | | - if (IsDebuggerPresent()) |
31 | | - { |
32 | | - auto errorMessage = e.Message(); |
33 | | - __debugbreak(); |
34 | | - } |
35 | | - }); |
| 18 | + MainComponentName(L"TodosFeed"); |
| 19 | + |
| 20 | +#if BUNDLE |
| 21 | + JavaScriptBundleFile(L"index.windows"); |
| 22 | + InstanceSettings().UseWebDebugger(false); |
| 23 | + InstanceSettings().UseLiveReload(false); |
| 24 | +#else |
| 25 | + JavaScriptMainModuleName(L"index"); |
| 26 | + InstanceSettings().UseWebDebugger(true); |
| 27 | + InstanceSettings().UseLiveReload(true); |
36 | 28 | #endif |
37 | | -} |
38 | | - |
39 | | -/// <summary> |
40 | | -/// Invoked when the application is launched normally by the end user. Other entry points |
41 | | -/// will be used such as when the application is launched to open a specific file. |
42 | | -/// </summary> |
43 | | -/// <param name="e">Details about the launch request and process.</param> |
44 | | -void App::OnLaunched(LaunchActivatedEventArgs const& e) |
45 | | -{ |
46 | | - Frame rootFrame{ nullptr }; |
47 | | - auto content = Window::Current().Content(); |
48 | | - if (content) |
49 | | - { |
50 | | - rootFrame = content.try_as<Frame>(); |
51 | | - } |
52 | | - |
53 | | - // Do not repeat app initialization when the Window already has content, |
54 | | - // just ensure that the window is active |
55 | | - if (rootFrame == nullptr) |
56 | | - { |
57 | | - // Create a Frame to act as the navigation context and associate it with |
58 | | - // a SuspensionManager key |
59 | | - rootFrame = Frame(); |
60 | 29 |
|
61 | | - rootFrame.NavigationFailed({ this, &App::OnNavigationFailed }); |
| 30 | +#if _DEBUG |
| 31 | + InstanceSettings().EnableDeveloperMenu(true); |
| 32 | +#else |
| 33 | + InstanceSettings().EnableDeveloperMenu(false); |
| 34 | +#endif |
62 | 35 |
|
63 | | - if (e.PreviousExecutionState() == ApplicationExecutionState::Terminated) |
64 | | - { |
65 | | - // Restore the saved session state only when appropriate, scheduling the |
66 | | - // final launch steps after the restore is complete |
67 | | - } |
| 36 | + PackageProviders().Append(make<ReactPackageProvider>()); // Includes all modules in this project |
68 | 37 |
|
69 | | - if (e.PrelaunchActivated() == false) |
70 | | - { |
71 | | - if (rootFrame.Content() == nullptr) |
72 | | - { |
73 | | - // When the navigation stack isn't restored navigate to the first page, |
74 | | - // configuring the new page by passing required information as a navigation |
75 | | - // parameter |
76 | | - rootFrame.Navigate(xaml_typename<TodosFeed::MainPage>(), box_value(e.Arguments())); |
77 | | - } |
78 | | - // Place the frame in the current Window |
79 | | - Window::Current().Content(rootFrame); |
80 | | - // Ensure the current window is active |
81 | | - Window::Current().Activate(); |
82 | | - } |
83 | | - } |
84 | | - else |
85 | | - { |
86 | | - if (e.PrelaunchActivated() == false) |
87 | | - { |
88 | | - if (rootFrame.Content() == nullptr) |
89 | | - { |
90 | | - // When the navigation stack isn't restored navigate to the first page, |
91 | | - // configuring the new page by passing required information as a navigation |
92 | | - // parameter |
93 | | - rootFrame.Navigate(xaml_typename<TodosFeed::MainPage>(), box_value(e.Arguments())); |
94 | | - } |
95 | | - // Ensure the current window is active |
96 | | - Window::Current().Activate(); |
97 | | - } |
98 | | - } |
99 | | -} |
100 | | - |
101 | | -/// <summary> |
102 | | -/// Invoked when application execution is being suspended. Application state is saved |
103 | | -/// without knowing whether the application will be terminated or resumed with the contents |
104 | | -/// of memory still intact. |
105 | | -/// </summary> |
106 | | -/// <param name="sender">The source of the suspend request.</param> |
107 | | -/// <param name="e">Details about the suspend request.</param> |
108 | | -void App::OnSuspending([[maybe_unused]] IInspectable const& sender, [[maybe_unused]] SuspendingEventArgs const& e) |
109 | | -{ |
110 | | - // Save application state and stop any background activity |
111 | | -} |
| 38 | + InitializeComponent(); |
112 | 39 |
|
113 | | -/// <summary> |
114 | | -/// Invoked when Navigation to a certain page fails |
115 | | -/// </summary> |
116 | | -/// <param name="sender">The Frame which failed navigation</param> |
117 | | -/// <param name="e">Details about the navigation failure</param> |
118 | | -void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e) |
119 | | -{ |
120 | | - throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name); |
| 40 | + // This works around a cpp/winrt bug with composable/aggregable types tracked |
| 41 | + // by 22116519 |
| 42 | + AddRef(); |
| 43 | + m_inner.as<::IUnknown>()->Release(); |
121 | 44 | } |
122 | 45 |
|
123 | 46 |
|
0 commit comments