Skip to content

Commit

Permalink
added install status and getoutputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Oct 9, 2024
1 parent 23322a1 commit 40da0bc
Show file tree
Hide file tree
Showing 8 changed files with 1,791 additions and 1,224 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ dependencies {
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-android:+"
implementation 'com.github.functionland:fula-build-aar:v1.54.13' // From jitpack.io
implementation 'com.github.functionland:fula-build-aar:v1.54.14' // From jitpack.io
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
implementation 'commons-io:commons-io:20030203.000550'
implementation 'commons-codec:commons-codec:1.15'
Expand Down
30 changes: 30 additions & 0 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1802,4 +1802,34 @@ public void showPluginStatus(String pluginName, int lines, Promise promise) {
});
}

@ReactMethod
public void getInstallOutput(String pluginName, String params, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "getInstallOutput: pluginName = " + pluginName + ", params = " + params);
try {
byte[] result = this.fula.getInstallOutput(pluginName, params);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
}

@ReactMethod
public void getInstallStatus(String pluginName, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "getInstallStatus: pluginName = " + pluginName);
try {
byte[] result = this.fula.getInstallStatus(pluginName);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
}

}
70 changes: 69 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';
import { StyleSheet, ScrollView, View, Button } from 'react-native';
import { installPlugin, listPlugins } from '../../src/protocols/fxblox';
import { installPlugin, listPlugins, getInstallOutput, getInstallStatus } from '../../src/protocols/fxblox';

import {
fula,
Expand Down Expand Up @@ -1164,6 +1164,74 @@ const App = () => {
color={inprogress ? 'green' : 'blue'}
/>
</View>

<View style={styles.section}>
<Button
title={inprogress ? 'Getting...' : 'Test Get Output Plugins'}
onPress={async () => {
try {
if (initComplete) {
fula.checkConnection().then((r: any) => {
console.log('connection check');
console.log(r);
if (r) {
console.log(
'initialization is completed. send getInstallOutput plugin'
);
fxblox
.getInstallOutput('streamr-node', 'contractAddress')
.then((res: any) => {
console.log('getInstallOutput plugins received');
console.log(res);
})
.catch((e: any) => {
console.log('getInstallOutput plugins failed');
console.log(e);
});
}
});
} else {
console.log('wait for init to complete');
}
} catch (e) {}
}}
color={inprogress ? 'green' : 'blue'}
/>
</View>

<View style={styles.section}>
<Button
title={inprogress ? 'Getting...' : 'Test Get Install Status Plugins'}
onPress={async () => {
try {
if (initComplete) {
fula.checkConnection().then((r: any) => {
console.log('connection check');
console.log(r);
if (r) {
console.log(
'initialization is completed. send getInstallStatus plugin'
);
fxblox
.getInstallStatus('streamr-node')
.then((res: any) => {
console.log('getInstallStatus plugins received');
console.log(res);
})
.catch((e: any) => {
console.log('getInstallStatus plugins failed');
console.log(e);
});
}
});
} else {
console.log('wait for init to complete');
}
} catch (e) {}
}}
color={inprogress ? 'green' : 'blue'}
/>
</View>
</ScrollView>
);
};
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@functionland/react-native-fula",
"version": "1.54.22",
"version": "1.54.23",
"description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -64,7 +64,7 @@
"@release-it/conventional-changelog": "^5.0.0",
"@types/jest": "^28.1.2",
"@types/react": "~17.0.21",
"@types/react-native": "0.71.0",
"@types/react-native": "0.73.0",
"commitlint": "^17.0.2",
"del-cli": "^5.0.0",
"eslint": "^8.4.1",
Expand All @@ -74,7 +74,7 @@
"pod-install": "^0.1.0",
"prettier": "^2.0.5",
"react": "18.2.0",
"react-native": "0.71.0",
"react-native": "0.73.0",
"react-native-builder-bob": "^0.20.0",
"release-it": "^15.0.0",
"ts-node": "^10.9.1",
Expand All @@ -88,7 +88,7 @@
"@babel/core": "^7.0.0-0",
"@babel/preset-env": "^7.1.6",
"react": "*",
"react-native": "0.71.0"
"react-native": "0.73.0"
},
"engines": {
"node": ">= 16.0.0"
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ interface FulaNativeModule {
installPlugin: (pluginName: string, params: string) => Promise<string>;
uninstallPlugin: (pluginName: string) => Promise<string>;
showPluginStatus: (pluginName: string, lines: number) => Promise<string>;
getInstallOutput: (pluginName: string, params: string) => Promise<string>;
getInstallStatus: (pluginName: string) => Promise<string>;
}

const LINKING_ERROR =
Expand Down
65 changes: 65 additions & 0 deletions src/protocols/fxblox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,68 @@ export const showPluginStatus = (
});
return res;
};

export const getInstallStatus = (
pluginName: string
): Promise<BType.GetInstallStatusResponse> => {
console.log('getInstallStatus in react-native started');
let res = Fula.getInstallStatus(pluginName)
.then((res1) => {
try {
console.log('res1 received');
console.log(res1);
let jsonRes: BType.GetInstallStatusResponse = JSON.parse(res1);
if (jsonRes.status) {
return jsonRes;
} else {
console.error('Error getting install status:', jsonRes.msg);
throw jsonRes;
}
} catch (e) {
try {
return JSON.parse(res1);
} catch (e1) {
console.error('Error parsing res in getInstallStatus:', e1);
throw e1;
}
}
})
.catch((err) => {
console.error('Error getInstallStatus:', err);
throw err;
});
return res;
};

export const getInstallOutput = (
pluginName: string,
params: string
): Promise<BType.GetInstallOutputResponse> => {
console.log('getInstallOutput in react-native started');
let res = Fula.getInstallOutput(pluginName, params)
.then((res1) => {
try {
console.log('res1 received');
console.log(res1);
let jsonRes: BType.GetInstallOutputResponse = JSON.parse(res1);
if (jsonRes.status) {
return jsonRes;
} else {
console.error('Error getting install output:', jsonRes.msg);
throw jsonRes;
}
} catch (e) {
try {
return JSON.parse(res1);
} catch (e1) {
console.error('Error parsing res in getInstallOutput:', e1);
throw e1;
}
}
})
.catch((err) => {
console.error('Error getInstallOutput:', err);
throw err;
});
return res;
};
14 changes: 14 additions & 0 deletions src/types/fxblox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,17 @@ export interface PluginParam {
name: string;
value: string;
}

export interface GetInstallOutputResponse {
status: boolean;
msg:
| string
| {
[key: string]: string;
};
}

export interface GetInstallStatusResponse {
status: boolean;
msg: string;
}
Loading

0 comments on commit 40da0bc

Please sign in to comment.