mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +02:00
chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)
* chore: adjust prettier config, .gitignore and use taplo to format toml files This brings the plugins-workspace repository to the same code style of the main tauri repo * format toml * ignore examples gen dir * add .vscode/extensions.json * remove packageManager field * fmt * fix audit * taplo ignore permissions autogenerated files * remove create dummy dist * fix prettier workflow * install fmt in prettier workflow --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
@@ -1 +0,0 @@
|
||||
/.tauri
|
||||
@@ -9,12 +9,12 @@ repository = { workspace = true }
|
||||
links = "tauri-plugin-nfc"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustc-args = [ "--cfg", "docsrs" ]
|
||||
rustdoc-args = [ "--cfg", "docsrs" ]
|
||||
targets = [ "x86_64-linux-android" ]
|
||||
rustc-args = ["--cfg", "docsrs"]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
targets = ["x86_64-linux-android"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-plugin = { workspace = true, features = [ "build" ] }
|
||||
tauri-plugin = { workspace = true, features = ["build"] }
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -62,9 +62,9 @@ fn main() {
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { scan, textRecord, write } from "@tauri-apps/plugin-nfc";
|
||||
await scan({ type: "tag", keepSessionAlive: true });
|
||||
await write([textRecord("Tauri is awesome!")]);
|
||||
import { scan, textRecord, write } from '@tauri-apps/plugin-nfc'
|
||||
await scan({ type: 'tag', keepSessionAlive: true })
|
||||
await write([textRecord('Tauri is awesome!')])
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
@@ -20,4 +20,4 @@ We prefer to receive reports in English.
|
||||
|
||||
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
|
||||
|
||||
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
|
||||
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
|
||||
|
||||
+105
-107
@@ -2,15 +2,15 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
export const RTD_TEXT = [0x54]; // "T"
|
||||
export const RTD_URI = [0x55]; // "U"
|
||||
export const RTD_TEXT = [0x54] // "T"
|
||||
export const RTD_URI = [0x55] // "U"
|
||||
|
||||
export interface UriFilter {
|
||||
scheme?: string;
|
||||
host?: string;
|
||||
pathPrefix?: string;
|
||||
scheme?: string
|
||||
host?: string
|
||||
pathPrefix?: string
|
||||
}
|
||||
|
||||
export enum TechKind {
|
||||
@@ -23,19 +23,19 @@ export enum TechKind {
|
||||
NfcB,
|
||||
NfcBarcode,
|
||||
NfcF,
|
||||
NfcV,
|
||||
NfcV
|
||||
}
|
||||
|
||||
export type ScanKind =
|
||||
| {
|
||||
type: "tag";
|
||||
uri?: UriFilter;
|
||||
mimeType?: string;
|
||||
type: 'tag'
|
||||
uri?: UriFilter
|
||||
mimeType?: string
|
||||
}
|
||||
| {
|
||||
type: "ndef";
|
||||
uri?: UriFilter;
|
||||
mimeType?: string;
|
||||
type: 'ndef'
|
||||
uri?: UriFilter
|
||||
mimeType?: string
|
||||
/**
|
||||
* Each of the tech-lists is considered independently and the activity is considered a match if
|
||||
* any single tech-list matches the tag that was discovered.
|
||||
@@ -56,25 +56,25 @@ export type ScanKind =
|
||||
* ]
|
||||
* ```
|
||||
*/
|
||||
techLists?: TechKind[][];
|
||||
};
|
||||
techLists?: TechKind[][]
|
||||
}
|
||||
|
||||
export interface ScanOptions {
|
||||
keepSessionAlive?: boolean;
|
||||
keepSessionAlive?: boolean
|
||||
/** Message displayed in the UI. iOS only. */
|
||||
message?: string;
|
||||
message?: string
|
||||
/** Message displayed in the UI when the message has been read. iOS only. */
|
||||
successMessage?: string;
|
||||
successMessage?: string
|
||||
}
|
||||
|
||||
export interface WriteOptions {
|
||||
kind?: ScanKind;
|
||||
kind?: ScanKind
|
||||
/** Message displayed in the UI when reading the tag. iOS only. */
|
||||
message?: string;
|
||||
message?: string
|
||||
/** Message displayed in the UI when the tag has been read. iOS only. */
|
||||
successfulReadMessage?: string;
|
||||
successfulReadMessage?: string
|
||||
/** Message displayed in the UI when the message has been written. iOS only. */
|
||||
successMessage?: string;
|
||||
successMessage?: string
|
||||
}
|
||||
|
||||
export enum NFCTypeNameFormat {
|
||||
@@ -84,122 +84,120 @@ export enum NFCTypeNameFormat {
|
||||
AbsoluteURI = 3,
|
||||
NfcExternal = 4,
|
||||
Unknown = 5,
|
||||
Unchanged = 6,
|
||||
Unchanged = 6
|
||||
}
|
||||
|
||||
export interface TagRecord {
|
||||
tnf: NFCTypeNameFormat;
|
||||
kind: number[];
|
||||
id: number[];
|
||||
payload: number[];
|
||||
tnf: NFCTypeNameFormat
|
||||
kind: number[]
|
||||
id: number[]
|
||||
payload: number[]
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
id: number[];
|
||||
kind: string[];
|
||||
records: TagRecord[];
|
||||
id: number[]
|
||||
kind: string[]
|
||||
records: TagRecord[]
|
||||
}
|
||||
|
||||
export interface NFCRecord {
|
||||
format: NFCTypeNameFormat;
|
||||
kind: number[];
|
||||
id: number[];
|
||||
payload: number[];
|
||||
format: NFCTypeNameFormat
|
||||
kind: number[]
|
||||
id: number[]
|
||||
payload: number[]
|
||||
}
|
||||
|
||||
export function record(
|
||||
format: NFCTypeNameFormat,
|
||||
kind: string | number[],
|
||||
id: string | number[],
|
||||
payload: string | number[],
|
||||
payload: string | number[]
|
||||
): NFCRecord {
|
||||
return {
|
||||
format,
|
||||
kind:
|
||||
typeof kind === "string"
|
||||
typeof kind === 'string'
|
||||
? Array.from(new TextEncoder().encode(kind))
|
||||
: kind,
|
||||
id: typeof id === "string" ? Array.from(new TextEncoder().encode(id)) : id,
|
||||
id: typeof id === 'string' ? Array.from(new TextEncoder().encode(id)) : id,
|
||||
payload:
|
||||
typeof payload === "string"
|
||||
typeof payload === 'string'
|
||||
? Array.from(new TextEncoder().encode(payload))
|
||||
: payload,
|
||||
};
|
||||
: payload
|
||||
}
|
||||
}
|
||||
|
||||
export function textRecord(
|
||||
text: string,
|
||||
id?: string | number[],
|
||||
language: string = "en",
|
||||
language: string = 'en'
|
||||
): NFCRecord {
|
||||
const payload = Array.from(new TextEncoder().encode(language + text));
|
||||
payload.unshift(language.length);
|
||||
return record(NFCTypeNameFormat.NfcWellKnown, RTD_TEXT, id ?? [], payload);
|
||||
const payload = Array.from(new TextEncoder().encode(language + text))
|
||||
payload.unshift(language.length)
|
||||
return record(NFCTypeNameFormat.NfcWellKnown, RTD_TEXT, id ?? [], payload)
|
||||
}
|
||||
|
||||
const protocols = [
|
||||
"",
|
||||
"http://www.",
|
||||
"https://www.",
|
||||
"http://",
|
||||
"https://",
|
||||
"tel:",
|
||||
"mailto:",
|
||||
"ftp://anonymous:anonymous@",
|
||||
"ftp://ftp.",
|
||||
"ftps://",
|
||||
"sftp://",
|
||||
"smb://",
|
||||
"nfs://",
|
||||
"ftp://",
|
||||
"dav://",
|
||||
"news:",
|
||||
"telnet://",
|
||||
"imap:",
|
||||
"rtsp://",
|
||||
"urn:",
|
||||
"pop:",
|
||||
"sip:",
|
||||
"sips:",
|
||||
"tftp:",
|
||||
"btspp://",
|
||||
"btl2cap://",
|
||||
"btgoep://",
|
||||
"tcpobex://",
|
||||
"irdaobex://",
|
||||
"file://",
|
||||
"urn:epc:id:",
|
||||
"urn:epc:tag:",
|
||||
"urn:epc:pat:",
|
||||
"urn:epc:raw:",
|
||||
"urn:epc:",
|
||||
"urn:nfc:",
|
||||
];
|
||||
'',
|
||||
'http://www.',
|
||||
'https://www.',
|
||||
'http://',
|
||||
'https://',
|
||||
'tel:',
|
||||
'mailto:',
|
||||
'ftp://anonymous:anonymous@',
|
||||
'ftp://ftp.',
|
||||
'ftps://',
|
||||
'sftp://',
|
||||
'smb://',
|
||||
'nfs://',
|
||||
'ftp://',
|
||||
'dav://',
|
||||
'news:',
|
||||
'telnet://',
|
||||
'imap:',
|
||||
'rtsp://',
|
||||
'urn:',
|
||||
'pop:',
|
||||
'sip:',
|
||||
'sips:',
|
||||
'tftp:',
|
||||
'btspp://',
|
||||
'btl2cap://',
|
||||
'btgoep://',
|
||||
'tcpobex://',
|
||||
'irdaobex://',
|
||||
'file://',
|
||||
'urn:epc:id:',
|
||||
'urn:epc:tag:',
|
||||
'urn:epc:pat:',
|
||||
'urn:epc:raw:',
|
||||
'urn:epc:',
|
||||
'urn:nfc:'
|
||||
]
|
||||
|
||||
function encodeURI(uri: string): number[] {
|
||||
let prefix = "";
|
||||
let prefix = ''
|
||||
|
||||
protocols.slice(1).forEach(function (protocol) {
|
||||
if (
|
||||
(prefix.length === 0 || prefix === "urn:") &&
|
||||
(prefix.length === 0 || prefix === 'urn:') &&
|
||||
uri.indexOf(protocol) === 0
|
||||
) {
|
||||
prefix = protocol;
|
||||
prefix = protocol
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
if (prefix.length === 0) {
|
||||
prefix = "";
|
||||
prefix = ''
|
||||
}
|
||||
|
||||
const encoded = Array.from(
|
||||
new TextEncoder().encode(uri.slice(prefix.length)),
|
||||
);
|
||||
const protocolCode = protocols.indexOf(prefix);
|
||||
const encoded = Array.from(new TextEncoder().encode(uri.slice(prefix.length)))
|
||||
const protocolCode = protocols.indexOf(prefix)
|
||||
// prepend protocol code
|
||||
encoded.unshift(protocolCode);
|
||||
encoded.unshift(protocolCode)
|
||||
|
||||
return encoded;
|
||||
return encoded
|
||||
}
|
||||
|
||||
export function uriRecord(uri: string, id?: string | number[]): NFCRecord {
|
||||
@@ -207,13 +205,13 @@ export function uriRecord(uri: string, id?: string | number[]): NFCRecord {
|
||||
NFCTypeNameFormat.NfcWellKnown,
|
||||
RTD_URI,
|
||||
id ?? [],
|
||||
encodeURI(uri),
|
||||
);
|
||||
encodeURI(uri)
|
||||
)
|
||||
}
|
||||
|
||||
function mapScanKind(kind: ScanKind): Record<string, unknown> {
|
||||
const { type: scanKind, ...kindOptions } = kind;
|
||||
return { [scanKind]: kindOptions };
|
||||
const { type: scanKind, ...kindOptions } = kind
|
||||
return { [scanKind]: kindOptions }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,12 +230,12 @@ function mapScanKind(kind: ScanKind): Record<string, unknown> {
|
||||
*/
|
||||
export async function scan(
|
||||
kind: ScanKind,
|
||||
options?: ScanOptions,
|
||||
options?: ScanOptions
|
||||
): Promise<Tag> {
|
||||
return await invoke("plugin:nfc|scan", {
|
||||
return await invoke('plugin:nfc|scan', {
|
||||
kind: mapScanKind(kind),
|
||||
...options,
|
||||
});
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,19 +255,19 @@ export async function scan(
|
||||
*/
|
||||
export async function write(
|
||||
records: NFCRecord[],
|
||||
options?: WriteOptions,
|
||||
options?: WriteOptions
|
||||
): Promise<void> {
|
||||
const { kind, ...opts } = options ?? {};
|
||||
const { kind, ...opts } = options ?? {}
|
||||
if (kind) {
|
||||
// @ts-expect-error map the property
|
||||
opts.kind = mapScanKind(kind);
|
||||
opts.kind = mapScanKind(kind)
|
||||
}
|
||||
await invoke("plugin:nfc|write", {
|
||||
await invoke('plugin:nfc|write', {
|
||||
records,
|
||||
...opts,
|
||||
});
|
||||
...opts
|
||||
})
|
||||
}
|
||||
|
||||
export async function isAvailable(): Promise<boolean> {
|
||||
return await invoke("plugin:nfc|is_available");
|
||||
return await invoke('plugin:nfc|is_available')
|
||||
}
|
||||
|
||||
@@ -12,7 +12,4 @@ and scanning nearby tags is allowed.
|
||||
Writing to tags needs to be manually enabled.
|
||||
|
||||
"""
|
||||
permissions = [
|
||||
"allow-is-available",
|
||||
"allow-scan",
|
||||
]
|
||||
permissions = ["allow-is-available", "allow-scan"]
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { createConfig } from "../../shared/rollup.config.js";
|
||||
import { createConfig } from '../../shared/rollup.config.js'
|
||||
|
||||
export default createConfig();
|
||||
export default createConfig()
|
||||
|
||||
Reference in New Issue
Block a user