update response data

pull/830/head
Lucas Nogueira 2 years ago
parent cfc5fc699e
commit 6794455208
No known key found for this signature in database
GPG Key ID: 3AFF5CAD641DD470

1
Cargo.lock generated

@ -5827,6 +5827,7 @@ dependencies = [
"log",
"serde",
"serde_json",
"serde_repr",
"tauri",
"tauri-build",
"thiserror",

@ -20,3 +20,4 @@ serde_json = { workspace = true }
tauri = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
serde_repr = "0.1"

@ -17,8 +17,18 @@ export interface ScanOptions {
keepAlive?: boolean;
}
export enum NFCTypeNameFormat {
Empty = 0,
NfcWellKnown = 1,
Media = 2,
AbsoluteURI = 3,
NfcExternal = 4,
Unknown = 5,
Unchanged = 6,
}
export interface TagRecord {
tnf: number;
tnf: NFCTypeNameFormat;
kind: number[];
id: number[];
payload: number[];

@ -260,9 +260,9 @@ class NfcPlugin: Plugin, NFCTagReaderSessionDelegate, NFCNDEFReaderSessionDelega
for record in message.records {
var recordJson: JsonObject = [:]
recordJson["tnf"] = record.typeNameFormat.rawValue
recordJson["kind"] = record.type
recordJson["id"] = record.identifier
recordJson["payload"] = record.payload
recordJson["kind"] = byteArrayFromData(record.type)
recordJson["id"] = byteArrayFromData(record.identifier)
recordJson["payload"] = byteArrayFromData(record.payload)
records.append(recordJson)
}
@ -272,6 +272,14 @@ class NfcPlugin: Plugin, NFCTagReaderSessionDelegate, NFCNDEFReaderSessionDelega
return tag
}
private func byteArrayFromData(_ data: Data) -> [UInt8] {
var arr: [UInt8] = []
for b in data {
arr.append(b)
}
return arr
}
@objc func isAvailable(_ invoke: Invoke) {
invoke.resolve([
"available": NFCNDEFReaderSession.readingAvailable

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_NFC__=function(n){"use strict";var _;return n.ScanKind=void 0,(_=n.ScanKind||(n.ScanKind={}))[_.Ndef=0]="Ndef",_[_.Tag=1]="Tag",n.isAvailable=async function(){return await window.__TAURI_INVOKE__("plugin:nfc|isAvailable")},n.scan=async function(_,i){return await window.__TAURI_INVOKE__("plugin:nfc|scan",{kind:_===n.ScanKind.Ndef?"ndef":"tag",...i})},n}({});Object.defineProperty(window.__TAURI__,"nfc",{value:__TAURI_NFC__})}
if("__TAURI__"in window){var __TAURI_NFC__=function(n){"use strict";var a,e;return n.ScanKind=void 0,(a=n.ScanKind||(n.ScanKind={}))[a.Ndef=0]="Ndef",a[a.Tag=1]="Tag",n.NFCTypeNameFormat=void 0,(e=n.NFCTypeNameFormat||(n.NFCTypeNameFormat={}))[e.Empty=0]="Empty",e[e.NfcWellKnown=1]="NfcWellKnown",e[e.Media=2]="Media",e[e.AbsoluteURI=3]="AbsoluteURI",e[e.NfcExternal=4]="NfcExternal",e[e.Unknown=5]="Unknown",e[e.Unchanged=6]="Unchanged",n.isAvailable=async function(){return await window.__TAURI_INVOKE__("plugin:nfc|isAvailable")},n.scan=async function(a,e){return await window.__TAURI_INVOKE__("plugin:nfc|scan",{kind:a===n.ScanKind.Ndef?"ndef":"tag",...e})},n}({});Object.defineProperty(window.__TAURI__,"nfc",{value:__TAURI_NFC__})}

@ -12,9 +12,21 @@ pub struct ScanRequest {
pub keep_alive: bool,
}
#[derive(serde_repr::Deserialize_repr)]
#[repr(u8)]
pub enum NFCTypeNameFormat {
Empty = 0,
NfcWellKnown = 1,
Media = 2,
AbsoluteURI = 3,
NfcExternal = 4,
Unknown = 5,
Unchanged = 6,
}
#[derive(Deserialize)]
pub struct NfcTagRecord {
pub tnf: u8,
pub tnf: NFCTypeNameFormat,
pub kind: Vec<u8>,
pub id: Vec<u8>,
pub payload: Vec<u8>,

Loading…
Cancel
Save