@@ -5,20 +5,20 @@ import androidx.annotation.NonNull
55import com.facebook.react.bridge.*
66
77internal class FastOpenpgpModule (reactContext : ReactApplicationContext ) :
8- ReactContextBaseJavaModule (reactContext) {
8+ ReactContextBaseJavaModule (reactContext) {
99
1010 val TAG = " [FastOpenPGPModule]"
1111
12- external fun initialize (jsiPtr : Long );
13- external fun destruct ();
14- external fun callJSI (jsiPtr : Long , name : String , payload : ByteArray ): ByteArray ;
15- external fun callNative (name : String , payload : ByteArray ): ByteArray ;
12+ external fun initialize (jsiPtr : Long );
13+ external fun destruct ();
14+ external fun callJSI (jsiPtr : Long , name : String , payload : ByteArray ): ByteArray ;
15+ external fun callNative (name : String , payload : ByteArray ): ByteArray ;
1616
17- companion object {
18- init {
19- System .loadLibrary(" fast-openpgp" )
20- }
17+ companion object {
18+ init {
19+ System .loadLibrary(" fast-openpgp" )
2120 }
21+ }
2222
2323 @ReactMethod
2424 fun callJSI (name : String , payload : ReadableArray , promise : Promise ) {
@@ -61,26 +61,22 @@ internal class FastOpenpgpModule(reactContext: ReactApplicationContext) :
6161 }.start()
6262 }
6363
64- @ReactMethod
65- fun install (promise : Promise ) {
66- Thread {
67- reactApplicationContext.runOnJSQueueThread {
68- Log .d(TAG , " installing" )
69- try {
70- val contextHolder = this .reactApplicationContext.javaScriptContextHolder!! .get()
71- if (contextHolder.toInt() == 0 ) {
72- promise.resolve(false )
73- return @runOnJSQueueThread
74- }
75- initialize(contextHolder)
76- Log .i(TAG , " successfully installed" )
77- promise.resolve(true )
78- } catch (exception: java.lang.Exception ) {
79- Log .e(TAG , " failed to install JSI" , exception)
80- promise.reject(exception)
81- }
64+ @ReactMethod(isBlockingSynchronousMethod = true )
65+ fun install (): Boolean {
66+ Log .d(TAG , " installing" )
67+ try {
68+ val contextHolder = this .reactApplicationContext.javaScriptContextHolder!! .get()
69+ if (contextHolder.toInt() == 0 ) {
70+ Log .d(TAG , " context not available" )
71+ return false
8272 }
83- }.start()
73+ initialize(contextHolder)
74+ Log .i(TAG , " successfully installed" )
75+ return true
76+ } catch (exception: java.lang.Exception ) {
77+ Log .e(TAG , " failed to install JSI" , exception)
78+ return false
79+ }
8480 }
8581
8682 override fun getName (): String {
@@ -91,4 +87,3 @@ internal class FastOpenpgpModule(reactContext: ReactApplicationContext) :
9187 destruct();
9288 }
9389}
94-
0 commit comments