sketch api, remove desktop

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

@ -25,7 +25,6 @@ tauri-plugin-clipboard-manager = { path = "../../../plugins/clipboard-manager",
tauri-plugin-dialog = { path = "../../../plugins/dialog", version = "2.0.0-alpha.2" }
tauri-plugin-http = { path = "../../../plugins/http", features = [ "multipart" ], version = "2.0.0-alpha.3" }
tauri-plugin-notification = { path = "../../../plugins/notification", version = "2.0.0-alpha.3", features = [ "windows7-compat" ] }
tauri-plugin-nfc = { path = "../../../plugins/nfc", version = "1.0.0" }
tauri-plugin-os = { path = "../../../plugins/os", version = "2.0.0-alpha.2" }
tauri-plugin-process = { path = "../../../plugins/process", version = "2.0.0-alpha.2" }
tauri-plugin-shell = { path = "../../../plugins/shell", version = "2.0.0-alpha.2" }
@ -49,6 +48,7 @@ tauri-plugin-updater = { path = "../../../plugins/updater", version = "2.0.0-alp
[target."cfg(any(target_os = \"android\", target_os = \"ios\"))".dependencies]
tauri-plugin-barcode-scanner = { path = "../../../plugins/barcode-scanner/", version = "2.0.0-alpha.0" }
tauri-plugin-nfc = { path = "../../../plugins/nfc", version = "1.0.0" }
[target."cfg(target_os = \"windows\")".dependencies]
window-shadows = "0.2"

@ -1,116 +1,116 @@
{
"images" : [
"images": [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "AppIcon-20x20@2x.png",
"scale" : "2x"
"size": "20x20",
"idiom": "iphone",
"filename": "AppIcon-20x20@2x.png",
"scale": "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "AppIcon-20x20@3x.png",
"scale" : "3x"
"size": "20x20",
"idiom": "iphone",
"filename": "AppIcon-20x20@3x.png",
"scale": "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "AppIcon-29x29@2x-1.png",
"scale" : "2x"
"size": "29x29",
"idiom": "iphone",
"filename": "AppIcon-29x29@2x-1.png",
"scale": "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "AppIcon-29x29@3x.png",
"scale" : "3x"
"size": "29x29",
"idiom": "iphone",
"filename": "AppIcon-29x29@3x.png",
"scale": "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "AppIcon-40x40@2x.png",
"scale" : "2x"
"size": "40x40",
"idiom": "iphone",
"filename": "AppIcon-40x40@2x.png",
"scale": "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "AppIcon-40x40@3x.png",
"scale" : "3x"
"size": "40x40",
"idiom": "iphone",
"filename": "AppIcon-40x40@3x.png",
"scale": "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "AppIcon-60x60@2x.png",
"scale" : "2x"
"size": "60x60",
"idiom": "iphone",
"filename": "AppIcon-60x60@2x.png",
"scale": "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "AppIcon-60x60@3x.png",
"scale" : "3x"
"size": "60x60",
"idiom": "iphone",
"filename": "AppIcon-60x60@3x.png",
"scale": "3x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "AppIcon-20x20@1x.png",
"scale" : "1x"
"size": "20x20",
"idiom": "ipad",
"filename": "AppIcon-20x20@1x.png",
"scale": "1x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "AppIcon-20x20@2x-1.png",
"scale" : "2x"
"size": "20x20",
"idiom": "ipad",
"filename": "AppIcon-20x20@2x-1.png",
"scale": "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "AppIcon-29x29@1x.png",
"scale" : "1x"
"size": "29x29",
"idiom": "ipad",
"filename": "AppIcon-29x29@1x.png",
"scale": "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "AppIcon-29x29@2x.png",
"scale" : "2x"
"size": "29x29",
"idiom": "ipad",
"filename": "AppIcon-29x29@2x.png",
"scale": "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "AppIcon-40x40@1x.png",
"scale" : "1x"
"size": "40x40",
"idiom": "ipad",
"filename": "AppIcon-40x40@1x.png",
"scale": "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "AppIcon-40x40@2x-1.png",
"scale" : "2x"
"size": "40x40",
"idiom": "ipad",
"filename": "AppIcon-40x40@2x-1.png",
"scale": "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "AppIcon-76x76@1x.png",
"scale" : "1x"
"size": "76x76",
"idiom": "ipad",
"filename": "AppIcon-76x76@1x.png",
"scale": "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "AppIcon-76x76@2x.png",
"scale" : "2x"
"size": "76x76",
"idiom": "ipad",
"filename": "AppIcon-76x76@2x.png",
"scale": "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "AppIcon-83.5x83.5@2x.png",
"scale" : "2x"
"size": "83.5x83.5",
"idiom": "ipad",
"filename": "AppIcon-83.5x83.5@2x.png",
"scale": "2x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "AppIcon-512@2x.png",
"scale" : "1x"
"size": "1024x1024",
"idiom": "ios-marketing",
"filename": "AppIcon-512@2x.png",
"scale": "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"info": {
"version": 1,
"author": "xcode"
}
}
}

@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"info": {
"version": 1,
"author": "xcode"
}
}
}

