Skip to content

Commit 40da0bc

Browse files
committed
added install status and getoutputs
1 parent 23322a1 commit 40da0bc

File tree

8 files changed

+1791
-1224
lines changed

8 files changed

+1791
-1224
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ dependencies {
9999
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
100100
//noinspection GradleDynamicVersion
101101
implementation "com.facebook.react:react-android:+"
102-
implementation 'com.github.functionland:fula-build-aar:v1.54.13' // From jitpack.io
102+
implementation 'com.github.functionland:fula-build-aar:v1.54.14' // From jitpack.io
103103
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
104104
implementation 'commons-io:commons-io:20030203.000550'
105105
implementation 'commons-codec:commons-codec:1.15'

android/src/main/java/land/fx/fula/FulaModule.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,4 +1802,34 @@ public void showPluginStatus(String pluginName, int lines, Promise promise) {
18021802
});
18031803
}
18041804

1805+
@ReactMethod
1806+
public void getInstallOutput(String pluginName, String params, Promise promise) {
1807+
ThreadUtils.runOnExecutor(() -> {
1808+
Log.d("ReactNative", "getInstallOutput: pluginName = " + pluginName + ", params = " + params);
1809+
try {
1810+
byte[] result = this.fula.getInstallOutput(pluginName, params);
1811+
String resultString = toString(result);
1812+
promise.resolve(resultString);
1813+
} catch (Exception e) {
1814+
Log.d("ReactNative", "ERROR:" + e.getMessage());
1815+
promise.reject(e);
1816+
}
1817+
});
1818+
}
1819+
1820+
@ReactMethod
1821+
public void getInstallStatus(String pluginName, Promise promise) {
1822+
ThreadUtils.runOnExecutor(() -> {
1823+
Log.d("ReactNative", "getInstallStatus: pluginName = " + pluginName);
1824+
try {
1825+
byte[] result = this.fula.getInstallStatus(pluginName);
1826+
String resultString = toString(result);
1827+
promise.resolve(resultString);
1828+
} catch (Exception e) {
1829+
Log.d("ReactNative", "ERROR:" + e.getMessage());
1830+
promise.reject(e);
1831+
}
1832+
});
1833+
}
1834+
18051835
}

example/src/App.tsx

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect } from 'react';
22
import { StyleSheet, ScrollView, View, Button } from 'react-native';
3-
import { installPlugin, listPlugins } from '../../src/protocols/fxblox';
3+
import { installPlugin, listPlugins, getInstallOutput, getInstallStatus } from '../../src/protocols/fxblox';
44

