From 67944552081993bfd2e5d9f8d0681ffef146546f Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Mon, 9 Oct 2023 09:28:24 -0300 Subject: [PATCH] update response data --- Cargo.lock | 1 + plugins/nfc/Cargo.toml | 1 + plugins/nfc/guest-js/index.ts | 12 +++++++++++- plugins/nfc/ios/Sources/NfcPlugin.swift | 14 +++++++++++--- plugins/nfc/src/api-iife.js | 2 +- plugins/nfc/src/models.rs | 14 +++++++++++++- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55d36341..0f565c69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5827,6 +5827,7 @@ dependencies = [ "log", "serde", "serde_json", + "serde_repr", "tauri", "tauri-build", "thiserror", diff --git a/plugins/nfc/Cargo.toml b/plugins/nfc/Cargo.toml index 4479e215..bda434d2 100644 --- a/plugins/nfc/Cargo.toml +++ b/plugins/nfc/Cargo.toml @@ -20,3 +20,4 @@ serde_json = { workspace = true } tauri = { workspace = true } log = { workspace = true } thiserror = { workspace = true } +serde_repr = "0.1" diff --git a/plugins/nfc/guest-js/index.ts b/plugins/nfc/guest-js/index.ts index da43aefa..11b0fbc1 100644 --- a/plugins/nfc/guest-js/index.ts +++ b/plugins/nfc/guest-js/index.ts @@ -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[]; diff --git a/plugins/nfc/ios/Sources/NfcPlugin.swift b/plugins/nfc/ios/Sources/NfcPlugin.swift index caee8c23..8fa323e7 100644 --- a/plugins/nfc/ios/Sources/NfcPlugin.swift +++ b/plugins/nfc/ios/Sources/NfcPlugin.swift @@ -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 diff --git a/plugins/nfc/src/api-iife.js b/plugins/nfc/src/api-iife.js index a4faafe1..3e558e01 100644 --- a/plugins/nfc/src/api-iife.js +++ b/plugins/nfc/src/api-iife.js @@ -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__})} diff --git a/plugins/nfc/src/models.rs b/plugins/nfc/src/models.rs index f05a223c..ada1a34a 100644 --- a/plugins/nfc/src/models.rs +++ b/plugins/nfc/src/models.rs @@ -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, pub id: Vec, pub payload: Vec,