@idpass/smartscanner-capacitor 0.5.0-beta.9 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ import android.app.Activity
4
4
  import android.content.Intent
5
5
  import androidx.activity.result.ActivityResult
6
6
  import com.getcapacitor.JSObject
7
+ import com.getcapacitor.Logger
7
8
  import com.getcapacitor.Plugin
8
9
  import com.getcapacitor.PluginCall
9
10
  import com.getcapacitor.PluginMethod
@@ -21,45 +22,54 @@ class SmartScannerPlugin : Plugin() {
21
22
 
22
23
  @PluginMethod
23
24
  fun executeScanner(call: PluginCall) {
24
- val action = call.getString("action")
25
- val options: JSONObject = call.getObject("options")
26
- if (action == "START_SCANNER") {
27
- Timber.d("executeScanner %s", action)
28
- val intent = Intent(context, SmartScannerActivity::class.java)
29
- val scannerOptions = Gson().fromJson(options.toString(), ScannerOptions::class.java)
30
- intent.putExtra(SmartScannerActivity.SCANNER_OPTIONS, scannerOptions)
31
- startActivityForResult(call, intent, "requestScannerResult")
32
- } else {
33
- call.reject("\"$action\" is not a recognized action.")
25
+ try {
26
+ val action = call.getString("action")
27
+ val options: JSONObject = call.getObject("options")
28
+ if (action == "START_SCANNER") {
29
+ Timber.d("executeScanner %s", action)
30
+ val intent = Intent(context, SmartScannerActivity::class.java)
31
+ val scannerOptions = Gson().fromJson(options.toString(), ScannerOptions::class.java)
32
+ intent.putExtra(SmartScannerActivity.SCANNER_OPTIONS, scannerOptions)
33
+ startActivityForResult(call, intent, "requestScannerResult")
34
+ } else {
35
+ call.reject("\"$action\" is not a recognized action.")
36
+ }
37
+ } catch (e: Exception) {
38
+ call.reject(e.toString() ,e)
34
39
  }
35
40
  }
36
41
 
37
42
  @ActivityCallback
38
43
  private fun requestScannerResult(call: PluginCall, result: ActivityResult) {
39
- if (result.resultCode == Activity.RESULT_CANCELED) {
40
- Timber.d("SmartScanner: RESULT CANCELLED")
41
- call.reject("Scanning Cancelled.")
42
- } else {
43
- if (result.resultCode == Activity.RESULT_OK) {
44
- val returnedResult = result.data?.getStringExtra(SmartScannerActivity.SCANNER_RESULT)
45
- try {
46
- if (returnedResult != null) {
47
- Timber.d("SmartScanner: RESULT OK -- $returnedResult")
48
- val scannerResult = JSONObject(returnedResult)
49
- val ret = JSObject()
50
- ret.put(SmartScannerActivity.SCANNER_RESULT, scannerResult)
51
- call.resolve(ret)
52
- } else {
53
- Timber.d("SmartScanner: RESULT SCANNING NULL")
54
- call.reject("Scanning result is null.")
44
+ try {
45
+ if (result.resultCode == Activity.RESULT_CANCELED) {
46
+ Timber.d("SmartScanner: RESULT CANCELLED")
47
+ call.reject("Scanning Cancelled.")
48
+ } else {
49
+ if (result.resultCode == Activity.RESULT_OK) {
50
+ val returnedResult = result.data?.getStringExtra(SmartScannerActivity.SCANNER_RESULT)
51
+ try {
52
+ if (returnedResult != null) {
53
+ Timber.d("SmartScanner: RESULT OK -- $returnedResult")
54
+ val scannerResult = JSONObject(returnedResult)
55
+ val ret = JSObject()
56
+ ret.put(SmartScannerActivity.SCANNER_RESULT, scannerResult)
57
+ call.resolve(ret)
58
+ } else {
59
+ Timber.d("SmartScanner: RESULT SCANNING NULL")
60
+ call.reject("Scanning result is null.")
61
+ }
62
+ } catch (e: JSONException) {
63
+ e.printStackTrace()
64
+ call.reject(e.toString() ,e)
55
65
  }
56
- } catch (e: JSONException) {
57
- e.printStackTrace()
66
+ } else {
67
+ Timber.d("SmartScanner: RESULT SCANNING FAILED")
68
+ call.reject("Scanning Failed.")
58
69
  }
59
- } else {
60
- Timber.d("SmartScanner: RESULT SCANNING FAILED")
61
- call.reject("Scanning Failed.")
62
70
  }
71
+ } catch (e: Exception) {
72
+ call.reject(e.toString() ,e)
63
73
  }
64
74
  }
65
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idpass/smartscanner-capacitor",
3
- "version": "0.5.0-beta.9",
3
+ "version": "0.5.0",
4
4
  "description": "Capacitor plugin for the SmartScanner Core library to scan MRZ, NFC and barcodes",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",