Skip to content

Commit

Permalink
added update plugin, installstatus and installoutputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Oct 9, 2024
1 parent 40da0bc commit ba1b2c2
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 4 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.14' // From jitpack.io
implementation 'com.github.functionland:fula-build-aar:v1.54.15' // 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
15 changes: 15 additions & 0 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1832,4 +1832,19 @@ public void getInstallStatus(String pluginName, Promise promise) {
});
}

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

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

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

<View style={styles.section}>
<Button
title={inprogress ? 'Getting...' : 'Test Update Plugin'}
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 updatePlugin'
);
fxblox
.updatePlugin('streamr-node')
.then((res: any) => {
console.log('updatePlugin received');
console.log(res);
})
.catch((e: any) => {
console.log('updatePlugin failed');
console.log(e);
});
}
});
} else {
console.log('wait for init to complete');
}
} catch (e) {}
}}
color={inprogress ? 'green' : 'blue'}
/>
</View>
</ScrollView>
);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@functionland/react-native-fula",
"version": "1.54.23",
"version": "1.54.24",
"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
1 change: 1 addition & 0 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ interface FulaNativeModule {
showPluginStatus: (pluginName: string, lines: number) => Promise<string>;
getInstallOutput: (pluginName: string, params: string) => Promise<string>;
getInstallStatus: (pluginName: string) => Promise<string>;
updatePlugin: (pluginName: string) => Promise<string>;
}

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

export const updatePlugin = (
pluginName: string
): Promise<BType.UpdatePluginResponse> => {
console.log('updatePlugin in react-native started');
let res = Fula.updatePlugin(pluginName)
.then((res1) => {
try {
console.log('res1 received');
console.log(res1);
let jsonRes: BType.UpdatePluginResponse = JSON.parse(res1);
if (jsonRes.status) {
return jsonRes;
} else {
console.error('Error updating plugin:', jsonRes.msg);
throw jsonRes;
}
} catch (e) {
try {
return JSON.parse(res1);
} catch (e1) {
console.error('Error parsing res in updatePlugin:', e1);
throw e1;
}
}
})
.catch((err) => {
console.error('Error updatePlugin:', err);
throw err;
});
return res;
};
9 changes: 7 additions & 2 deletions src/types/fxblox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,16 @@ export interface GetInstallOutputResponse {
msg:
| string
| {
[key: string]: string;
};
[key: string]: string;
};
}

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

export interface UpdatePluginResponse {
status: boolean;
msg: string;
}

0 comments on commit ba1b2c2

Please sign in to comment.