diff --git a/.gitignore b/.gitignore index 2ae3cc7e6d..f711d9ca09 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ **/target/CACHEDIR.TAG **/target/debug/ **/target/release/ +**/windows/AppPackages/ +**/windows/Generated Files/ +**/windows/obj/ +**/windows/x64/ *.log *.tgz *.xcworkspace/ @@ -23,14 +27,15 @@ /packages/*/*.LICENSE.txt /packages/*/*/rnx-build/ /packages/*/dist/ -/packages/*/ios/build +/packages/*/ios/build/ /packages/*/lib/ -/packages/*/macos/build +/packages/*/macos/build/ /packages/template/CHANGELOG.md /scripts/bin/ /scripts/lib/ Pods/ coverage/ local.properties +msbuild.binlog node_modules/ !**/__fixtures__/**/node_modules/ diff --git a/incubator/@react-native-webapis/battery-status/windows/PropertySheet.props b/incubator/@react-native-webapis/battery-status/windows/PropertySheet.props new file mode 100644 index 0000000000..38a8cd24ae --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/PropertySheet.props @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/incubator/@react-native-webapis/battery-status/windows/RNWBatteryStatus.h b/incubator/@react-native-webapis/battery-status/windows/RNWBatteryStatus.h new file mode 100644 index 0000000000..70cce7f5ca --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/RNWBatteryStatus.h @@ -0,0 +1,59 @@ +#pragma once + +#include + +#include "JSValue.h" +#include "NativeModules.h" + +namespace winrt::ReactNativeBatteryStatus +{ + using winrt::Windows::Devices::Power::Battery; + using winrt::Windows::System::Power::BatteryStatus; + using winrt::Microsoft::ReactNative::JSValue; + using winrt::Microsoft::ReactNative::JSValueObject; + using winrt::Microsoft::ReactNative::ReactContext; + using winrt::Microsoft::ReactNative::ReactPromise; + + REACT_MODULE(RNWBatteryStatus) + struct RNWBatteryStatus + { + REACT_INIT(Initialize) + void Initialize(ReactContext const &reactContext) noexcept + { + m_reactContext = reactContext; + } + + REACT_METHOD(GetStatus, L"getStatus") + void GetStatus(ReactPromise promise) noexcept + { + JSValueObject status; + + // https://learn.microsoft.com/en-us/windows/uwp/devices-sensors/get-battery-info + auto report = Battery::AggregateBattery().GetReport(); + auto const batteryStatus = report.Status(); + if (batteryStatus == BatteryStatus::NotPresent) { + // These are values reported by Chrome/Edge on a desktop machine + status["charging"] = true; + status["chargingTime"] = 0; + status["dischargingTime"] = -1; + status["level"] = 1; + } else { + status["charging"] = batteryStatus == BatteryStatus::Charging; + + // TODO: Actually implement charging/discharging times + status["chargingTime"] = batteryStatus == BatteryStatus::Charging ? -1 : 0; + status["dischargingTime"] = batteryStatus == BatteryStatus::Discharging ? -1 : -1; + + auto const remaining = report.RemainingCapacityInMilliwattHours().GetInt32(); + auto const fullCharge = report.FullChargeCapacityInMilliwattHours().GetInt32(); + status["level"] = static_cast(remaining) / static_cast(fullCharge); + } + + promise.Resolve(JSValue{std::move(status)}); + } + + private: + ReactContext m_reactContext{nullptr}; + }; + +} // namespace winrt::ReactNativeBatteryStatus diff --git a/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.def b/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.def new file mode 100644 index 0000000000..d04a02ea81 --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.def @@ -0,0 +1,3 @@ +EXPORTS +DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE +DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE diff --git a/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.vcxproj b/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.vcxproj new file mode 100644 index 0000000000..b15c98d2ba --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.vcxproj @@ -0,0 +1,142 @@ + + + + + true + true + true + {e9b31ce3-6931-442e-bb6b-0ccf2943b6bd} + ReactNativeBatteryStatus + ReactNativeBatteryStatus + en-US + 17.0 + true + Windows Store + 10.0 + + + $([MSBuild]::GetDirectoryNameOfFileAbove($(SolutionDir), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\ + + + + 10.0.19041.0 + 10.0.17763.0 + + + + + Debug + ARM64 + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM64 + + + Release + Win32 + + + Release + x64 + + + + DynamicLibrary + Unicode + false + + + true + true + + + false + true + false + + + + + + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /bigobj + 4453;28204 + _WINRT_DLL;%(PreprocessorDefinitions) + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + + + + %(AdditionalOptions) /noattributename + + + Console + true + ReactNativeBatteryStatus.def + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + + + ReactPackageProvider.idl + + + + + + + Create + + + ReactPackageProvider.idl + + + + + + + + + + + + + + + + This project references targets in your node_modules\react-native-windows folder that are missing. The missing file is {0}. + + + + + diff --git a/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.vcxproj.filters b/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.vcxproj.filters new file mode 100644 index 0000000000..246e260dbb --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/ReactNativeBatteryStatus.vcxproj.filters @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.cpp b/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.cpp new file mode 100644 index 0000000000..f86e235497 --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.cpp @@ -0,0 +1,18 @@ +#include "pch.h" +#include "ReactPackageProvider.h" +#if __has_include("ReactPackageProvider.g.cpp") +#include "ReactPackageProvider.g.cpp" +#endif + +#include "RNWBatteryStatus.h" + +namespace winrt::ReactNativeBatteryStatus::implementation +{ + using winrt::Microsoft::ReactNative::AddAttributedModules; + using winrt::Microsoft::ReactNative::IReactPackageBuilder; + + void ReactPackageProvider::CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept + { + AddAttributedModules(packageBuilder, false); + } +} // namespace winrt::ReactNativeBatteryStatus::implementation diff --git a/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.h b/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.h new file mode 100644 index 0000000000..48e20f377d --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.h @@ -0,0 +1,21 @@ +#pragma once +#include "ReactPackageProvider.g.h" + +namespace winrt::ReactNativeBatteryStatus::implementation +{ + using winrt::Microsoft::ReactNative::IReactPackageBuilder; + + struct ReactPackageProvider : ReactPackageProviderT + { + ReactPackageProvider() = default; + + void CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept; + }; +} // namespace winrt::ReactNativeBatteryStatus::implementation + +namespace winrt::ReactNativeBatteryStatus::factory_implementation +{ + using winrt::Microsoft::ReactNative::IReactPackageBuilder; + + struct ReactPackageProvider : ReactPackageProviderT {}; +} // namespace winrt::ReactNativeBatteryStatus::factory_implementation diff --git a/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.idl b/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.idl new file mode 100644 index 0000000000..5d0813f56b --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/ReactPackageProvider.idl @@ -0,0 +1,9 @@ +namespace ReactNativeBatteryStatus +{ + [webhosthidden] + [default_interface] + runtimeclass ReactPackageProvider : Microsoft.ReactNative.IReactPackageProvider + { + ReactPackageProvider(); + }; +} diff --git a/incubator/@react-native-webapis/battery-status/windows/pch.cpp b/incubator/@react-native-webapis/battery-status/windows/pch.cpp new file mode 100644 index 0000000000..1d9f38c57d --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/incubator/@react-native-webapis/battery-status/windows/pch.h b/incubator/@react-native-webapis/battery-status/windows/pch.h new file mode 100644 index 0000000000..dd9407c48b --- /dev/null +++ b/incubator/@react-native-webapis/battery-status/windows/pch.h @@ -0,0 +1,14 @@ +#pragma once + +#define NOMINMAX + +#include +#include +#include +#include +#include +#if __has_include() + #include +#endif + +#include diff --git a/packages/test-app/package.json b/packages/test-app/package.json index fb30a49a43..19d73fecb1 100644 --- a/packages/test-app/package.json +++ b/packages/test-app/package.json @@ -21,7 +21,7 @@ "android": "react-native run-android --no-packager --appId com.msft.identity.client.sample.local", "ios": "react-native run-ios --no-packager", "macos": "react-native run-macos --scheme ReactTestApp --no-packager", - "windows": "react-native run-windows --no-packager --sln windows\\SampleCrossApp.sln", + "windows": "react-native run-windows --no-packager --sln windows/SampleCrossApp.sln", "start": "react-native rnx-start" }, "dependencies": {