From fac83870d4cbba6c7a95a430723da447382c1b49 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Tue, 8 Oct 2024 01:51:24 -0400 Subject: [PATCH] Added Plugin support --- android/build.gradle | 4 +- android/gradle.properties | 3 + .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../main/java/land/fx/fula/FulaModule.java | 110 +- example/src/App.tsx | 105 +- package.json | 8 +- src/interfaces/fulaNativeModule.ts | 7 + src/protocols/fxblox.ts | 147 +++ src/types/fxblox.ts | 61 + yarn.lock | 1155 +++++++++++------ 10 files changed, 1178 insertions(+), 424 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index aeeaf9c..646c4d5 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -98,8 +98,8 @@ dependencies { // For < 0.71, this will be from the local maven repo // 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-native:+" - implementation 'com.github.functionland:fula-build-aar:v1.54.10' // From jitpack.io + implementation "com.facebook.react:react-android:+" + implementation 'com.github.functionland:fula-build-aar:v1.54.13' // 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' diff --git a/android/gradle.properties b/android/gradle.properties index 8e43c24..5248db3 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -3,3 +3,6 @@ Fula_minSdkVersion=26 Fula_targetSdkVersion=33 Fula_compileSdkVersion=33 Fula_ndkversion=26.2.11394342 +android.useAndroidX=true +android.enableJetifier=true +org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 83148f3..6ac0c81 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip org.gradle.java.home=JAVA_HOME zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/android/src/main/java/land/fx/fula/FulaModule.java b/android/src/main/java/land/fx/fula/FulaModule.java index c4f4a24..a0b4f56 100755 --- a/android/src/main/java/land/fx/fula/FulaModule.java +++ b/android/src/main/java/land/fx/fula/FulaModule.java @@ -1181,7 +1181,7 @@ public void setAuth(String peerIdString, boolean allow, Promise promise) { } promise.resolve(false); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1230,7 +1230,7 @@ public void getAccount(Promise promise) { String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1245,7 +1245,7 @@ public void accountFund(String accountString, Promise promise) { String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1262,7 +1262,7 @@ public void assetsBalance(String account, String assetId, String classId, Promis String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1277,7 +1277,7 @@ public void transferToFula(String amount, String wallet, String chain, Promise p String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1292,7 +1292,7 @@ public void checkAccountExists(String accountString, Promise promise) { String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1307,7 +1307,7 @@ public void listPools(Promise promise) { String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1323,7 +1323,7 @@ public void joinPool(String poolID, Promise promise) { String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1339,7 +1339,7 @@ public void cancelPoolJoin(String poolID, Promise promise) { String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1355,7 +1355,7 @@ public void listPoolJoinRequests(String poolIDStr, Promise promise) { String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1371,7 +1371,7 @@ public void leavePool(String poolID, Promise promise) { String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1387,7 +1387,7 @@ public void listAvailableReplicationRequests(String poolIDStr, Promise promise) String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1561,7 +1561,7 @@ public void bloxFreeSpace(Promise promise) { Log.d("ReactNative", "result string="+resultString); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1577,7 +1577,7 @@ public void wifiRemoveall(Promise promise) { Log.d("ReactNative", "result string="+resultString); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1657,7 +1657,7 @@ public void reboot(Promise promise) { Log.d("ReactNative", "result string="+resultString); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1673,7 +1673,7 @@ public void partition(Promise promise) { Log.d("ReactNative", "result string="+resultString); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1689,7 +1689,7 @@ public void eraseBlData(Promise promise) { Log.d("ReactNative", "result string="+resultString); promise.resolve(resultString); } catch (Exception e) { - Log.d("ReactNative", e.getMessage()); + Log.d("ReactNative", "ERROR:" + e.getMessage()); promise.reject(e); } }); @@ -1726,4 +1726,80 @@ public void testData(String identityString, String bloxAddr, Promise promise) { } } + // Plugin Methods + @ReactMethod + public void listPlugins(Promise promise) { + ThreadUtils.runOnExecutor(() -> { + Log.d("ReactNative", "listPlugins"); + try { + byte[] result = this.fula.listPlugins(); + String resultString = toString(result); + promise.resolve(resultString); + } catch (Exception e) { + Log.d("ReactNative", "ERROR:" + e.getMessage()); + promise.reject(e); + } + }); + } + + @ReactMethod + public void listActivePlugins(Promise promise) { + ThreadUtils.runOnExecutor(() -> { + Log.d("ReactNative", "listActivePlugins"); + try { + byte[] result = this.fula.listActivePlugins(); + String resultString = toString(result); + promise.resolve(resultString); + } catch (Exception e) { + Log.d("ReactNative", "ERROR:" + e.getMessage()); + promise.reject(e); + } + }); + } + + @ReactMethod + public void installPlugin(String pluginName, String params, Promise promise) { + ThreadUtils.runOnExecutor(() -> { + Log.d("ReactNative", "installPlugin: pluginName = " + pluginName + ", params = " + params); + try { + byte[] result = this.fula.installPlugin(pluginName, params); + String resultString = toString(result); + promise.resolve(resultString); + } catch (Exception e) { + Log.d("ReactNative", "ERROR:" + e.getMessage()); + promise.reject(e); + } + }); + } + + @ReactMethod + public void uninstallPlugin(String pluginName, Promise promise) { + ThreadUtils.runOnExecutor(() -> { + Log.d("ReactNative", "uninstallPlugin: pluginName = " + pluginName); + try { + byte[] result = this.fula.uninstallPlugin(pluginName); + String resultString = toString(result); + promise.resolve(resultString); + } catch (Exception e) { + Log.d("ReactNative", "ERROR:" + e.getMessage()); + promise.reject(e); + } + }); + } + + @ReactMethod + public void showPluginStatus(String pluginName, int lines, Promise promise) { + ThreadUtils.runOnExecutor(() -> { + Log.d("ReactNative", "showPluginStatus: pluginName = " + pluginName + ", lines = " + lines); + try { + byte[] result = this.fula.showPluginStatus(pluginName, lines); + String resultString = toString(result); + promise.resolve(resultString); + } catch (Exception e) { + Log.d("ReactNative", "ERROR:" + e.getMessage()); + promise.reject(e); + } + }); + } + } diff --git a/example/src/App.tsx b/example/src/App.tsx index 57bb787..34bdb64 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,5 +1,6 @@ import React, { useEffect } from 'react'; import { StyleSheet, ScrollView, View, Button } from 'react-native'; +import { installPlugin, listPlugins } from '../../src/protocols/fxblox'; import { fula, @@ -69,8 +70,8 @@ const App = () => { // const bloxPeerId = '12D3KooWQZBdE5zNUVTE2Aayajyy9cJDmK4bJwMZG52ieHt2f6nb'; //laptop2 //const bloxPeerId = '12D3KooWAN5FaAnC4d1GhAvoYxyUXdrkCGqux1NB6Pr4cZXn813E'; //test aws server - const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/' + bloxPeerId; - //const bloxAddr = '/ip4/192.168.2.14/tcp/40001/p2p/' + bloxPeerId; // /ip4/192.168.2.14/tcp/40001/p2p/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q + // const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/' + bloxPeerId; + const bloxAddr = '/ip4/192.168.2.14/tcp/40001/p2p/' + bloxPeerId; // /ip4/192.168.2.14/tcp/40001/p2p/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q //const bloxAddr = '/dns4/1.pools.test.fula.network/tcp/40001/p2p/12D3KooWHb38UxY8akVGWZBuFtS3NJ7rJUwd36t3cfkoY7EbgNt9'; const initFula = async () => { try { @@ -1063,6 +1064,106 @@ const App = () => { color={inprogress ? 'green' : 'blue'} /> + + +