55
import {
66
fula,
@@ -1164,6 +1164,74 @@ const App = () => {
11641164
color={inprogress ? 'green' : 'blue'}
11651165
/>
11661166
</View>
1167+
1168+
<View style={styles.section}>
1169+
<Button
1170+
title={inprogress ? 'Getting...' : 'Test Get Output Plugins'}
1171+
onPress={async () => {
1172+
try {
1173+
if (initComplete) {
1174+
fula.checkConnection().then((r: any) => {
1175+
console.log('connection check');
1176+
console.log(r);
1177+
if (r) {
1178+
console.log(
1179+
'initialization is completed. send getInstallOutput plugin'
1180+
);
1181+
fxblox
1182+
.getInstallOutput('streamr-node', 'contractAddress')
1183+
.then((res: any) => {
1184+
console.log('getInstallOutput plugins received');
1185+
console.log(res);
1186+
})
1187+
.catch((e: any) => {
1188+
console.log('getInstallOutput plugins failed');
1189+
console.log(e);
1190+
});
1191+
}
1192+
});
1193+
} else {
1194+
console.log('wait for init to complete');
1195+
}
1196+
} catch (e) {}
1197+
}}
1198+
color={inprogress ? 'green' : 'blue'}
1199+
/>
1200+
</View>
1201+
1202+
<View style={styles.section}>
1203+
<Button
1204+
title={inprogress ? 'Getting...' : 'Test Get Install Status Plugins'}
1205+
onPress={async () => {
1206+
try {
1207+
if (initComplete) {
1208+
fula.checkConnection().then((r: any) => {
1209+
console.log('connection check');
1210+
console.log(r);
1211+
if (r) {
1212+
console.log(
1213+
'initialization is completed. send getInstallStatus plugin'
1214+
);
1215+
fxblox
1216+
.getInstallStatus('streamr-node')
1217+
.then((res: any) => {
1218+
console.log('getInstallStatus plugins received');
1219+
console.log(res);
1220+
})
1221+
.catch((e: any) => {
1222+
console.log('getInstallStatus plugins failed');
1223+
console.log(e);
1224+
});
1225+
}
1226+
});
1227+
} else {
1228+
console.log('wait for init to complete');
1229+
}
1230+
} catch (e) {}
1231+
}}
1232+
color={inprogress ? 'green' : 'blue'}
1233+
/>
1234+
</View>
11671235
</ScrollView>
11681236
);
11691237
};

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@functionland/react-native-fula",
3-
"version": "1.54.22",
3+
"version": "1.54.23",
44
"description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -64,7 +64,7 @@
6464
"@release-it/conventional-changelog": "^5.0.0",
6565
"@types/jest": "^28.1.2",
6666
"@types/react": "~17.0.21",
67-
"@types/react-native": "0.71.0",
67+
"@types/react-native": "0.73.0",
6868
"commitlint": "^17.0.2",
6969
"del-cli": "^5.0.0",
7070
"eslint": "^8.4.1",
@@ -74,7 +74,7 @@
7474
"pod-install": "^0.1.0",
7575
"prettier": "^2.0.5",
7676
"react": "18.2.0",
77-
"react-native": "0.71.0",
77+
"react-native": "0.73.0",
7878
"react-native-builder-bob": "^0.20.0",
7979
"release-it": "^15.0.0",
8080
"ts-node": "^10.9.1",
@@ -88,7 +88,7 @@
8888
"@babel/core": "^7.0.0-0",
8989
"@babel/preset-env": "^7.1.6",
9090
"react": "*",
91-
"react-native": "0.71.0"
91+
"react-native": "0.73.0"
9292
},
9393
"engines": {
9494
"node": ">= 16.0.0"

src/interfaces/fulaNativeModule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ interface FulaNativeModule {
142142
installPlugin: (pluginName: string, params: string) => Promise<string>;
143143
uninstallPlugin: (pluginName: string) => Promise<string>;
144144
showPluginStatus: (pluginName: string, lines: number) => Promise<string>;
145+
getInstallOutput: (pluginName: string, params: string) => Promise<string>;
146+
getInstallStatus: (pluginName: string) => Promise<string>;
145147
}
146148

147149
const LINKING_ERROR =

src/protocols/fxblox.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,68 @@ export const showPluginStatus = (
344344
});
345345
return res;
346346
};
347+
348+
export const getInstallStatus = (
349+
pluginName: string
350+
): Promise<BType.GetInstallStatusResponse> => {
351+
console.log('getInstallStatus in react-native started');
352+
let res = Fula.getInstallStatus(pluginName)
353+
.then((res1) => {
354+
try {
355+
console.log('res1 received');
356+
console.log(res1);
357+
let jsonRes: BType.GetInstallStatusResponse = JSON.parse(res1);
358+
if (jsonRes.status) {
359+
return jsonRes;
360+
} else {
361+
console.error('Error getting install status:', jsonRes.msg);
362+
throw jsonRes;
363+
}
364+
} catch (e) {
365+
try {
366+
return JSON.parse(res1);
367+
} catch (e1) {
368+
console.error('Error parsing res in getInstallStatus:', e1);
369+
throw e1;
370+
}
371+
}
372+
})
373+
.catch((err) => {
374+
console.error('Error getInstallStatus:', err);
375+
throw err;
376+
});
377+
return res;
378+
};
379+
380+
export const getInstallOutput = (
381+
pluginName: string,
382+
params: string
383+
): Promise<BType.GetInstallOutputResponse> => {
384+
console.log('getInstallOutput in react-native started');
385+
let res = Fula.getInstallOutput(pluginName, params)
386+
.then((res1) => {
387+
try {
388+
console.log('res1 received');
389+
console.log(res1);
390+
let jsonRes: BType.GetInstallOutputResponse = JSON.parse(res1);
391+
if (jsonRes.status) {
392+
return jsonRes;
393+
} else {
394+
console.error('Error getting install output:', jsonRes.msg);
395+
throw jsonRes;
396+
}
397+
} catch (e) {
398+
try {
399+
return JSON.parse(res1);
400+
} catch (e1) {
401+
console.error('Error parsing res in getInstallOutput:', e1);
402+
throw e1;
403+
}
404+
}
405+
})
406+
.catch((err) => {
407+
console.error('Error getInstallOutput:', err);
408+
throw err;
409+
});
410+
return res;
411+
};

src/types/fxblox.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,17 @@ export interface PluginParam {
100100
name: string;
101101
value: string;
102102
}
103+
104+
export interface GetInstallOutputResponse {
105+
status: boolean;
106+
msg:
107+
| string
108+
| {
109+
[key: string]: string;
110+
};
111+
}
112+
113+
export interface GetInstallStatusResponse {
114+
status: boolean;
115+
msg: string;
116+
}

0 commit comments

Comments
 (0)