diff --git a/android/src/main/java/com/fastopenpgp/FastOpenpgpModule.kt b/android/src/main/java/com/fastopenpgp/FastOpenpgpModule.kt index 0c8dbd0..fcde808 100644 --- a/android/src/main/java/com/fastopenpgp/FastOpenpgpModule.kt +++ b/android/src/main/java/com/fastopenpgp/FastOpenpgpModule.kt @@ -5,20 +5,20 @@ import androidx.annotation.NonNull import com.facebook.react.bridge.* internal class FastOpenpgpModule(reactContext: ReactApplicationContext) : - ReactContextBaseJavaModule(reactContext) { + ReactContextBaseJavaModule(reactContext) { val TAG = "[FastOpenPGPModule]" - external fun initialize(jsiPtr: Long); - external fun destruct(); - external fun callJSI(jsiPtr: Long, name: String, payload: ByteArray): ByteArray; - external fun callNative(name: String, payload: ByteArray): ByteArray; + external fun initialize(jsiPtr: Long); + external fun destruct(); + external fun callJSI(jsiPtr: Long, name: String, payload: ByteArray): ByteArray; + external fun callNative(name: String, payload: ByteArray): ByteArray; - companion object { - init { - System.loadLibrary("fast-openpgp") - } + companion object { + init { + System.loadLibrary("fast-openpgp") } + } @ReactMethod fun callJSI(name: String, payload: ReadableArray, promise: Promise) { @@ -61,26 +61,22 @@ internal class FastOpenpgpModule(reactContext: ReactApplicationContext) : }.start() } - @ReactMethod - fun install(promise: Promise) { - Thread { - reactApplicationContext.runOnJSQueueThread { - Log.d(TAG, "installing") - try { - val contextHolder = this.reactApplicationContext.javaScriptContextHolder!!.get() - if (contextHolder.toInt() == 0) { - promise.resolve(false) - return@runOnJSQueueThread - } - initialize(contextHolder) - Log.i(TAG, "successfully installed") - promise.resolve(true) - } catch (exception: java.lang.Exception) { - Log.e(TAG, "failed to install JSI", exception) - promise.reject(exception) - } + @ReactMethod(isBlockingSynchronousMethod = true) + fun install(): Boolean { + Log.d(TAG, "installing") + try { + val contextHolder = this.reactApplicationContext.javaScriptContextHolder!!.get() + if (contextHolder.toInt() == 0) { + Log.d(TAG, "context not available") + return false } - }.start() + initialize(contextHolder) + Log.i(TAG, "successfully installed") + return true + } catch (exception: java.lang.Exception) { + Log.e(TAG, "failed to install JSI", exception) + return false + } } override fun getName(): String { @@ -91,4 +87,3 @@ internal class FastOpenpgpModule(reactContext: ReactApplicationContext) : destruct(); } } - diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index c14c60a..cdb8939 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -375,7 +375,7 @@ PODS: - React-jsinspector (0.72.6) - React-logger (0.72.6): - glog - - react-native-fast-openpgp (2.6.0): + - react-native-fast-openpgp (2.7.1): - RCT-Folly (= 2021.07.22.00) - React-Core - React-NativeModulesApple (0.72.6): @@ -698,7 +698,7 @@ SPEC CHECKSUMS: React-jsiexecutor: 3bf18ff7cb03cd8dfdce08fbbc0d15058c1d71ae React-jsinspector: 194e32c6aab382d88713ad3dd0025c5f5c4ee072 React-logger: cebf22b6cf43434e471dc561e5911b40ac01d289 - react-native-fast-openpgp: eb8ca17f55e866965515a9e2b0b4a1dfc26a72d6 + react-native-fast-openpgp: 50b906a9d41f1a3c0f0190e755b7fc37060a6b55 React-NativeModulesApple: 02e35e9a51e10c6422f04f5e4076a7c02243fff2 React-perflogger: e3596db7e753f51766bceadc061936ef1472edc3 React-RCTActionSheet: 17ab132c748b4471012abbcdcf5befe860660485 @@ -723,4 +723,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 71caf16b5cb1532cfe3e9f0ca018f42889cbeede -COCOAPODS: 1.13.0 +COCOAPODS: 1.14.3 diff --git a/example/src/App.tsx b/example/src/App.tsx index 2f944f9..6cf543d 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -116,12 +116,8 @@ D4m65Neoc7DBEdvzgK9IUMpwG5N0t+0pfWLhs8AZdMxE7RbP =kbtq -----END PGP PUBLIC KEY BLOCK-----`; +OpenPGP.useJSI = true; const App = () => { - - useEffect(()=>{ - OpenPGP.useJSI = true - },[]) - return ( <> @@ -172,13 +168,8 @@ const App = () => { privateKey={privateKey} passphrase={passphrase} /> - - + + @@ -188,14 +179,13 @@ const App = () => { }; const styles = StyleSheet.create({ - container: { - }, + container: {}, scrollView: { backgroundColor: Colors.lighter, }, body: { backgroundColor: Colors.white, - minHeight: Dimensions.get("screen").height + minHeight: Dimensions.get('screen').height, }, }); diff --git a/ios/FastOpenpgp.mm b/ios/FastOpenpgp.mm index 52d0ce0..238ab4a 100644 --- a/ios/FastOpenpgp.mm +++ b/ios/FastOpenpgp.mm @@ -98,20 +98,21 @@ @implementation FastOpenpgp resolve(result); } -RCT_REMAP_METHOD(install,installWithResolver:(RCTPromiseResolveBlock)resolve - withReject:(RCTPromiseRejectBlock)reject) +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) { RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge; if (!cxxBridge.runtime) { - NSNumber * val = [NSNumber numberWithBool:NO]; - resolve(val); - return; + return @false; } - jsi::Runtime * runtime = (jsi::Runtime *)cxxBridge.runtime; + using namespace facebook; + auto jsiRuntime = (jsi::Runtime *)cxxBridge.runtime; + if (jsiRuntime == nil) { + return @false; + } + auto &runtime = *jsiRuntime; - fastOpenPGP::install(*runtime); - NSNumber * val = [NSNumber numberWithBool:TRUE]; - resolve(val); + fastOpenPGP::install(runtime); + return @true; } + (BOOL)requiresMainQueueSetup { diff --git a/package.json b/package.json index 2f5dde2..c2f7dca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-fast-openpgp", - "version": "2.7.1", + "version": "2.7.2", "description": "library for use openPGP", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/src/index.tsx b/src/index.tsx index 6c1d6ad..43d47b5 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -636,7 +636,7 @@ export default class OpenPGP { let result: BridgeResponse; if (this.useJSI) { if (!this.loaded) { - this.loaded = await FastOpenPGPNativeModules.install(); + this.loaded = FastOpenPGPNativeModules.install(); console.log( this.TAG, `(${name})`, diff --git a/src/types.d.ts b/src/types.d.ts index e91c592..a0ac5f2 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -46,7 +46,7 @@ interface FastOpenPGPNativeModules { /** * this method will install JSI definitions */ - install(): Promise; + install(): boolean; } interface NativeModulesDef {