From 0be9adf117732edc565ce12b3e7f9925f17f2eca Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Tue, 20 Jun 2023 15:53:52 +0000 Subject: [PATCH] added `startScanning` method --- packages/app/src/cores/nfc/nfc.core.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/app/src/cores/nfc/nfc.core.js b/packages/app/src/cores/nfc/nfc.core.js index 143e09bc..d8aea5cc 100644 --- a/packages/app/src/cores/nfc/nfc.core.js +++ b/packages/app/src/cores/nfc/nfc.core.js @@ -1,5 +1,6 @@ import Core from "evite/src/core" import TapShareDialog from "components/TapShare/Dialog" +import { Nfc, NfcUtils, NfcTagTechType } from "@capawesome-team/capacitor-nfc" export default class NFC extends Core { static refName = "NFC" @@ -13,6 +14,7 @@ export default class NFC extends Core { public = { incompatible: null, scanning: false, + startScanning: this.startScanning.bind(this), instance: function () { return this.instance }.bind(this), subscribe: this.subscribe.bind(this), unsubscribe: this.unsubscribe.bind(this), @@ -25,8 +27,12 @@ export default class NFC extends Core { this.instance = new NDEFReader() + this.startScanning() + } + + async startScanning() { try { - navigator.permissions.query({ name: "nfc" }) + //await navigator.permissions.query({ name: "nfc" }) this.instance.scan() @@ -43,6 +49,11 @@ export default class NFC extends Core { } subscribe(callback) { + // check if scan service is available, if not try to initialize + if (this.public.scanning === false) { + this.startScanning() + } + this.subscribers.push(callback) console.debug(`[NFC] SUBSCRIBED >`, this.subscribers.length)