From 322a1ba6b1f6fc2e8421b56171d93f733f35b71d Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Sun, 4 Sep 2022 12:19:26 -0700 Subject: [PATCH] Initialise Flipper on module initialisation Summary: ^ This diff brings most things together and can be considered the test platform for RNW. With this, Flipper client gets initialised and started. This means the application connects and is ready for debugging. Reviewed By: antonk52 Differential Revision: D39054912 fbshipit-source-id: 94397f6a72b1e9d9c0f2f3efaf9967be525076cd --- .../ReactNativeFlipper/FlipperModule.h | 37 +++++++++++++++++-- .../FlipperReactDeviceInfo.cpp | 10 ++++- .../FlipperReactDeviceInfo.h | 2 + .../FlipperReactScheduler.h | 2 +- .../ReactNativeFlipper.vcxproj | 12 +++++- .../ReactNativeFlipper.vcxproj.filters | 8 ++++ 6 files changed, 64 insertions(+), 7 deletions(-) diff --git a/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperModule.h b/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperModule.h index ee54fe56d..62a79ced9 100644 --- a/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperModule.h +++ b/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperModule.h @@ -7,22 +7,53 @@ #pragma once -#include -#include #include "JSValue.h" #include "NativeModules.h" +#include +#include +#include +#include "../../../../xplat/Flipper/FlipperClient.h" +#include "../../../../xplat/Flipper/FlipperInitConfig.h" +#include "../../../../xplat/Flipper/FlipperScheduler.h" +#include "../../../../xplat/Flipper/FlipperSocketProvider.h" + using namespace winrt::Microsoft::ReactNative; namespace winrt::ReactNativeFlipper { REACT_MODULE(FlipperModule, L"Flipper") struct FlipperModule { + std::unique_ptr sonarScheduler; + std::unique_ptr connectionScheduler; + REACT_INIT(Initialize) void Initialize(ReactContext const& reactContext) noexcept { m_reactContext = reactContext; - // Initialise flipper, etc. + sonarScheduler = + std::make_unique(); + connectionScheduler = + std::make_unique(); + + facebook::flipper::FlipperReactDeviceInfo deviceInfo; + facebook::flipper::FlipperInitConfig config; + config.deviceData.host = deviceInfo.getHost(); + config.deviceData.os = deviceInfo.getOS(); + config.deviceData.device = deviceInfo.getDevice(); + config.deviceData.deviceId = deviceInfo.getDeviceId(); + config.deviceData.app = deviceInfo.getAppName(); + config.deviceData.appId = deviceInfo.getAppId(); + config.deviceData.privateAppDirectory = deviceInfo.getAppStorageDirectory(); + config.callbackWorker = sonarScheduler.get(); + config.connectionWorker = connectionScheduler.get(); + + facebook::flipper::FlipperClient::init(config); + + facebook::flipper::FlipperSocketProvider::setDefaultProvider( + std::make_unique()); + + facebook::flipper::FlipperClient::instance()->start(); } REACT_METHOD(registerPlugin) diff --git a/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactDeviceInfo.cpp b/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactDeviceInfo.cpp index f30672a12..2054ea45a 100644 --- a/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactDeviceInfo.cpp +++ b/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactDeviceInfo.cpp @@ -9,12 +9,15 @@ #include #include +#include using namespace winrt::Windows::Foundation; namespace facebook { namespace flipper { - +std::string FlipperReactDeviceInfo::getOS() { + return "Windows"; +} std::string FlipperReactDeviceInfo::getDevice() { try { return winrt::to_string( @@ -46,6 +49,11 @@ std::string FlipperReactDeviceInfo::getAppId() { return winrt::to_string( winrt::Windows::ApplicationModel::Package::Current().Id().Name()); } +std::string FlipperReactDeviceInfo::getAppStorageDirectory() { + winrt::Windows::Storage::StorageFolder storageFolder{ + winrt::Windows::Storage::ApplicationData::Current().LocalFolder()}; + return winrt::to_string(storageFolder.Path()); +} } // namespace flipper } // namespace facebook diff --git a/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactDeviceInfo.h b/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactDeviceInfo.h index e1ed2a084..857290b8e 100644 --- a/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactDeviceInfo.h +++ b/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactDeviceInfo.h @@ -14,11 +14,13 @@ namespace flipper { class FlipperReactDeviceInfo { public: + std::string getOS(); std::string getDevice(); std::string getDeviceId(); std::string getHost(); std::string getAppName(); std::string getAppId(); + std::string getAppStorageDirectory(); }; } // namespace flipper diff --git a/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactScheduler.h b/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactScheduler.h index 66dc54978..42548448c 100644 --- a/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactScheduler.h +++ b/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactScheduler.h @@ -17,7 +17,7 @@ using namespace winrt::Microsoft::ReactNative; namespace facebook { namespace flipper { -class FlipperReactScheduler : public Scheduler { +struct FlipperReactScheduler : public Scheduler { FlipperReactScheduler() : dispatcher_(ReactDispatcher::CreateSerialDispatcher()) {} virtual ~FlipperReactScheduler() {} diff --git a/react-native/react-native-flipper/windows/ReactNativeFlipper/ReactNativeFlipper.vcxproj b/react-native/react-native-flipper/windows/ReactNativeFlipper/ReactNativeFlipper.vcxproj index 4f5337560..45b2c4d00 100644 --- a/react-native/react-native-flipper/windows/ReactNativeFlipper/ReactNativeFlipper.vcxproj +++ b/react-native/react-native-flipper/windows/ReactNativeFlipper/ReactNativeFlipper.vcxproj @@ -109,7 +109,7 @@ - _WIN32;_CRT_SECURE_NO_WARNINGS;FOLLY_NO_CONFIG;NOMINMAX;RN_EXPORT=;JSI_EXPORT=;WIN32;_WINDLL;_HAS_AUTO_PTR_ETC;__unused=[[maybe_unused]];FOLLY_MOBILE=1;_USE_MATH_DEFINES;_UNICODE;UNICODE;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;BOOST_ALL_NO_LIB=1;BOOST_ERROR_CODE_HEADER_ONLY;BOOST_NO_RTTI;BOOST_NO_TYPEID;BOOST_SYSTEM_SOURCE;USE_EDGEMODE_JSRT;WIN32_LEAN_AND_MEAN;_DEBUG;_DEBUG;%(PreprocessorDefinitions) + FB_SONARKIT_ENABLED;_WIN32;_CRT_SECURE_NO_WARNINGS;FOLLY_NO_CONFIG;NOMINMAX;RN_EXPORT=;JSI_EXPORT=;WIN32;_WINDLL;_HAS_AUTO_PTR_ETC;__unused=[[maybe_unused]];FOLLY_MOBILE=1;_USE_MATH_DEFINES;_UNICODE;UNICODE;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;BOOST_ALL_NO_LIB=1;BOOST_ERROR_CODE_HEADER_ONLY;BOOST_NO_RTTI;BOOST_NO_TYPEID;BOOST_SYSTEM_SOURCE;USE_EDGEMODE_JSRT;WIN32_LEAN_AND_MEAN;_DEBUG;_DEBUG;%(PreprocessorDefinitions) $(ProjectDir)..\..\node_modules\.fmt\fmt-7.1.3\include;$(ProjectDir)..\..\node_modules\.folly\folly-2021.06.28.00\;$(ProjectDir)..\..\node_modules\react-native-windows\stubs;%(AdditionalIncludeDirectories) $(ProjectDir)..\..\node_modules\.fmt\fmt-7.1.3\include;$(ProjectDir)..\..\node_modules\react-native-windows\stubs;$(ProjectDir)..\..\node_modules\.folly\folly-2021.06.28.00;%(AdditionalIncludeDirectories) @@ -119,7 +119,7 @@ - _WIN32;_CRT_SECURE_NO_WARNINGS;FOLLY_NO_CONFIG;NOMINMAX;RN_EXPORT=;JSI_EXPORT=;WIN32;_WINDLL;_HAS_AUTO_PTR_ETC;__unused=[[maybe_unused]];FOLLY_MOBILE=1;_USE_MATH_DEFINES;_UNICODE;UNICODE;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;BOOST_ALL_NO_LIB=1;BOOST_ERROR_CODE_HEADER_ONLY;BOOST_NO_RTTI;BOOST_NO_TYPEID;BOOST_SYSTEM_SOURCE;USE_EDGEMODE_JSRT;WIN32_LEAN_AND_MEAN;_DEBUG;NDEBUG;%(PreprocessorDefinitions) + FB_SONARKIT_ENABLED;_WIN32;_CRT_SECURE_NO_WARNINGS;FOLLY_NO_CONFIG;NOMINMAX;RN_EXPORT=;JSI_EXPORT=;WIN32;_WINDLL;_HAS_AUTO_PTR_ETC;__unused=[[maybe_unused]];FOLLY_MOBILE=1;_USE_MATH_DEFINES;_UNICODE;UNICODE;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;BOOST_ALL_NO_LIB=1;BOOST_ERROR_CODE_HEADER_ONLY;BOOST_NO_RTTI;BOOST_NO_TYPEID;BOOST_SYSTEM_SOURCE;USE_EDGEMODE_JSRT;WIN32_LEAN_AND_MEAN;_DEBUG;NDEBUG;%(PreprocessorDefinitions) $(ProjectDir)..\..\node_modules\.fmt\fmt-7.1.3\include;$(ProjectDir)..\..\node_modules\.folly\folly-2021.06.28.00\;$(ProjectDir)..\..\node_modules\react-native-windows\stubs;%(AdditionalIncludeDirectories) $(ProjectDir)..\..\node_modules\.fmt\fmt-7.1.3\include;$(ProjectDir)..\..\node_modules\react-native-windows\stubs;$(ProjectDir)..\..\node_modules\.folly\folly-2021.06.28.00;%(AdditionalIncludeDirectories) @@ -152,6 +152,11 @@ + + + + + ReactPackageProvider.idl @@ -169,6 +174,9 @@ + + + Create diff --git a/react-native/react-native-flipper/windows/ReactNativeFlipper/ReactNativeFlipper.vcxproj.filters b/react-native/react-native-flipper/windows/ReactNativeFlipper/ReactNativeFlipper.vcxproj.filters index 80588979f..76eaecce7 100644 --- a/react-native/react-native-flipper/windows/ReactNativeFlipper/ReactNativeFlipper.vcxproj.filters +++ b/react-native/react-native-flipper/windows/ReactNativeFlipper/ReactNativeFlipper.vcxproj.filters @@ -17,6 +17,9 @@ + + + @@ -46,6 +49,11 @@ + + + + +