@ -36,7 +36,6 @@ pub fn run() {
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_nfc::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_process::init())
@ -55,6 +54,7 @@ pub fn run() {
#[cfg(mobile)]
{
app.handle().plugin(tauri_plugin_barcode_scanner::init())?;
app.handle().plugin(tauri_plugin_nfc::init())?;
}
let mut window_builder = WindowBuilder::new(app, "main", WindowUrl::default());

@ -2,6 +2,50 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
export async function scanNdef() {}
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
export async function scanTag() {}
export enum ScanKind {
Ndef,
Tag,
}
export interface ScanOptions {
keepAlive?: boolean;
}
export interface TagRecord {
tnf: number;
kind: number[];
id: number[];
payload: number[];
}
export interface Tag {
id: string;
kind: string;
records: TagRecord[];
}
export interface Scan {
id: string;
kind: string;
tag: Tag;
}
export async function scan(
kind: ScanKind,
options?: ScanOptions,
): Promise<Scan> {
return await window.__TAURI_INVOKE__("plugin:nfc|scan", {
kind: kind === ScanKind.Ndef ? "ndef" : "tag",
...options,
});
}
export async function isAvailable(): Promise<boolean> {
return await window.__TAURI_INVOKE__("plugin:nfc|isAvailable");
}

@ -45,7 +45,6 @@ class NfcPlugin: Plugin, NFCTagReaderSessionDelegate, NFCNDEFReaderSessionDelega
}
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
Logger.info("detected tags!")
let tag = tags.first!
session.connect(
@ -132,23 +131,23 @@ class NfcPlugin: Plugin, NFCTagReaderSessionDelegate, NFCNDEFReaderSessionDelega
switch tag {
case .feliCa:
metadata["type"] = "FeliCa"
metadata["kind"] = "FeliCa"
metadata["id"] = nil
break
case let .miFare(tag):
metadata["type"] = "MiFare"
metadata["kind"] = "MiFare"
metadata["id"] = tag.identifier
break
case let .iso15693(tag):
metadata["type"] = "ISO15693"
metadata["kind"] = "ISO15693"
metadata["id"] = tag.identifier
break
case let .iso7816(tag):
metadata["type"] = "ISO7816Compatible"
metadata["kind"] = "ISO7816Compatible"
metadata["id"] = tag.identifier
break
default:
metadata["type"] = "Unknown"
metadata["kind"] = "Unknown"
metadata["id"] = nil
break
}
@ -260,8 +259,8 @@ class NfcPlugin: Plugin, NFCTagReaderSessionDelegate, NFCNDEFReaderSessionDelega
var records: [JsonObject] = []
for record in message.records {
var recordJson: JsonObject = [:]
recordJson["tnf"] = record.typeNameFormat
recordJson["type"] = record.type
recordJson["tnf"] = record.typeNameFormat.rawValue
recordJson["kind"] = record.type
recordJson["id"] = record.identifier
recordJson["payload"] = record.payload
@ -273,16 +272,22 @@ class NfcPlugin: Plugin, NFCTagReaderSessionDelegate, NFCNDEFReaderSessionDelega
return tag
}
@objc func isAvailable(_ invoke: Invoke) {
invoke.resolve([
"available": NFCNDEFReaderSession.readingAvailable
])
}
@objc public func scan(_ invoke: Invoke) {
let kind: ScanKind
switch invoke.getString("kind") {
case "tag":
case "tag":
kind = .tag
break
case "ndef":
case "ndef":
kind = .ndef
break
default:
default:
invoke.reject("invalid `kind` argument, expected one of `tag`, `ndef`.")
return
}

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_NFC__=function(_){"use strict";return _.scanNdef=async function(){},_.scanTag=async function(){},_}({});Object.defineProperty(window.__TAURI__,"nfc",{value:__TAURI_NFC__})}
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__})}

