10
10
#include " TurboModulesProvider.h"
11
11
12
12
#include < future/futureWinRT.h>
13
+ #include < jsinspector-modern/InspectorFlags.h>
13
14
#include < winrt/Windows.Foundation.Collections.h>
14
15
#include " IReactContext.h"
16
+ #include " ReactHost/DebuggerNotifications.h"
15
17
#include " ReactInstanceSettings.h"
16
18
17
19
#ifdef USE_FABRIC
@@ -30,13 +32,86 @@ using namespace xaml::Controls;
30
32
31
33
namespace winrt ::Microsoft::ReactNative::implementation {
32
34
35
+ class FuseboxHostTargetDelegate : public facebook ::react::jsinspector_modern::HostTargetDelegate,
36
+ public std::enable_shared_from_this<FuseboxHostTargetDelegate> {
37
+ public:
38
+ FuseboxHostTargetDelegate (ReactNativeHost *reactNativeHost) : m_reactNativeHost(reactNativeHost) {}
39
+
40
+ void onReload (facebook::react::jsinspector_modern::HostTargetDelegate::PageReloadRequest const &request) override {
41
+ m_reactNativeHost->ReloadInstance ();
42
+ }
43
+
44
+ #ifdef HAS_FUSEBOX_PAUSED_OVERLAY // Remove after syncing past https://github.com/facebook/react-native/pull/44078
45
+ void onSetPausedInDebuggerMessage (
46
+ facebook::react::jsinspector_modern::HostTargetDelegate::OverlaySetPausedInDebuggerMessageRequest const &request)
47
+ override {
48
+ const auto instanceSettings = m_reactNativeHost->InstanceSettings ();
49
+ if (instanceSettings) {
50
+ if (request.message .has_value ()) {
51
+ ::Microsoft::ReactNative::DebuggerNotifications::OnShowDebuggerPausedOverlay (
52
+ instanceSettings.Notifications(), request.message.value(), [weakThis = weak_from_this()]() {
53
+ if (auto strongThis = weakThis.lock ()) {
54
+ strongThis->m_reactNativeHost ->OnDebuggerResume ();
55
+ }
56
+ });
57
+ } else {
58
+ ::Microsoft::ReactNative::DebuggerNotifications::OnHideDebuggerPausedOverlay (instanceSettings.Notifications());
59
+ }
60
+ }
61
+ }
62
+ #endif
63
+
64
+ private:
65
+ ReactNativeHost *m_reactNativeHost;
66
+ };
67
+
33
68
ReactNativeHost::ReactNativeHost () noexcept : m_reactHost{Mso::React::MakeReactHost ()} {
34
69
#if _DEBUG
35
70
facebook::react::InitializeLogging ([](facebook::react::RCTLogLevel /* logLevel*/ , const char *message) {
36
71
std::string str = std::string (" ReactNative:" ) + message;
37
72
OutputDebugStringA (str.c_str ());
38
73
});
39
74
#endif
75
+
76
+ auto &inspectorFlags = facebook::react::jsinspector_modern::InspectorFlags::getInstance ();
77
+ if (inspectorFlags.getEnableModernCDPRegistry () && !m_inspectorPageId.has_value ()) {
78
+ m_inspectorThread = std::make_shared<Mso::DispatchQueue>(Mso::DispatchQueue::MakeLooperQueue ());
79
+ m_inspectorHostDelegate = std::make_shared<FuseboxHostTargetDelegate>(this );
80
+ m_inspectorTarget = facebook::react::jsinspector_modern::HostTarget::create (
81
+ *m_inspectorHostDelegate, [inspectorThread = m_inspectorThread](std::function<void ()> &&callback) {
82
+ inspectorThread->InvokeElsePost ([callback]() { callback (); });
83
+ });
84
+
85
+ std::weak_ptr<facebook::react::jsinspector_modern::HostTarget> weakInspectorTarget = m_inspectorTarget;
86
+ facebook::react::jsinspector_modern::InspectorTargetCapabilities capabilities;
87
+ #ifdef HAS_FUSEBOX_CAPABILITIES // Remove after syncing past https://github.com/facebook/react-native/pull/43689
88
+ capabilities.nativePageReloads = true ;
89
+ capabilities.prefersFuseboxFrontend = true ;
90
+ #endif
91
+ m_inspectorPageId = facebook::react::jsinspector_modern::getInspectorInstance ().addPage (
92
+ " React Native Windows (Experimental)" ,
93
+ /* vm */ " " ,
94
+ [weakInspectorTarget](std::unique_ptr<facebook::react::jsinspector_modern::IRemoteConnection> remote)
95
+ -> std::unique_ptr<facebook::react::jsinspector_modern::ILocalConnection> {
96
+ if (const auto inspectorTarget = weakInspectorTarget.lock ()) {
97
+ facebook::react::jsinspector_modern::HostTarget::SessionMetadata sessionMetadata;
98
+ sessionMetadata.integrationName = " React Native Windows (Host)" ;
99
+ return inspectorTarget->connect (std::move (remote), sessionMetadata);
100
+ }
101
+
102
+ // This can happen if we're about to be dealloc'd. Reject the connection.
103
+ return nullptr ;
104
+ },
105
+ capabilities);
106
+ }
107
+ }
108
+
109
+ ReactNativeHost::~ReactNativeHost () noexcept {
110
+ if (m_inspectorPageId.has_value ()) {
111
+ facebook::react::jsinspector_modern::getInspectorInstance ().removePage (*m_inspectorPageId);
112
+ m_inspectorPageId.reset ();
113
+ m_inspectorTarget.reset ();
114
+ }
40
115
}
41
116
42
117
/* static*/ ReactNative::ReactNativeHost ReactNativeHost::FromContext (
@@ -197,4 +272,10 @@ Mso::React::IReactHost *ReactNativeHost::ReactHost() noexcept {
197
272
return m_reactHost.Get ();
198
273
}
199
274
275
+ #ifdef HAS_FUSEBOX_PAUSED_OVERLAY // Remove after syncing past https://github.com/facebook/react-native/pull/44078
276
+ void ReactNativeHost::OnDebuggerResume () noexcept {
277
+ m_inspectorTarget->sendCommand (facebook::react::jsinspector_modern::HostCommand::DebuggerResume);
278
+ }
279
+ #endif
280
+
200
281
} // namespace winrt::Microsoft::ReactNative::implementation
0 commit comments