Skip to content

Commit 6189ae5

Browse files
committed
Updates for Windows
1 parent 22855be commit 6189ae5

17 files changed

+71
-69
lines changed

example/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"ios": "react-native run-ios",
88
"start": "react-native start",
99
"pods": "pod-install --quiet",
10-
"windows": "react-native run-windows"
10+
"windows": "react-native run-windows",
11+
"windows:autolink": "react-native autolink-windows --sln \"windows\\ReactNativeStaticServerExample.sln\" --proj \"windows\\ReactNativeStaticServerExample\\ReactNativeStaticServerExample.vcxproj\""
1112
},
1213
"dependencies": {
1314
"@dr.pogodin/react-native-fs": "^2.21.0-alpha.4",
1415
"react": "18.2.0",
1516
"react-native": "0.72.5",
1617
"react-native-webview": "^13.6.2",
17-
"react-native-windows": "0.72.10"
18+
"react-native-windows": "0.72.11"
1819
},
1920
"devDependencies": {
2021
"@babel/core": "^7.23.0",

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"react-native": "src/index",
99
"source": "src/index",
1010
"scripts": {
11+
"codegen-windows": "react-native codegen-windows",
1112
"test": "npm run lint && npm run typecheck",
1213
"typecheck": "tsc --noEmit",
1314
"lint": "eslint \"**/*.{js,ts,tsx}\"",
@@ -47,7 +48,7 @@
4748
"@react-native/eslint-config": "^0.72.2",
4849
"@react-native/metro-config": "^0.72.11",
4950
"@types/jest": "^29.5.5",
50-
"@types/react": "^18.2.25",
51+
"@types/react": "^18.2.26",
5152
"@types/uuid": "^9.0.5",
5253
"del-cli": "^5.1.0",
5354
"eslint": "^8.51.0",
@@ -60,7 +61,7 @@
6061
"react": "18.2.0",
6162
"react-native": "0.72.5",
6263
"react-native-builder-bob": "^0.23.1",
63-
"react-native-windows": "^0.72.10",
64+
"react-native-windows": "^0.72.11",
6465
"typescript": "^5.2.2"
6566
},
6667
"peerDependencies": {
@@ -128,7 +129,8 @@
128129
"type": "modules",
129130
"jsSrcsDir": "src",
130131
"windows": {
131-
"namespace": "ReactNativeStaticServer"
132+
"namespace": "winrt::ReactNativeStaticServer",
133+
"outputDirectory": "windows/ReactNativeStaticServer/codegen"
132134
}
133135
},
134136
"dependencies": {

src/NativeReactNativeStaticServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface Spec extends TurboModule {
2222
getLocalIpAddress(): Promise<string>;
2323

2424
getOpenPort(address: string): Promise<number>;
25-
stop(): Promise<void>;
25+
stop(): Promise<string>;
2626
}
2727

2828
export default TurboModuleRegistry.getEnforcing<Spec>(

windows/ReactNativeStaticServer/Errors.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,3 @@ RNException::RNException(std::string && message) {
99
const char* RNException::what() {
1010
return this->Message.c_str();
1111
}
12-
13-
void RNException::reject(ReactPromise<React::JSValue>& promise) {
14-
promise.Reject(*this);
15-
}

windows/ReactNativeStaticServer/Errors.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,12 @@ class RNException : public std::exception, public ReactError {
1212
RNException(std::string && message);
1313

1414
virtual const char* what();
15-
void reject(ReactPromise<React::JSValue>& promise);
15+
16+
template <typename T>
17+
void reject(ReactPromise<T>& promise);
1618
};
19+
20+
template<typename T>
21+
void RNException::reject(ReactPromise<T>& promise) {
22+
promise.Reject(*this);
23+
}

windows/ReactNativeStaticServer/ReactNativeModule.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using namespace winrt::Windows::Networking::Connectivity;
1414

1515
double activeServerId;
1616
ReactNativeModule* mod;
17-
React::ReactPromise<::React::JSValue>* pendingResult;
17+
React::ReactPromise<std::string>* pendingResult;
1818
Server *server;
1919

2020
// There is no semaphore in C++ STL prior to C++20,
@@ -43,7 +43,7 @@ void OnSignal(std::string signal, std::string details) {
4343
}
4444
if (pendingResult) {
4545
if (signal == CRASHED) RNException("Server crashed").reject(*pendingResult);
46-
else pendingResult->Resolve(NULL);
46+
else pendingResult->Resolve(details);
4747
delete pendingResult;
4848
pendingResult = NULL;
4949
unlock_sem();
@@ -59,7 +59,7 @@ ReactNativeStaticServerSpec_Constants ReactNativeModule::GetConstants() noexcept
5959
return res;
6060
}
6161

62-
void ReactNativeModule::getLocalIpAddress(React::ReactPromise<React::JSValue>&& result) noexcept {
62+
void ReactNativeModule::getLocalIpAddress(React::ReactPromise<std::string>&& result) noexcept {
6363
try {
6464
auto hosts = NetworkInformation::GetHostNames();
6565
for (winrt::Windows::Networking::HostName host: hosts) {
@@ -91,7 +91,7 @@ void ReactNativeModule::getLocalIpAddress(React::ReactPromise<React::JSValue>&&
9191

9292
void ReactNativeModule::getOpenPort(
9393
std::string address,
94-
React::ReactPromise<React::JSValue>&& result
94+
React::ReactPromise<double>&& result
9595
) noexcept {
9696
try {
9797
auto socket = winrt::Windows::Networking::Sockets::StreamSocketListener();
@@ -125,7 +125,7 @@ void ReactNativeModule::start(
125125
double id,
126126
std::string configPath,
127127
std::string errlogPath,
128-
React::ReactPromise<::React::JSValue>&& result
128+
React::ReactPromise<std::string>&& result
129129
) noexcept {
130130
lock_sem();
131131

@@ -143,12 +143,12 @@ void ReactNativeModule::start(
143143

144144
mod = this;
145145
activeServerId = id;
146-
pendingResult = new React::ReactPromise<React::JSValue>(result);
146+
pendingResult = new React::ReactPromise<std::string>(result);
147147
server = new Server(configPath, errlogPath, OnSignal);
148148
server->launch();
149149
}
150150

151-
void ReactNativeModule::stop(React::ReactPromise<React::JSValue>&& result) noexcept {
151+
void ReactNativeModule::stop(React::ReactPromise<std::string>&& result) noexcept {
152152
try {
153153
lock_sem();
154154

@@ -171,7 +171,7 @@ void ReactNativeModule::stop(React::ReactPromise<React::JSValue>&& result) noexc
171171
return;
172172
}
173173

174-
pendingResult = new React::ReactPromise<React::JSValue>(result);
174+
pendingResult = new React::ReactPromise<std::string>(result);
175175
server->shutdown();
176176

177177
// The OnSignal() handler will dispose the server once TERMINATED,

windows/ReactNativeStaticServer/ReactNativeModule.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#pragma once
1+
#pragma once
22

3-
#include "NativeReactNativeStaticServerSpec.g.h"
3+
#include "codegen/NativeReactNativeStaticServerSpec.g.h"
44

55
#include "JSValue.h"
66
#include "NativeModules.h"
@@ -34,19 +34,19 @@ struct ReactNativeModule
3434
void sendEvent(std::string signal, std::string details);
3535

3636
REACT_METHOD(getLocalIpAddress)
37-
void getLocalIpAddress(React::ReactPromise<React::JSValue>&& result) noexcept;
37+
void getLocalIpAddress(React::ReactPromise<std::string>&& result) noexcept;
3838

3939
REACT_METHOD(getOpenPort)
40-
void getOpenPort(std::string address, React::ReactPromise<React::JSValue>&& result) noexcept;
40+
void getOpenPort(std::string address, React::ReactPromise<double>&& result) noexcept;
4141

4242
REACT_METHOD(start)
4343
void start(double id,
4444
std::string configPath,
4545
std::string errlogPath,
46-
React::ReactPromise<::React::JSValue>&& result) noexcept;
46+
React::ReactPromise<std::string>&& result) noexcept;
4747

4848
REACT_METHOD(stop)
49-
void stop(React::ReactPromise<React::JSValue>&& result) noexcept;
49+
void stop(React::ReactPromise<std::string>&& result) noexcept;
5050
};
5151

5252
} // namespace winrt::ReactNativeStaticServer

windows/ReactNativeStaticServer/ReactNativeStaticServer.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
</ClCompile>
110110
</ItemDefinitionGroup>
111111
<ItemGroup>
112+
<ClInclude Include="codegen\NativeReactNativeStaticServerSpec.g.h" />
112113
<ClInclude Include="Errors.h" />
113-
<ClInclude Include="NativeReactNativeStaticServerSpec.g.h" />
114114
<ClInclude Include="ReactPackageProvider.h">
115115
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
116116
</ClInclude>

0 commit comments

Comments
 (0)