Skip to content

Commit

Permalink
Update Capacitor version to 3.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmangubat23 committed Sep 13, 2021
1 parent e46aad3 commit 042fae8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,73 @@ package org.idpass.smartscanner.capacitor

import android.app.Activity
import android.content.Intent
import com.getcapacitor.*
import androidx.activity.result.ActivityResult
import com.getcapacitor.JSObject
import com.getcapacitor.Plugin
import com.getcapacitor.PluginCall
import com.getcapacitor.PluginMethod
import com.getcapacitor.annotation.ActivityCallback
import com.getcapacitor.annotation.CapacitorPlugin
import com.google.gson.Gson
import org.idpass.smartscanner.lib.SmartScannerActivity
import org.idpass.smartscanner.lib.scanner.config.ScannerOptions
import org.json.JSONException
import org.json.JSONObject
import timber.log.Timber

@NativePlugin(requestCodes = [SmartScannerPlugin.REQUEST_OP_SCANNER])
@CapacitorPlugin
class SmartScannerPlugin : Plugin() {

companion object {
const val REQUEST_OP_SCANNER = 1001
const val handleSmartScannerResult = "handleSmartScannerResult"
}

@PluginMethod
fun executeScanner(call: PluginCall) {
val action = call.getString("action")
val options: JSONObject = call.getObject("options")
saveCall(call)
call.setKeepAlive(true)
if (action == "START_SCANNER") {
Timber.d("executeScanner %s", action)
Timber.d("SmartScannerPlugin -- executeScanner $action")
val intent = Intent(context, SmartScannerActivity::class.java)
val scannerOptions = Gson().fromJson(options.toString(), ScannerOptions::class.java)
intent.putExtra(SmartScannerActivity.SCANNER_OPTIONS, scannerOptions)
startActivityForResult(call, intent, REQUEST_OP_SCANNER)
startActivityForResult(call, intent, handleSmartScannerResult)
} else {
call.error("\"$action\" is not a recognized action.")
call.reject("\"$action\" is not a recognized action.")
}
}

override fun handleOnActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.handleOnActivityResult(requestCode, resultCode, data)
val savedCall = savedCall ?: return
if (requestCode == REQUEST_OP_SCANNER) {
@ActivityCallback
fun handleSmartScannerResult(call: PluginCall, result: ActivityResult) {
if (result.resultCode == Activity.RESULT_CANCELED) {
Timber.d("SmartScannerPlugin -- RESULT CANCELLED")
call.reject("Scanning Cancelled.")
} else {
try {
Timber.d("Plugin post SmartScannerActivity resultCode %d", resultCode)
if (resultCode == Activity.RESULT_OK) {
val returnedResult = data?.getStringExtra(SmartScannerActivity.SCANNER_RESULT)
Timber.d("Plugin post SmartScannerActivity result %s", returnedResult)
Timber.d("SmartScannerPlugin -- resultCode ${result.resultCode}")
if (result.resultCode == Activity.RESULT_OK) {
val returnedResult = result.data?.getStringExtra(SmartScannerActivity.SCANNER_RESULT)
try {
Timber.d("SmartScannerPlugin -- result $returnedResult")
if (returnedResult != null) {
val result = JSONObject(returnedResult)
val ret = JSObject()
ret.put(SmartScannerActivity.SCANNER_RESULT, result)
savedCall.success(ret)
val ret = JSONObject(returnedResult)
val scannedResult = JSObject()
scannedResult.put(SmartScannerActivity.SCANNER_RESULT, ret)
call.resolve(scannedResult)
} else {
savedCall.error("Scanning result is null.")
call.reject("Scanning result is null.")
}
} catch (e: JSONException) {
e.printStackTrace()
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Timber.d("Plugin post SmartScannerActivity RESULT CANCELLED")
savedCall.error("Scanning Cancelled.")
} else {
savedCall.error("Scanning Failed.")
call.reject("Scanning Failed.")
}
} catch (exception: Exception) {
Timber.e(exception)
exception.printStackTrace()
}
} else {
savedCall.error("Unknown Request Code!")
}
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@idpass/smartscanner-capacitor",
"version": "0.3.7-beta.3",
"description": "Capacitor plugin for the SmartScanner Core library to scan MRZ and barcodes",
"description": "Capacitor plugin for the SmartScanner Core library to scan MRZ, NFC and barcodes",
"main": "dist/plugin.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
Expand All @@ -17,9 +17,9 @@
"author": "NewLogic",
"license": "Apache-2.0",
"devDependencies": {
"@capacitor/android": "^2.4.2",
"@capacitor/core": "^2.4.1",
"@capacitor/ios": "^2.4.1",
"@capacitor/android": "^3.2.2",
"@capacitor/core": "^3.2.2",
"@capacitor/ios": "^3.2.2",
"@ionic/prettier-config": "^1.0.0",
"@ionic/swiftlint-config": "^1.0.0",
"@rollup/plugin-node-resolve": "^8.1.0",
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@capacitor/android@^2.4.2":
version "2.4.2"
resolved "https://registry.yarnpkg.com/@capacitor/android/-/android-2.4.2.tgz#ddc55bf0ea78214a0a760330a439916093792d00"
integrity sha512-0OpOmsno6yFyN0tOEhE9LkAqQrnTGUxz49+ZdivieI3axFe3CpxbFhcfIsJtr96q9jhkspkYPMqGNZm3gPKjaA==
"@capacitor/android@^3.2.2":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@capacitor/android/-/android-3.2.2.tgz#0847d62d21c4e7007cf0b34fd95965afa22ba619"
integrity sha512-+/qbSZIHPP1VndRUe5c6dgheLV0MgX9CXeUo7el8ODHgVrC2DXKhczgvs+EpTAmvS2VZFxzDeld7AMUmHybTcg==

"@capacitor/core@^2.4.1":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@capacitor/core/-/core-2.4.1.tgz#d47db023d4b98fd62f8f829d2a046d0c1f0e5352"
integrity sha512-/OTDYTztAri04SNC+pIsSiIVG8ryjKkt3kG+aupoiHI1xankLJxGbcw5Z3aVZmhmMmJpk2nda2LC9Kc3Y0bA2w==
"@capacitor/core@^3.2.2":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@capacitor/core/-/core-3.2.2.tgz#5926788920ba9117aa735d2941f5b2bdc4a6889a"
integrity sha512-xY3VyLbF0vSxQmQto6cI1PqP8idbwmfEAeaj248uuSrIYHeMc1L3RS6UN/yNBDPYPeAfNUwBhVqSTCtuZkEIcg==
dependencies:
tslib "^1.9.0"
tslib "^2.1.0"

"@capacitor/ios@^2.4.1":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@capacitor/ios/-/ios-2.4.1.tgz#c65f3d3ae24b50806e60189087efc6703ac96e69"
integrity sha512-Q1PfO67zn2668Gu9OYY2v02TuB20E530HHfe28wrK9X1Jy5jRFl1ZUr3epCkaB4XJQeGqM42oACO+BwURNAW5Q==
"@capacitor/ios@^3.2.2":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@capacitor/ios/-/ios-3.2.2.tgz#0417cf89df23f651c6a1e20a8fb98294a918ce1f"
integrity sha512-Eq17Y+UDHFmYGaZcObvxHAcHw0fF9TCBAg1f5f6qdV8ab3cKKEUB9xMvoCSZAueBfxFARrD18TsZJKoxh2YsLA==

"@ionic/prettier-config@^1.0.0":
version "1.0.1"
Expand Down Expand Up @@ -367,7 +367,7 @@ [email protected]:
integrity sha512-YphTEk4zIpWAHqBriAdjlNnTEcEYQ2xBA8KOH5V7QxggNbxjkeEcKJjNYnQvqEue8+O1TLj7vfL0NVG6x5LGMw==
dependencies:
chevrotain "6.5.0"
lodash "4.17.20"
lodash "4.17.21"

js-tokens@^4.0.0:
version "4.0.0"
Expand Down Expand Up @@ -465,7 +465,7 @@ prettier-plugin-java@^0.8.0:
integrity sha512-G11PMutlfhUjLqmrB0gW9n6hTIvlnXX+lhzgH3Uhc1QSlDQoLBky5lNSRgvdYSDPpSF3DmyYd3/7U3Ez8n0ckg==
dependencies:
java-parser "0.8.2"
lodash "4.17.20"
lodash "4.17.21"
prettier "2.1.1"

[email protected]:
Expand Down

0 comments on commit 042fae8

Please sign in to comment.