@ -1,26 +0,0 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use serde::de::DeserializeOwned;
use tauri::{plugin::PluginApi, AppHandle, Runtime};
use crate::models::*;
pub fn init<R: Runtime, C: DeserializeOwned>(
app: &AppHandle<R>,
_api: PluginApi<R, C>,
) -> crate::Result<Nfc<R>> {
Ok(Nfc(app.clone()))
}
/// Access to the nfc APIs.
pub struct Nfc<R: Runtime>(AppHandle<R>);
impl<R: Runtime> Nfc<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
Ok(PingResponse {
value: payload.value,
})
}
}

@ -2,28 +2,50 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#![cfg(mobile)]
use serde::Deserialize;
use tauri::{
plugin::{Builder, TauriPlugin},
plugin::{Builder, PluginHandle, TauriPlugin},
Manager, Runtime,
};
pub use models::*;
#[cfg(desktop)]
mod desktop;
#[cfg(mobile)]
mod mobile;
mod commands;
mod error;
mod models;
pub use error::{Error, Result};
#[cfg(desktop)]
use desktop::Nfc;
#[cfg(mobile)]
use mobile::Nfc;
#[cfg(target_os = "android")]
const PLUGIN_IDENTIFIER: &str = "app.tauri.nfc";
#[cfg(target_os = "ios")]
tauri::ios_plugin_binding!(init_plugin_nfc);
/// Access to the nfc APIs.
pub struct Nfc<R: Runtime>(PluginHandle<R>);
#[derive(Deserialize)]
struct IsAvailableResponse {
available: bool,
}
impl<R: Runtime> Nfc<R> {
pub fn is_available(&self) -> crate::Result<bool> {
self.0
.run_mobile_plugin::<IsAvailableResponse>("isAvailable", ())
.map(|r| r.available)
.map_err(Into::into)
}
pub fn scan(&self, payload: ScanRequest) -> crate::Result<ScanResponse> {
self.0
.run_mobile_plugin("scan", payload)
.map_err(Into::into)
}
}
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the nfc APIs.
pub trait NfcExt<R: Runtime> {
@ -42,11 +64,11 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![commands::execute])
.setup(|app, api| {
#[cfg(mobile)]
let nfc = mobile::init(app, api)?;
#[cfg(desktop)]
let nfc = desktop::init(app, api)?;
app.manage(nfc);
#[cfg(target_os = "android")]
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "NfcPlugin")?;
#[cfg(target_os = "ios")]
let handle = api.register_ios_plugin(init_plugin_nfc)?;
app.manage(Nfc(handle));
Ok(())
})
.build()

@ -9,32 +9,3 @@ use tauri::{
};
use crate::models::*;
#[cfg(target_os = "android")]
const PLUGIN_IDENTIFIER: &str = "app.tauri.nfc";
#[cfg(target_os = "ios")]
tauri::ios_plugin_binding!(init_plugin_nfc);
// initializes the Kotlin or Swift plugin classes
pub fn init<R: Runtime, C: DeserializeOwned>(
_app: &AppHandle<R>,
api: PluginApi<R, C>,
) -> crate::Result<Nfc<R>> {
#[cfg(target_os = "android")]
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "NfcPlugin")?;
#[cfg(target_os = "ios")]
let handle = api.register_ios_plugin(init_plugin_nfc)?;
Ok(Nfc(handle))
}
/// Access to the nfc APIs.
pub struct Nfc<R: Runtime>(PluginHandle<R>);
impl<R: Runtime> Nfc<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
self.0
.run_mobile_plugin("ping", payload)
.map_err(Into::into)
}
}

@ -2,16 +2,60 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Serialize, Serializer};
use std::fmt::Display;
#[derive(Debug, Serialize)]
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PingRequest {
pub value: Option<String>,
pub struct ScanRequest {
pub kind: ScanKind,
pub keep_alive: bool,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PingResponse {
pub value: Option<String>,
#[derive(Deserialize)]
pub struct NfcTagRecord {
pub tnf: u8,
pub kind: Vec<u8>,
pub id: Vec<u8>,
pub payload: Vec<u8>,
}
#[derive(Deserialize)]
pub struct NfcTag {
pub id: String,
pub kind: String,
pub records: Vec<NfcTagRecord>,
}
#[derive(Deserialize)]
pub struct ScanResponse {
pub tag: NfcTag,
}
#[derive(Debug)]
pub enum ScanKind {
Ndef,
Tag,
}
impl Display for ScanKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::Ndef => "ndef",
Self::Tag => "tag",
}
)
}
}
impl Serialize for ScanKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.to_string())
}
}

Loading…
Cancel
Save