mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +02:00
Merge remote-tracking branch 'origin/v2' into feat/camera
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.2]
|
||||
|
||||
- [`4e2cef9`](https://github.com/tauri-apps/plugins-workspace/commit/4e2cef9b702bbbb9cf4ee17de50791cb21f1b2a4)([#593](https://github.com/tauri-apps/plugins-workspace/pull/593)) Update to alpha.12.
|
||||
|
||||
## \[2.0.0-alpha.1]
|
||||
|
||||
- [`d74fc0a`](https://github.com/tauri-apps/plugins-workspace/commit/d74fc0a097996e90a37be8f57d50b7d1f6ca616f)([#555](https://github.com/tauri-apps/plugins-workspace/pull/555)) Update to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
te to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "tauri-plugin-app"
|
||||
version = "2.0.0-alpha.2"
|
||||
description = "APIs to read application metadata and change app visibility on macOS."
|
||||
edition = { workspace = true }
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [ "tauri/dox" ]
|
||||
|
||||
[dependencies]
|
||||
tauri = { workspace = true }
|
||||
@@ -1,10 +1,10 @@
|
||||

|
||||

|
||||
|
||||
Watch files and directories for changes using [notify](https://github.com/notify-rs/notify).
|
||||
This plugin provides APIs to read application metadata and macOS app visibility functions.
|
||||
|
||||
## Install
|
||||
|
||||
_This plugin requires a Rust version of at least **1.64**_
|
||||
_This plugin requires a Rust version of at least **1.65**_
|
||||
|
||||
There are three general methods of installation that we can recommend.
|
||||
|
||||
@@ -18,7 +18,9 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri-plugin-fs-watch = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
tauri-plugin-app = "2.0.0-alpha"
|
||||
# alternatively with Git:
|
||||
tauri-plugin-app = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
||||
@@ -26,11 +28,18 @@ You can install the JavaScript Guest bindings using your preferred JavaScript pa
|
||||
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
||||
|
||||
```sh
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-fs-watch#v2
|
||||
pnpm add @tauri-apps/plugin-app
|
||||
# or
|
||||
npm add https://github.com/tauri-apps/tauri-plugin-fs-watch#v2
|
||||
npm add @tauri-apps/plugin-app
|
||||
# or
|
||||
yarn add https://github.com/tauri-apps/tauri-plugin-fs-watch#v2
|
||||
yarn add @tauri-apps/plugin-app
|
||||
|
||||
# alternatively with Git:
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-app#v2
|
||||
# or
|
||||
npm add https://github.com/tauri-apps/tauri-plugin-app#v2
|
||||
# or
|
||||
yarn add https://github.com/tauri-apps/tauri-plugin-app#v2
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -42,7 +51,7 @@ First you need to register the core plugin with Tauri:
|
||||
```rust
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_fs_watch::init())
|
||||
.plugin(tauri_plugin_app::init())
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -51,24 +60,9 @@ fn main() {
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { watch, watchImmediate } from "tauri-plugin-fs-watch-api";
|
||||
|
||||
// can also watch an array of paths
|
||||
const stopWatching = await watch(
|
||||
"/path/to/something",
|
||||
(event) => {
|
||||
const { type, payload } = event;
|
||||
},
|
||||
{ recursive: true }
|
||||
);
|
||||
|
||||
const stopRawWatcher = await watchImmediate(
|
||||
["/path/a", "/path/b"],
|
||||
(event) => {
|
||||
const { path, operation, cookie } = event;
|
||||
},
|
||||
{}
|
||||
);
|
||||
import { getVersion, hide } from "@tauri-apps/plugin-app";
|
||||
const appVersion = await getVersion();
|
||||
await hide();
|
||||
```
|
||||
|
||||
## Contributing
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
@@ -0,0 +1,90 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* Get application metadata.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application version.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { getVersion } from '@tauri-apps/plugin-app';
|
||||
* const appVersion = await getVersion();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function getVersion(): Promise<string> {
|
||||
return window.__TAURI_INVOKE__("plugin:app|version");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application name.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { getName } from '@tauri-apps/plugin-app';
|
||||
* const appName = await getName();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function getName(): Promise<string> {
|
||||
return window.__TAURI_INVOKE__("plugin:app|name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Tauri version.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { getTauriVersion } from '@tauri-apps/plugin-app';
|
||||
* const tauriVersion = await getTauriVersion();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function getTauriVersion(): Promise<string> {
|
||||
return window.__TAURI_INVOKE__("plugin:app|tauri_version");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the application on macOS. This function does not automatically focus any specific app window.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { show } from '@tauri-apps/plugin-app';
|
||||
* await show();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function show(): Promise<void> {
|
||||
return window.__TAURI_INVOKE__("plugin:app|show");
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides the application on macOS.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { hide } from '@tauri-apps/plugin-app';
|
||||
* await hide();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function hide(): Promise<void> {
|
||||
return window.__TAURI_INVOKE__("plugin:app|hide");
|
||||
}
|
||||
|
||||
export { getName, getVersion, getTauriVersion, show, hide };
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"name": "tauri-plugin-fs-watch-api",
|
||||
"version": "0.0.0",
|
||||
"description": "Watch files and directories for changes.",
|
||||
"name": "@tauri-apps/plugin-app",
|
||||
"version": "2.0.0-alpha.1",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
"Tauri Programme within The Commons Conservancy"
|
||||
@@ -28,6 +27,6 @@
|
||||
"tslib": "^2.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.2.0"
|
||||
"@tauri-apps/api": "2.0.0-alpha.8"
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { createConfig } from "../../shared/rollup.config.mjs";
|
||||
export default createConfig({
|
||||
input: "guest-js/index.ts",
|
||||
pkg: JSON.parse(
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
|
||||
),
|
||||
external: [/^@tauri-apps\/api/],
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_APP__=function(_){"use strict";return _.getName=async function(){return window.__TAURI_INVOKE__("plugin:app|name")},_.getTauriVersion=async function(){return window.__TAURI_INVOKE__("plugin:app|tauri_version")},_.getVersion=async function(){return window.__TAURI_INVOKE__("plugin:app|version")},_.hide=async function(){return window.__TAURI_INVOKE__("plugin:app|hide")},_.show=async function(){return window.__TAURI_INVOKE__("plugin:app|show")},_}({});Object.defineProperty(window.__TAURI__,"app",{value:__TAURI_APP__})}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use tauri::{AppHandle, Runtime};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn version<R: Runtime>(app: AppHandle<R>) -> String {
|
||||
app.package_info().version.to_string()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn name<R: Runtime>(app: AppHandle<R>) -> String {
|
||||
app.package_info().name.clone()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn tauri_version() -> &'static str {
|
||||
tauri::VERSION
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[allow(unused_variables)]
|
||||
pub fn show<R: Runtime>(app: AppHandle<R>) -> tauri::Result<()> {
|
||||
#[cfg(target_os = "macos")]
|
||||
app.show()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[allow(unused_variables)]
|
||||
pub fn hide<R: Runtime>(app: AppHandle<R>) -> tauri::Result<()> {
|
||||
#[cfg(target_os = "macos")]
|
||||
app.hide()?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//! [](https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/app)
|
||||
//!
|
||||
//! This plugin provides APIs to read application metadata and macOS app visibility functions.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
|
||||
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
||||
)]
|
||||
|
||||
use tauri::{
|
||||
plugin::{Builder, TauriPlugin},
|
||||
Runtime,
|
||||
};
|
||||
|
||||
mod commands;
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("app")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::version,
|
||||
commands::name,
|
||||
commands::tauri_version,
|
||||
commands::show,
|
||||
commands::hide
|
||||
])
|
||||
.build()
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.2]
|
||||
|
||||
- [`4e2cef9`](https://github.com/tauri-apps/plugins-workspace/commit/4e2cef9b702bbbb9cf4ee17de50791cb21f1b2a4)([#593](https://github.com/tauri-apps/plugins-workspace/pull/593)) Update to alpha.12.
|
||||
|
||||
## \[2.0.0-alpha.1]
|
||||
|
||||
- [`d74fc0a`](https://github.com/tauri-apps/plugins-workspace/commit/d74fc0a097996e90a37be8f57d50b7d1f6ca616f)([#555](https://github.com/tauri-apps/plugins-workspace/pull/555)) Update to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
te to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
@@ -1,20 +1,23 @@
|
||||
[package]
|
||||
name = "tauri-plugin-authenticator"
|
||||
version = "0.0.0"
|
||||
version = "2.0.0-alpha.2"
|
||||
description = "Use hardware security-keys in your Tauri App."
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
rust-version = { workspace = true }
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[package.metadata.docs.rs]
|
||||
features = [ "tauri/dox" ]
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
tauri.workspace = true
|
||||
log.workspace = true
|
||||
thiserror.workspace = true
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
log = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
|
||||
authenticator = "0.3.1"
|
||||
once_cell = "1"
|
||||
sha2 = "0.10"
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||

|
||||

|
||||
|
||||
Use hardware security-keys in your Tauri App.
|
||||
|
||||
- Supported platforms: Windows, Linux, FreeBSD, NetBSD, OpenBSD, and macOS.
|
||||
|
||||
## Install
|
||||
|
||||
_This plugin requires a Rust version of at least **1.64**_
|
||||
_This plugin requires a Rust version of at least **1.65**_
|
||||
|
||||
There are three general methods of installation that we can recommend.
|
||||
|
||||
@@ -17,9 +19,10 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
`src-tauri/Cargo.toml`
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri-plugin-authenticator = "0.1"
|
||||
# or through git
|
||||
# you can add the dependencies on the `[dependencies]` section if you do not target mobile
|
||||
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
|
||||
tauri-plugin-authenticator = "2.0.0-alpha"
|
||||
# alternatively with Git:
|
||||
tauri-plugin-authenticator = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
@@ -27,6 +30,16 @@ You can install the JavaScript Guest bindings using your preferred JavaScript pa
|
||||
|
||||
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
||||
|
||||
```sh
|
||||
pnpm add @tauri-apps/plugin-authenticator
|
||||
# or
|
||||
npm add @tauri-apps/plugin-authenticator
|
||||
# or
|
||||
yarn add @tauri-apps/plugin-authenticator
|
||||
```
|
||||
|
||||
Alternatively with Git:
|
||||
|
||||
```sh
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-authenticator#v2
|
||||
# or
|
||||
@@ -44,7 +57,11 @@ First you need to register the core plugin with Tauri:
|
||||
```rust
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_authenticator::init())
|
||||
.setup(|app| {
|
||||
#[cfg(desktop)]
|
||||
app.handle().plugin(tauri_plugin_authenticator::init())?;
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -53,7 +70,7 @@ fn main() {
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { Authenticator } from "tauri-plugin-authenticator-api";
|
||||
import { Authenticator } from "@tauri-apps/plugin-authenticator";
|
||||
|
||||
const auth = new Authenticator();
|
||||
auth.init(); // initialize transports
|
||||
@@ -76,7 +93,7 @@ const r2 = await auth.verifyRegistration(
|
||||
challenge,
|
||||
app,
|
||||
registerResult.registerData,
|
||||
registerResult.clientData
|
||||
registerResult.clientData,
|
||||
);
|
||||
const j2 = JSON.parse(r2);
|
||||
|
||||
@@ -91,7 +108,7 @@ const counter = await auth.verifySignature(
|
||||
signData.signData,
|
||||
clientData,
|
||||
keyHandle,
|
||||
pubkey
|
||||
pubkey,
|
||||
);
|
||||
|
||||
if (counter && counter > 0) {
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
export class Authenticator {
|
||||
async init(): Promise<void> {
|
||||
return await invoke("plugin:authenticator|init_auth");
|
||||
return await window.__TAURI_INVOKE__("plugin:authenticator|init_auth");
|
||||
}
|
||||
|
||||
async register(challenge: string, application: string): Promise<string> {
|
||||
return await invoke("plugin:authenticator|register", {
|
||||
return await window.__TAURI_INVOKE__("plugin:authenticator|register", {
|
||||
timeout: 10000,
|
||||
challenge,
|
||||
application,
|
||||
@@ -17,22 +25,25 @@ export class Authenticator {
|
||||
challenge: string,
|
||||
application: string,
|
||||
registerData: string,
|
||||
clientData: string
|
||||
clientData: string,
|
||||
): Promise<string> {
|
||||
return await invoke("plugin:authenticator|verify_registration", {
|
||||
challenge,
|
||||
application,
|
||||
registerData,
|
||||
clientData,
|
||||
});
|
||||
return await window.__TAURI_INVOKE__(
|
||||
"plugin:authenticator|verify_registration",
|
||||
{
|
||||
challenge,
|
||||
application,
|
||||
registerData,
|
||||
clientData,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async sign(
|
||||
challenge: string,
|
||||
application: string,
|
||||
keyHandle: string
|
||||
keyHandle: string,
|
||||
): Promise<string> {
|
||||
return await invoke("plugin:authenticator|sign", {
|
||||
return await window.__TAURI_INVOKE__("plugin:authenticator|sign", {
|
||||
timeout: 10000,
|
||||
challenge,
|
||||
application,
|
||||
@@ -46,15 +57,18 @@ export class Authenticator {
|
||||
signData: string,
|
||||
clientData: string,
|
||||
keyHandle: string,
|
||||
pubkey: string
|
||||
pubkey: string,
|
||||
): Promise<number> {
|
||||
return await invoke("plugin:authenticator|verify_signature", {
|
||||
challenge,
|
||||
application,
|
||||
signData,
|
||||
clientData,
|
||||
keyHandle,
|
||||
pubkey,
|
||||
});
|
||||
return await window.__TAURI_INVOKE__(
|
||||
"plugin:authenticator|verify_signature",
|
||||
{
|
||||
challenge,
|
||||
application,
|
||||
signData,
|
||||
clientData,
|
||||
keyHandle,
|
||||
pubkey,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tauri-plugin-authenticator-api",
|
||||
"version": "0.0.0",
|
||||
"name": "@tauri-apps/plugin-authenticator",
|
||||
"version": "2.0.0-alpha.1",
|
||||
"description": "Use hardware security-keys in your Tauri App.",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
@@ -25,9 +25,9 @@
|
||||
"LICENSE"
|
||||
],
|
||||
"devDependencies": {
|
||||
"tslib": "^2.5.0"
|
||||
"tslib": "2.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.2.0"
|
||||
"@tauri-apps/api": "2.0.0-alpha.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { createConfig } from "../../shared/rollup.config.mjs";
|
||||
export default createConfig({
|
||||
input: "guest-js/index.ts",
|
||||
pkg: JSON.parse(
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
|
||||
),
|
||||
external: [/^@tauri-apps\/api/],
|
||||
});
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_AUTHENTICATOR__=function(t){"use strict";return t.Authenticator=class{async init(){return await window.__TAURI_INVOKE__("plugin:authenticator|init_auth")}async register(t,i){return await window.__TAURI_INVOKE__("plugin:authenticator|register",{timeout:1e4,challenge:t,application:i})}async verifyRegistration(t,i,a,n){return await window.__TAURI_INVOKE__("plugin:authenticator|verify_registration",{challenge:t,application:i,registerData:a,clientData:n})}async sign(t,i,a){return await window.__TAURI_INVOKE__("plugin:authenticator|sign",{timeout:1e4,challenge:t,application:i,keyHandle:a})}async verifySignature(t,i,a,n,e,_){return await window.__TAURI_INVOKE__("plugin:authenticator|verify_signature",{challenge:t,application:i,signData:a,clientData:n,keyHandle:e,pubkey:_})}},t}({});Object.defineProperty(window.__TAURI__,"authenticator",{value:__TAURI_AUTHENTICATOR__})}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2021 Tauri Programme within The Commons Conservancy
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
// Copyright 2021 Tauri Programme within The Commons Conservancy
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//! [](https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/authenticator)
|
||||
//!
|
||||
//! Use hardware security-keys in your Tauri App.
|
||||
//!
|
||||
//! - Supported platforms: Windows, Linux, FreeBSD, NetBSD, OpenBSD, and macOS.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
|
||||
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
||||
)]
|
||||
#![cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
|
||||
mod auth;
|
||||
mod error;
|
||||
mod u2f;
|
||||
@@ -65,6 +77,7 @@ fn verify_signature(
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
PluginBuilder::new("authenticator")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
init_auth,
|
||||
register,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2021 Tauri Programme within The Commons Conservancy
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../shared/tsconfig.json
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["guest-js/*.ts"]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.2]
|
||||
|
||||
- [`4e2cef9`](https://github.com/tauri-apps/plugins-workspace/commit/4e2cef9b702bbbb9cf4ee17de50791cb21f1b2a4)([#593](https://github.com/tauri-apps/plugins-workspace/pull/593)) Update to alpha.12.
|
||||
|
||||
## \[2.0.0-alpha.1]
|
||||
|
||||
- [`d74fc0a`](https://github.com/tauri-apps/plugins-workspace/commit/d74fc0a097996e90a37be8f57d50b7d1f6ca616f)([#555](https://github.com/tauri-apps/plugins-workspace/pull/555)) Update to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
te to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
@@ -1,18 +1,19 @@
|
||||
[package]
|
||||
name = "tauri-plugin-autostart"
|
||||
version = "0.0.0"
|
||||
version = "2.0.0-alpha.2"
|
||||
description = "Automatically launch your application at startup."
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
rust-version = { workspace = true }
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[package.metadata.docs.rs]
|
||||
features = [ "tauri/dox" ]
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
tauri.workspace = true
|
||||
log.workspace = true
|
||||
thiserror.workspace = true
|
||||
auto-launch = "0.4"
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
log = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
auto-launch = "0.4"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||

|
||||

|
||||
|
||||
Automatically launch your application at startup. Supports Windows, Mac (via AppleScript or Launch Agent), and Linux.
|
||||
|
||||
## Install
|
||||
|
||||
_This plugin requires a Rust version of at least **1.64**_
|
||||
_This plugin requires a Rust version of at least **1.65**_
|
||||
|
||||
There are three general methods of installation that we can recommend.
|
||||
|
||||
@@ -18,6 +18,8 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri-plugin-autostart = "2.0.0-alpha"
|
||||
# alternatively with Git:
|
||||
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
@@ -26,6 +28,13 @@ You can install the JavaScript Guest bindings using your preferred JavaScript pa
|
||||
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
||||
|
||||
```sh
|
||||
pnpm add @tauri-apps/plugin-autostart
|
||||
# or
|
||||
npm add @tauri-apps/plugin-autostart
|
||||
# or
|
||||
yarn add @tauri-apps/plugin-autostart
|
||||
|
||||
# alternatively with Git:
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-autostart#v2
|
||||
# or
|
||||
npm add https://github.com/tauri-apps/tauri-plugin-autostart#v2
|
||||
@@ -53,7 +62,7 @@ fn main() {
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { enable, isEnabled, disable } from "tauri-plugin-autostart-api";
|
||||
import { enable, isEnabled, disable } from "@tauri-apps/plugin-autostart";
|
||||
|
||||
await enable();
|
||||
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
export async function isEnabled(): Promise<boolean> {
|
||||
return await invoke("plugin:autostart|is_enabled");
|
||||
return await window.__TAURI_INVOKE__("plugin:autostart|is_enabled");
|
||||
}
|
||||
|
||||
export async function enable(): Promise<void> {
|
||||
await invoke("plugin:autostart|enable");
|
||||
await window.__TAURI_INVOKE__("plugin:autostart|enable");
|
||||
}
|
||||
|
||||
export async function disable(): Promise<void> {
|
||||
await invoke("plugin:autostart|disable");
|
||||
await window.__TAURI_INVOKE__("plugin:autostart|disable");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tauri-plugin-autostart-api",
|
||||
"version": "0.0.0",
|
||||
"name": "@tauri-apps/plugin-autostart",
|
||||
"version": "2.0.0-alpha.1",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
"Tauri Programme within The Commons Conservancy"
|
||||
@@ -24,9 +24,9 @@
|
||||
"LICENSE"
|
||||
],
|
||||
"devDependencies": {
|
||||
"tslib": "^2.5.0"
|
||||
"tslib": "2.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.2.0"
|
||||
"@tauri-apps/api": "2.0.0-alpha.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { createConfig } from "../../shared/rollup.config.mjs";
|
||||
export default createConfig({
|
||||
input: "guest-js/index.ts",
|
||||
pkg: JSON.parse(
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
|
||||
),
|
||||
external: [/^@tauri-apps\/api/],
|
||||
});
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_AUTOSTART__=function(_){"use strict";return _.disable=async function(){await window.__TAURI_INVOKE__("plugin:autostart|disable")},_.enable=async function(){await window.__TAURI_INVOKE__("plugin:autostart|enable")},_.isEnabled=async function(){return await window.__TAURI_INVOKE__("plugin:autostart|is_enabled")},_}({});Object.defineProperty(window.__TAURI__,"autostart",{value:__TAURI_AUTOSTART__})}
|
||||
@@ -1,7 +1,17 @@
|
||||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//! [](https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/autostart)
|
||||
//!
|
||||
//! Automatically launch your application at startup. Supports Windows, Mac (via AppleScript or Launch Agent), and Linux.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
|
||||
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
||||
)]
|
||||
#![cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
|
||||
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
|
||||
#[cfg(target_os = "macos")]
|
||||
use log::info;
|
||||
@@ -97,6 +107,7 @@ pub fn init<R: Runtime>(
|
||||
args: Option<Vec<&'static str>>,
|
||||
) -> TauriPlugin<R> {
|
||||
Builder::new("autostart")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
|
||||
.setup(move |app, _api| {
|
||||
let mut builder = AutoLaunchBuilder::new();
|
||||
@@ -120,7 +131,7 @@ pub fn init<R: Runtime>(
|
||||
let exe_path = current_exe.canonicalize()?.display().to_string();
|
||||
let parts: Vec<&str> = exe_path.split(".app/").collect();
|
||||
let app_path = if parts.len() == 2 {
|
||||
format!("{}.app", parts.get(0).unwrap().to_string())
|
||||
format!("{}.app", parts.first().unwrap())
|
||||
} else {
|
||||
exe_path
|
||||
};
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../shared/tsconfig.json
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["guest-js/*.ts"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`454428c`](https://github.com/tauri-apps/plugins-workspace/commit/454428cd50ce4962f0bad8e355aebc68af8cc61f)([#536](https://github.com/tauri-apps/plugins-workspace/pull/536)) Initial release.
|
||||
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "tauri-plugin-barcode-scanner"
|
||||
version = "2.0.0-alpha.0"
|
||||
description = "Scan QR codes, EAN-13 and other kinds of barcodes on Android and iOS"
|
||||
edition = { workspace = true }
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
links = "tauri-plugin-barcode-scanner"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
log = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
@@ -0,0 +1,98 @@
|
||||

|
||||
|
||||
Allows your mobile application to use the camera to scan QR codes, EAN-13 and other kinds of barcodes.
|
||||
|
||||
## Install
|
||||
|
||||
_This plugin requires a Rust version of at least **1.64**_
|
||||
|
||||
There are three general methods of installation that we can recommend.
|
||||
|
||||
1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
|
||||
2. Pull sources directly from Github using git tags / revision hashes (most secure)
|
||||
3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
|
||||
|
||||
Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
|
||||
`src-tauri/Cargo.toml`
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri-plugin-barcode-scanner = "2.0.0-alpha"
|
||||
# alternatively with Git:
|
||||
tauri-plugin-barcode-scanner = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
||||
|
||||
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
||||
|
||||
```sh
|
||||
pnpm add @tauri-apps/plugin-barcode-scanner
|
||||
# or
|
||||
npm add @tauri-apps/plugin-barcode-scanner
|
||||
# or
|
||||
yarn add @tauri-apps/plugin-barcode-scanner
|
||||
|
||||
# alternatively with Git:
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-barcode-scanner#v2
|
||||
# or
|
||||
npm add https://github.com/tauri-apps/tauri-plugin-barcode-scanner#v2
|
||||
# or
|
||||
yarn add https://github.com/tauri-apps/tauri-plugin-barcode-scanner#v2
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
First you need to register the core plugin with Tauri:
|
||||
|
||||
`src-tauri/src/main.rs`
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_barcode_scanner::init())
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { scan } from "@tauri-apps/plugin-barcode-scanner";
|
||||
|
||||
// `windowed: true` actually sets the webview to transparent
|
||||
// instead of opening a separate view for the camera
|
||||
// make sure your user interface is ready to show what is underneath with a transparent element
|
||||
scan({ windowed: true, formats: [""] })
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
|
||||
|
||||
## Contributed By
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://crabnebula.dev" target="_blank">
|
||||
<img src="contributors/crabnebula.svg" alt="CrabNebula" width="283">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://impierce.com" target="_blank">
|
||||
<img src="contributors/impierce.svg" alt="Impierce" width="283" height="90">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## License
|
||||
|
||||
Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
|
||||
|
||||
MIT or MIT/Apache 2.0 where applicable.
|
||||
@@ -0,0 +1,56 @@
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "app.tauri.barcodescanner"
|
||||
compileSdk = 32
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 24
|
||||
targetSdk = 32
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation("androidx.core:core-ktx:1.9.0")
|
||||
implementation("androidx.appcompat:appcompat:1.6.0")
|
||||
implementation("com.google.android.material:material:1.7.0")
|
||||
implementation("androidx.camera:camera-core:1.1.0")
|
||||
implementation("androidx.camera:camera-view:1.1.0")
|
||||
implementation("androidx.camera:camera-lifecycle:1.1.0")
|
||||
implementation("androidx.camera:camera-camera2:1.1.0")
|
||||
implementation("androidx.camera:camera-lifecycle:1.1.0")
|
||||
implementation("androidx.camera:camera-view:1.1.0")
|
||||
implementation("com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
implementation("com.journeyapps:zxing-android-embedded:4.3.0") {
|
||||
isTransitive = false
|
||||
}
|
||||
implementation("com.google.zxing:core:3.3.0")
|
||||
implementation(project(":tauri-android"))
|
||||
}
|
||||
Vendored
@@ -0,0 +1,28 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package app.tauri.barcodescanner
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("app.tauri.barcodescanner", appContext.packageName)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:hardwareAccelerated="true">
|
||||
|
||||
<!-- Paste the following line into the AndroidManifest.xml of your project -->
|
||||
<!-- See also: https://capacitorjs.com/docs/plugins/android#manifest -->
|
||||
<!-- <uses-feature android:name="android.hardware.camera" android:required="false" /> -->
|
||||
|
||||
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
</manifest>
|
||||
@@ -0,0 +1,438 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package app.tauri.barcodescanner
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Context.MODE_PRIVATE
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
import android.provider.Settings
|
||||
import android.util.Size
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebView
|
||||
import android.widget.FrameLayout
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.camera.core.Camera
|
||||
import androidx.camera.core.CameraSelector
|
||||
import androidx.camera.core.ImageAnalysis
|
||||
import androidx.camera.core.ImageProxy
|
||||
import androidx.camera.core.Preview
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||
import androidx.camera.view.PreviewView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import app.tauri.Logger
|
||||
import app.tauri.PermissionState
|
||||
import app.tauri.annotation.ActivityCallback
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.Permission
|
||||
import app.tauri.annotation.PermissionCallback
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import app.tauri.plugin.Invoke
|
||||
import app.tauri.plugin.JSArray
|
||||
import app.tauri.plugin.JSObject
|
||||
import app.tauri.plugin.Plugin
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import com.google.mlkit.vision.barcode.BarcodeScannerOptions
|
||||
import com.google.mlkit.vision.barcode.BarcodeScanning
|
||||
import com.google.mlkit.vision.barcode.common.Barcode
|
||||
import com.google.mlkit.vision.common.InputImage
|
||||
import org.json.JSONException
|
||||
import java.util.Collections
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
private const val PERMISSION_ALIAS_CAMERA = "camera"
|
||||
private const val PERMISSION_NAME = Manifest.permission.CAMERA
|
||||
private const val PREFS_PERMISSION_FIRST_TIME_ASKING = "PREFS_PERMISSION_FIRST_TIME_ASKING"
|
||||
|
||||
@TauriPlugin(
|
||||
permissions = [
|
||||
Permission(strings = [Manifest.permission.CAMERA], alias = "camera")
|
||||
]
|
||||
)
|
||||
class BarcodeScannerPlugin(private val activity: Activity) : Plugin(activity),
|
||||
ImageAnalysis.Analyzer {
|
||||
private lateinit var webView: WebView
|
||||
private var previewView: PreviewView? = null
|
||||
private var cameraProviderFuture: ListenableFuture<ProcessCameraProvider>? = null
|
||||
private var cameraProvider: ProcessCameraProvider? = null
|
||||
private var graphicOverlay: GraphicOverlay? = null
|
||||
private var camera: Camera? = null
|
||||
private var vibrator: Vibrator? = null
|
||||
|
||||
private var scannerOptions: BarcodeScannerOptions? = null
|
||||
private var scanner: com.google.mlkit.vision.barcode.BarcodeScanner? = null
|
||||
|
||||
private var requestPermissionResponse: JSObject? = null
|
||||
private var windowed = false
|
||||
|
||||
// declare a map constant for allowed barcode formats
|
||||
private val supportedFormats = supportedFormats()
|
||||
|
||||
private var savedInvoke: Invoke? = null
|
||||
private var webViewBackground: Drawable? = null
|
||||
|
||||
override fun load(webView: WebView) {
|
||||
super.load(webView)
|
||||
this.webView = webView
|
||||
}
|
||||
|
||||
private fun supportedFormats(): Map<String, Int> {
|
||||
val map: MutableMap<String, Int> = HashMap()
|
||||
map["UPC_A"] = Barcode.FORMAT_UPC_A
|
||||
map["UPC_E"] = Barcode.FORMAT_UPC_E
|
||||
map["EAN_8"] = Barcode.FORMAT_EAN_8
|
||||
map["EAN_13"] = Barcode.FORMAT_EAN_13
|
||||
map["CODE_39"] = Barcode.FORMAT_CODE_39
|
||||
map["CODE_93"] = Barcode.FORMAT_CODE_93
|
||||
map["CODE_128"] = Barcode.FORMAT_CODE_128
|
||||
map["CODABAR"] = Barcode.FORMAT_CODABAR
|
||||
map["ITF"] = Barcode.FORMAT_ITF
|
||||
map["AZTEC"] = Barcode.FORMAT_AZTEC
|
||||
map["DATA_MATRIX"] = Barcode.FORMAT_DATA_MATRIX
|
||||
map["PDF_417"] = Barcode.FORMAT_PDF417
|
||||
map["QR_CODE"] = Barcode.FORMAT_QR_CODE
|
||||
return Collections.unmodifiableMap(map)
|
||||
}
|
||||
|
||||
private fun hasCamera(): Boolean {
|
||||
return activity.packageManager
|
||||
.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
|
||||
}
|
||||
|
||||
private fun setupCamera(cameraDirection: String, windowed: Boolean) {
|
||||
activity
|
||||
.runOnUiThread {
|
||||
val previewView = PreviewView(activity)
|
||||
previewView.layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
this.previewView = previewView
|
||||
|
||||
val graphicOverlay = GraphicOverlay(activity)
|
||||
graphicOverlay.layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
this.graphicOverlay = graphicOverlay
|
||||
|
||||
val parent = webView.parent as ViewGroup
|
||||
parent.addView(previewView)
|
||||
parent.addView(graphicOverlay)
|
||||
|
||||
this.windowed = windowed
|
||||
if (windowed) {
|
||||
webView.bringToFront()
|
||||
webViewBackground = webView.background
|
||||
webView.setBackgroundColor(Color.TRANSPARENT)
|
||||
}
|
||||
|
||||
val cameraProviderFuture = ProcessCameraProvider.getInstance(activity)
|
||||
cameraProviderFuture.addListener(
|
||||
{
|
||||
try {
|
||||
val cameraProvider = cameraProviderFuture.get()
|
||||
bindPreview(
|
||||
cameraProvider,
|
||||
if (cameraDirection == "front") CameraSelector.LENS_FACING_FRONT else CameraSelector.LENS_FACING_BACK
|
||||
)
|
||||
this.cameraProvider = cameraProvider
|
||||
} catch (e: InterruptedException) {
|
||||
// ignored
|
||||
} catch (_: ExecutionException) {
|
||||
// ignored
|
||||
}
|
||||
},
|
||||
ContextCompat.getMainExecutor(activity)
|
||||
)
|
||||
this.cameraProviderFuture = cameraProviderFuture
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindPreview(cameraProvider: ProcessCameraProvider, cameraDirection: Int) {
|
||||
activity
|
||||
.runOnUiThread {
|
||||
val preview = Preview.Builder().build()
|
||||
val cameraSelector =
|
||||
CameraSelector.Builder().requireLensFacing(cameraDirection).build()
|
||||
preview.setSurfaceProvider(previewView?.surfaceProvider)
|
||||
val imageAnalysis = ImageAnalysis.Builder()
|
||||
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
||||
.setTargetResolution(Size(1280, 720))
|
||||
.build()
|
||||
imageAnalysis.setAnalyzer(
|
||||
ContextCompat.getMainExecutor(activity),
|
||||
this
|
||||
)
|
||||
|
||||
try {
|
||||
camera = cameraProvider.bindToLifecycle(
|
||||
activity as LifecycleOwner,
|
||||
cameraSelector,
|
||||
preview,
|
||||
imageAnalysis
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun dismantleCamera() {
|
||||
activity
|
||||
.runOnUiThread {
|
||||
if (cameraProvider != null) {
|
||||
cameraProvider?.unbindAll()
|
||||
val parent = webView.parent as ViewGroup
|
||||
parent.removeView(previewView)
|
||||
parent.removeView(graphicOverlay)
|
||||
camera = null
|
||||
previewView = null
|
||||
graphicOverlay = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFormats(invoke: Invoke): List<Int> {
|
||||
val jsFormats = invoke.getArray("formats", JSArray())
|
||||
val formats = ArrayList<Int>()
|
||||
for (i in 0 until jsFormats.length()) {
|
||||
try {
|
||||
val targetedFormat: String = jsFormats.getString(i)
|
||||
val targetedBarcodeFormat =
|
||||
supportedFormats[targetedFormat]
|
||||
if (targetedBarcodeFormat != null) {
|
||||
formats.add(targetedBarcodeFormat)
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
return formats
|
||||
}
|
||||
|
||||
private fun prepare(direction: String, windowed: Boolean) {
|
||||
dismantleCamera()
|
||||
setupCamera(direction, windowed)
|
||||
}
|
||||
|
||||
private fun destroy() {
|
||||
dismantleCamera()
|
||||
savedInvoke = null
|
||||
if (windowed) {
|
||||
if (webViewBackground != null) {
|
||||
webView.background = webViewBackground
|
||||
webViewBackground = null
|
||||
} else {
|
||||
webView.setBackgroundColor(Color.WHITE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun configureCamera(formats: List<Int>) {
|
||||
activity
|
||||
.runOnUiThread {
|
||||
val vibrator =
|
||||
activity.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
this.vibrator = vibrator
|
||||
if (previewView == null) {
|
||||
throw Exception("Something went wrong configuring the BarcodeScanner")
|
||||
}
|
||||
|
||||
if (formats.isNotEmpty()) {
|
||||
val mappedFormats = mapFormats(formats)
|
||||
val options =
|
||||
BarcodeScannerOptions.Builder()
|
||||
.setBarcodeFormats(Barcode.FORMAT_QR_CODE, *mappedFormats).build()
|
||||
scannerOptions = options
|
||||
scanner = BarcodeScanning.getClient(options)
|
||||
} else {
|
||||
val options = BarcodeScannerOptions.Builder()
|
||||
.setBarcodeFormats(Barcode.FORMAT_ALL_FORMATS).build()
|
||||
scannerOptions = options
|
||||
scanner = BarcodeScanning.getClient(options)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun mapFormats(integers: List<Int>): IntArray {
|
||||
val ret = IntArray(integers.size)
|
||||
for (i in ret.indices) {
|
||||
if (integers[i] != Barcode.FORMAT_QR_CODE) ret[i] = integers[i]
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
override fun analyze(image: ImageProxy) {
|
||||
@SuppressLint("UnsafeOptInUsageError") val mediaImage = image.image
|
||||
if (mediaImage != null) {
|
||||
val inputImage =
|
||||
InputImage.fromMediaImage(mediaImage, image.imageInfo.rotationDegrees)
|
||||
scanner
|
||||
?.process(inputImage)
|
||||
?.addOnSuccessListener { barcodes ->
|
||||
if (barcodes.isNotEmpty()) {
|
||||
val barcode = barcodes[0]
|
||||
val bounds = barcode.boundingBox
|
||||
val rawValue = barcode.rawValue ?: ""
|
||||
val rawFormat = barcode.format
|
||||
var format: String? = null
|
||||
|
||||
for (entry in supportedFormats.entries) {
|
||||
if (entry.value == rawFormat) {
|
||||
format = entry.key
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
val s = bounds?.flattenToString()
|
||||
val jsObject = JSObject()
|
||||
jsObject.put("content", rawValue)
|
||||
jsObject.put("format", format)
|
||||
jsObject.put("bounds", s)
|
||||
|
||||
savedInvoke?.resolve(jsObject)
|
||||
destroy()
|
||||
}
|
||||
}
|
||||
?.addOnFailureListener { e ->
|
||||
Logger.error(e.message ?: e.toString())
|
||||
}
|
||||
?.addOnCompleteListener {
|
||||
image.close()
|
||||
mediaImage.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
fun vibrate(invoke: Invoke) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator!!.vibrate(
|
||||
VibrationEffect.createOneShot(
|
||||
50,
|
||||
VibrationEffect.DEFAULT_AMPLITUDE
|
||||
)
|
||||
)
|
||||
}
|
||||
invoke.resolve()
|
||||
}
|
||||
|
||||
@Command
|
||||
fun cancel(invoke: Invoke) {
|
||||
destroy()
|
||||
savedInvoke?.reject("cancelled")
|
||||
invoke.resolve()
|
||||
}
|
||||
|
||||
@Command
|
||||
fun scan(invoke: Invoke) {
|
||||
savedInvoke = invoke
|
||||
if (hasCamera()) {
|
||||
if (getPermissionState("camera") != PermissionState.GRANTED) {
|
||||
throw Exception("No permission to use camera. Did you request it yet?")
|
||||
} else {
|
||||
webViewBackground = null
|
||||
prepare(invoke.getString("cameraDirection", "back"), invoke.getBoolean("windowed", false))
|
||||
configureCamera(getFormats(invoke))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun markFirstPermissionRequest() {
|
||||
val sharedPreference: SharedPreferences =
|
||||
activity.getSharedPreferences(PREFS_PERMISSION_FIRST_TIME_ASKING, MODE_PRIVATE)
|
||||
sharedPreference.edit().putBoolean(PERMISSION_NAME, false).apply()
|
||||
}
|
||||
|
||||
private fun firstPermissionRequest(): Boolean {
|
||||
return activity.getSharedPreferences(PREFS_PERMISSION_FIRST_TIME_ASKING, MODE_PRIVATE)
|
||||
.getBoolean(PERMISSION_NAME, true)
|
||||
}
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
@PermissionCallback
|
||||
fun cameraPermissionCallback(invoke: Invoke) {
|
||||
if (requestPermissionResponse == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val requestPermissionResponse = requestPermissionResponse!!
|
||||
|
||||
val granted = getPermissionState(PERMISSION_ALIAS_CAMERA) === PermissionState.GRANTED
|
||||
|
||||
if (granted) {
|
||||
requestPermissionResponse.put(PERMISSION_ALIAS_CAMERA, PermissionState.GRANTED)
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (!activity.shouldShowRequestPermissionRationale(PERMISSION_NAME)) {
|
||||
requestPermissionResponse.put(PERMISSION_ALIAS_CAMERA, PermissionState.DENIED)
|
||||
}
|
||||
} else {
|
||||
requestPermissionResponse.put(PERMISSION_ALIAS_CAMERA, PermissionState.GRANTED)
|
||||
}
|
||||
}
|
||||
|
||||
invoke.resolve(requestPermissionResponse)
|
||||
this.requestPermissionResponse = null
|
||||
}
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
@Command
|
||||
override fun requestPermissions(invoke: Invoke) {
|
||||
val requestPermissionResponse = JSObject()
|
||||
this.requestPermissionResponse = requestPermissionResponse
|
||||
if (getPermissionState(PERMISSION_ALIAS_CAMERA) === PermissionState.GRANTED) {
|
||||
requestPermissionResponse.put(PERMISSION_ALIAS_CAMERA, PermissionState.GRANTED)
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (firstPermissionRequest() || activity.shouldShowRequestPermissionRationale(
|
||||
PERMISSION_NAME
|
||||
)
|
||||
) {
|
||||
markFirstPermissionRequest()
|
||||
requestPermissionForAlias(
|
||||
PERMISSION_ALIAS_CAMERA,
|
||||
invoke,
|
||||
"cameraPermissionCallback"
|
||||
)
|
||||
return
|
||||
} else {
|
||||
requestPermissionResponse.put(PERMISSION_ALIAS_CAMERA, PermissionState.DENIED)
|
||||
}
|
||||
} else {
|
||||
requestPermissionResponse.put(PERMISSION_ALIAS_CAMERA, PermissionState.GRANTED)
|
||||
}
|
||||
}
|
||||
invoke.resolve(requestPermissionResponse)
|
||||
}
|
||||
|
||||
@Command
|
||||
fun openAppSettings(invoke: Invoke) {
|
||||
val intent = Intent(
|
||||
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
Uri.fromParts("package", activity.packageName, null)
|
||||
)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivityForResult(invoke, intent, "openSettingsResult")
|
||||
}
|
||||
|
||||
@ActivityCallback
|
||||
private fun openSettingsResult(invoke: Invoke, result: ActivityResult) {
|
||||
invoke.resolve()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package app.tauri.barcodescanner
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Paint
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import com.google.android.gms.common.internal.Preconditions
|
||||
|
||||
class GraphicOverlay: View {
|
||||
private val lock = Any()
|
||||
private val graphics: MutableList<Graphic> = ArrayList()
|
||||
|
||||
private val transformationMatrix = Matrix()
|
||||
|
||||
private var imageWidth = 0
|
||||
private var imageHeight = 0
|
||||
|
||||
private var scaleFactor = 1.0f
|
||||
|
||||
private var postScaleWidthOffset = 0f
|
||||
|
||||
private var postScaleHeightOffset = 0f
|
||||
private var isImageFlipped = false
|
||||
private var needUpdateTransformation = true
|
||||
|
||||
abstract class Graphic(private val overlay: GraphicOverlay) {
|
||||
abstract fun draw(canvas: Canvas?)
|
||||
protected fun drawRect(
|
||||
canvas: Canvas,
|
||||
left: Float,
|
||||
top: Float,
|
||||
right: Float,
|
||||
bottom: Float,
|
||||
paint: Paint?
|
||||
) {
|
||||
canvas.drawRect(left, top, right, bottom, paint!!)
|
||||
}
|
||||
|
||||
protected fun drawText(canvas: Canvas, text: String?, x: Float, y: Float, paint: Paint?) {
|
||||
canvas.drawText(text!!, x, y, paint!!)
|
||||
}
|
||||
|
||||
/** Adjusts the supplied value from the image scale to the view scale. */
|
||||
fun scale(imagePixel: Float): Float {
|
||||
return imagePixel * overlay.scaleFactor
|
||||
}
|
||||
|
||||
val applicationContext
|
||||
get() = overlay.context.applicationContext
|
||||
|
||||
fun isImageFlipped(): Boolean {
|
||||
return overlay.isImageFlipped
|
||||
}
|
||||
|
||||
fun translateX(x: Float): Float {
|
||||
return if (overlay.isImageFlipped) {
|
||||
overlay.width - (scale(x) - overlay.postScaleWidthOffset)
|
||||
} else {
|
||||
scale(x) - overlay.postScaleWidthOffset
|
||||
}
|
||||
}
|
||||
|
||||
fun translateY(y: Float): Float {
|
||||
return scale(y) - overlay.postScaleHeightOffset
|
||||
}
|
||||
|
||||
fun getTransformationMatrix(): Matrix {
|
||||
return overlay.transformationMatrix
|
||||
}
|
||||
|
||||
fun postInvalidate() {
|
||||
overlay.postInvalidate()
|
||||
}
|
||||
|
||||
fun updatePaintColorByZValue(
|
||||
paint: Paint,
|
||||
canvas: Canvas,
|
||||
visualizeZ: Boolean,
|
||||
rescaleZForVisualization: Boolean,
|
||||
zInImagePixel: Float,
|
||||
zMin: Float,
|
||||
zMax: Float
|
||||
) {
|
||||
if (!visualizeZ) {
|
||||
return
|
||||
}
|
||||
|
||||
val zLowerBoundInScreenPixel: Float
|
||||
val zUpperBoundInScreenPixel: Float
|
||||
if (rescaleZForVisualization) {
|
||||
zLowerBoundInScreenPixel = (-0.001f).coerceAtMost(scale(zMin))
|
||||
zUpperBoundInScreenPixel = 0.001f.coerceAtLeast(scale(zMax))
|
||||
} else {
|
||||
val defaultRangeFactor = 1f
|
||||
zLowerBoundInScreenPixel = -defaultRangeFactor * canvas.width
|
||||
zUpperBoundInScreenPixel = defaultRangeFactor * canvas.width
|
||||
}
|
||||
val zInScreenPixel = scale(zInImagePixel)
|
||||
if (zInScreenPixel < 0) {
|
||||
val v = (zInScreenPixel / zLowerBoundInScreenPixel * 255).toInt()
|
||||
paint.setARGB(0, 0, 255, 0)
|
||||
} else {
|
||||
val v = (zInScreenPixel / zUpperBoundInScreenPixel * 255).toInt()
|
||||
paint.setARGB(0, 0, 255, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constructor(context: Context): super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet): super(context, attrs) {
|
||||
addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
||||
needUpdateTransformation = true
|
||||
}
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
synchronized(lock) { graphics.clear() }
|
||||
postInvalidate()
|
||||
}
|
||||
|
||||
fun add(graphic: Graphic) {
|
||||
synchronized(lock) { graphics.add(graphic) }
|
||||
}
|
||||
|
||||
fun remove(graphic: Graphic) {
|
||||
synchronized(lock) { graphics.remove(graphic) }
|
||||
postInvalidate()
|
||||
}
|
||||
|
||||
fun setImageSourceInfo(imageWidth: Int, imageHeight: Int, isFlipped: Boolean) {
|
||||
Preconditions.checkState(imageWidth > 0, "image width must be positive")
|
||||
Preconditions.checkState(imageHeight > 0, "image height must be positive")
|
||||
synchronized(lock) {
|
||||
this.imageWidth = imageWidth
|
||||
this.imageHeight = imageHeight
|
||||
isImageFlipped = isFlipped
|
||||
needUpdateTransformation = true
|
||||
}
|
||||
postInvalidate()
|
||||
}
|
||||
|
||||
fun getImageWidth(): Int {
|
||||
return imageWidth
|
||||
}
|
||||
|
||||
fun getImageHeight(): Int {
|
||||
return imageHeight
|
||||
}
|
||||
|
||||
private fun updateTransformationIfNeeded() {
|
||||
if (!needUpdateTransformation || imageWidth <= 0 || imageHeight <= 0) {
|
||||
return
|
||||
}
|
||||
val viewAspectRatio = width.toFloat() / height
|
||||
val imageAspectRatio = imageWidth.toFloat() / imageHeight
|
||||
postScaleWidthOffset = 0f
|
||||
postScaleHeightOffset = 0f
|
||||
if (viewAspectRatio > imageAspectRatio) {
|
||||
// The image needs to be vertically cropped to be displayed in this view.
|
||||
scaleFactor = width.toFloat() / imageWidth
|
||||
postScaleHeightOffset = (width.toFloat() / imageAspectRatio - height) / 2
|
||||
} else {
|
||||
// The image needs to be horizontally cropped to be displayed in this view.
|
||||
scaleFactor = height.toFloat() / imageHeight
|
||||
postScaleWidthOffset = (height.toFloat() * imageAspectRatio - width) / 2
|
||||
}
|
||||
transformationMatrix.reset()
|
||||
transformationMatrix.setScale(scaleFactor, scaleFactor)
|
||||
transformationMatrix.postTranslate(-postScaleWidthOffset, -postScaleHeightOffset)
|
||||
if (isImageFlipped) {
|
||||
transformationMatrix.postScale(-1f, 1f, width / 2f, height / 2f)
|
||||
}
|
||||
needUpdateTransformation = false
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas?) {
|
||||
super.onDraw(canvas)
|
||||
synchronized(lock) {
|
||||
updateTransformationIfNeeded()
|
||||
for (graphic in graphics) {
|
||||
graphic.draw(canvas)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package app.tauri.barcodescanner
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
@@ -1,3 +1,7 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::process::exit;
|
||||
|
||||
fn main() {
|
||||
@@ -0,0 +1,31 @@
|
||||
<svg class="crabnebula-logo" width="100%" height="100%" viewBox="0 0 1204 210" version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xml:space="preserve" xmlns:serif="http://www.serif.com/"
|
||||
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||
<style>
|
||||
.crabnebula-logo path,
|
||||
.crabnebula-logo rect {
|
||||
fill: #001e42;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.crabnebula-logo path, .crabnebula-logo rect {
|
||||
fill: #fff;
|
||||
}
|
||||
}
|
||||
html[data-color-mode="dark"] .crabnebula-logo path,
|
||||
html[data-color-mode="dark"] .crabnebula-logo rect {
|
||||
fill: #fff;
|
||||
}
|
||||
</style>
|
||||
<path d="M351.903,162.334C344.288,162.334 337.123,160.881 330.41,157.975C323.696,155.069 317.834,151.11 312.824,146.099C307.914,141.089 304.006,135.276 301.101,128.662C298.195,121.948 296.742,114.783 296.742,107.167C296.742,99.55 298.195,92.435 301.101,85.821C304.006,79.107 307.914,73.244 312.824,68.234C317.834,63.223 323.696,59.265 330.41,56.358C337.123,53.452 344.288,51.999 351.903,51.999C357.414,51.999 362.675,52.701 367.685,54.103C372.795,55.507 377.455,57.511 381.663,60.116C385.972,62.622 389.83,65.678 393.237,69.286C396.644,72.793 399.499,76.752 401.804,81.161L380.762,92.586C377.756,87.174 373.848,82.915 369.038,79.808C364.328,76.702 358.617,75.148 351.903,75.148C347.494,75.148 343.386,76 339.578,77.704C335.871,79.407 332.614,81.762 329.809,84.769C327.003,87.675 324.798,91.082 323.195,94.991C321.592,98.799 320.79,102.857 320.79,107.167C320.79,111.476 321.592,115.584 323.195,119.493C324.798,123.301 327.003,126.708 329.809,129.715C332.614,132.621 335.871,134.926 339.578,136.629C343.386,138.333 347.494,139.185 351.903,139.185C358.617,139.185 364.328,137.631 369.038,134.525C373.848,131.418 377.756,127.159 380.762,121.748L401.804,133.172C399.499,137.581 396.644,141.59 393.237,145.198C389.83,148.705 385.972,151.762 381.663,154.367C377.455,156.872 372.795,158.827 367.685,160.23C362.675,161.633 357.414,162.334 351.903,162.334Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M413.821,85.37L436.517,85.37L436.517,96.644C437.72,93.337 439.924,90.481 443.131,88.076C446.437,85.671 450.195,84.468 454.403,84.468C455.506,84.468 456.658,84.518 457.86,84.619C459.063,84.719 460.366,84.969 461.768,85.37L461.768,108.369C460.065,107.768 458.412,107.317 456.808,107.016C455.205,106.716 453.502,106.565 451.698,106.565C446.788,106.565 443.03,108.269 440.425,111.676C437.82,115.083 436.517,119.493 436.517,124.904L436.517,160.53L413.821,160.53L413.821,85.37Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M502.161,162.184C497.251,162.184 492.642,161.132 488.333,159.027C484.125,156.923 480.467,154.117 477.361,150.609C474.255,147.001 471.8,142.843 469.996,138.133C468.193,133.322 467.291,128.261 467.291,122.95C467.291,117.639 468.193,112.628 469.996,107.918C471.8,103.108 474.255,98.949 477.361,95.442C480.467,91.834 484.125,88.978 488.333,86.873C492.642,84.769 497.251,83.717 502.161,83.717C504.666,83.717 506.971,84.017 509.075,84.619C511.28,85.12 513.234,85.821 514.937,86.723C516.741,87.625 518.244,88.627 519.446,89.729C520.749,90.832 521.801,91.884 522.603,92.886L522.603,85.37L545.299,85.37L545.299,160.53L522.603,160.53L522.603,153.014C521.801,154.016 520.749,155.069 519.446,156.171C518.244,157.273 516.741,158.275 514.937,159.177C513.234,160.079 511.28,160.781 509.075,161.282C506.971,161.883 504.666,162.184 502.161,162.184ZM507.272,141.59C512.382,141.59 516.49,139.836 519.597,136.329C522.803,132.821 524.406,128.362 524.406,122.95C524.406,117.539 522.803,113.079 519.597,109.572C516.49,106.064 512.382,104.31 507.272,104.31C502.161,104.31 498.003,106.064 494.796,109.572C491.69,113.079 490.137,117.539 490.137,122.95C490.137,128.362 491.69,132.821 494.796,136.329C498.003,139.836 502.161,141.59 507.272,141.59Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M607.116,162.184C604.611,162.184 602.256,161.883 600.051,161.282C597.947,160.781 595.993,160.079 594.19,159.177C592.486,158.275 590.983,157.273 589.681,156.171C588.378,155.069 587.376,154.016 586.674,153.014L586.674,160.53L563.979,160.53L563.979,47.79L586.674,47.79L586.674,92.886C587.376,91.884 588.378,90.832 589.681,89.729C590.983,88.627 592.486,87.625 594.19,86.723C595.993,85.821 597.947,85.12 600.051,84.619C602.256,84.017 604.611,83.717 607.116,83.717C612.026,83.717 616.585,84.769 620.793,86.873C625.102,88.978 628.81,91.834 631.916,95.442C635.022,98.949 637.477,103.108 639.281,107.918C641.084,112.628 641.986,117.639 641.986,122.95C641.986,128.261 641.084,133.322 639.281,138.133C637.477,142.843 635.022,147.001 631.916,150.609C628.81,154.117 625.102,156.923 620.793,159.027C616.585,161.132 612.026,162.184 607.116,162.184ZM602.005,141.59C607.116,141.59 611.224,139.836 614.33,136.329C617.537,132.821 619.14,128.362 619.14,122.95C619.14,117.539 617.537,113.079 614.33,109.572C611.224,106.064 607.116,104.31 602.005,104.31C596.895,104.31 592.737,106.064 589.53,109.572C586.424,113.079 584.871,117.539 584.871,122.95C584.871,128.362 586.424,132.821 589.53,136.329C592.737,139.836 596.895,141.59 602.005,141.59Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M732.106,160.53L680.101,94.54L680.101,160.53L656.203,160.53L656.203,53.803L676.795,53.803L728.649,119.793L728.649,53.803L752.698,53.803L752.698,160.53L732.106,160.53Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M806.852,162.184C801.341,162.184 796.13,161.282 791.22,159.478C786.411,157.674 782.202,155.069 778.595,151.661C774.988,148.254 772.132,144.145 770.028,139.335C767.923,134.425 766.871,128.963 766.871,122.95C766.871,117.338 767.823,112.177 769.727,107.467C771.731,102.657 774.487,98.498 777.994,94.991C781.601,91.483 785.809,88.727 790.619,86.723C795.429,84.719 800.69,83.717 806.401,83.717C811.311,83.717 816.021,84.518 820.53,86.122C825.139,87.625 829.147,89.93 832.554,93.036C835.961,96.043 838.666,99.851 840.67,104.461C842.775,108.97 843.827,114.282 843.827,120.395C843.827,121.397 843.777,122.549 843.677,123.852C843.677,125.055 843.576,126.558 843.376,128.362L788.816,128.362C789.517,132.871 791.671,136.228 795.279,138.433C798.886,140.538 802.844,141.59 807.153,141.59C811.562,141.59 815.319,140.738 818.425,139.034C821.632,137.231 823.937,135.226 825.339,133.022L842.173,145.649C838.666,150.659 833.857,154.668 827.744,157.674C821.732,160.681 814.768,162.184 806.852,162.184ZM821.281,113.48C820.279,109.471 818.275,106.615 815.269,104.912C812.263,103.108 809.107,102.206 805.8,102.206C804.096,102.206 802.393,102.406 800.69,102.807C798.986,103.208 797.383,103.859 795.88,104.761C794.377,105.663 793.024,106.816 791.822,108.219C790.719,109.622 789.918,111.376 789.417,113.48L821.281,113.48Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M901.265,162.184C898.76,162.184 896.405,161.883 894.201,161.282C892.097,160.781 890.143,160.079 888.339,159.177C886.636,158.275 885.133,157.273 883.83,156.171C882.527,155.069 881.525,154.016 880.824,153.014L880.824,160.53L858.128,160.53L858.128,47.79L880.824,47.79L880.824,92.886C881.525,91.884 882.527,90.832 883.83,89.729C885.133,88.627 886.636,87.625 888.339,86.723C890.143,85.821 892.097,85.12 894.201,84.619C896.405,84.017 898.76,83.717 901.265,83.717C906.175,83.717 910.734,84.769 914.943,86.873C919.252,88.978 922.959,91.834 926.065,95.442C929.172,98.949 931.627,103.108 933.43,107.918C935.234,112.628 936.136,117.639 936.136,122.95C936.136,128.261 935.234,133.322 933.43,138.133C931.627,142.843 929.172,147.001 926.065,150.609C922.959,154.117 919.252,156.923 914.943,159.027C910.734,161.132 906.175,162.184 901.265,162.184ZM896.155,141.59C901.265,141.59 905.374,139.836 908.48,136.329C911.686,132.821 913.29,128.362 913.29,122.95C913.29,117.539 911.686,113.079 908.48,109.572C905.374,106.064 901.265,104.31 896.155,104.31C891.045,104.31 886.886,106.064 883.68,109.572C880.573,113.079 879.02,117.539 879.02,122.95C879.02,128.362 880.573,132.821 883.68,136.329C886.886,139.836 891.045,141.59 896.155,141.59Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M977.812,162.184C968.493,162.184 961.429,159.077 956.619,152.864C951.81,146.651 949.405,138.433 949.405,128.211L949.405,85.37L972.101,85.37L972.101,124.303C972.101,129.815 972.952,134.074 974.656,137.08C976.459,140.087 979.466,141.59 983.674,141.59C987.983,141.59 991.39,140.037 993.895,136.93C996.5,133.823 997.803,128.813 997.803,121.898L997.803,85.37L1020.5,85.37L1020.5,160.53L997.803,160.53L997.803,152.864C995.999,155.469 993.444,157.674 990.137,159.478C986.83,161.282 982.722,162.184 977.812,162.184Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<rect x="1039.11" y="47.79" width="22.701" height="112.74" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M1110.86,162.184C1105.95,162.184 1101.34,161.132 1097.03,159.027C1092.83,156.923 1089.17,154.117 1086.06,150.609C1082.96,147.001 1080.5,142.843 1078.7,138.133C1076.89,133.322 1075.99,128.261 1075.99,122.95C1075.99,117.639 1076.89,112.628 1078.7,107.918C1080.5,103.108 1082.96,98.949 1086.06,95.442C1089.17,91.834 1092.83,88.978 1097.03,86.873C1101.34,84.769 1105.95,83.717 1110.86,83.717C1113.37,83.717 1115.67,84.017 1117.78,84.619C1119.98,85.12 1121.94,85.821 1123.64,86.723C1125.44,87.625 1126.95,88.627 1128.15,89.729C1129.45,90.832 1130.5,91.884 1131.3,92.886L1131.3,85.37L1154,85.37L1154,160.53L1131.3,160.53L1131.3,153.014C1130.5,154.016 1129.45,155.069 1128.15,156.171C1126.95,157.273 1125.44,158.275 1123.64,159.177C1121.94,160.079 1119.98,160.781 1117.78,161.282C1115.67,161.883 1113.37,162.184 1110.86,162.184ZM1115.97,141.59C1121.08,141.59 1125.19,139.836 1128.3,136.329C1131.5,132.821 1133.11,128.362 1133.11,122.95C1133.11,117.539 1131.5,113.079 1128.3,109.572C1125.19,106.064 1121.08,104.31 1115.97,104.31C1110.86,104.31 1106.7,106.064 1103.5,109.572C1100.39,113.079 1098.84,117.539 1098.84,122.95C1098.84,128.362 1100.39,132.821 1103.5,136.329C1106.7,139.836 1110.86,141.59 1115.97,141.59Z" style="fill-rule:nonzero;stroke:black;stroke-width:0.55px;"/>
|
||||
<path d="M146.48,54.585C119.724,89.866 119.878,134.941 146.826,155.264C153.908,160.605 162.136,163.705 170.903,164.732C146.032,184.934 117.382,191.203 98.037,178.045C71.507,160 72.524,112.249 100.309,71.391C123.51,37.273 158.039,18.749 184.247,24.072C170.404,30.195 157.116,40.561 146.48,54.585ZM181.638,99.643C169.141,111.453 154.859,119.304 142.801,121.916C149.921,147.367 177.29,149.323 177.29,149.323C177.29,149.323 193.578,145.578 205.877,117.941C216.005,95.183 215.122,71.668 204.914,59.7C204.065,71.267 195.731,86.324 181.638,99.643Z" style="stroke:black;stroke-width:0.55px;"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 11 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,75 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
|
||||
export type PermissionState = "granted" | "denied" | "prompt";
|
||||
|
||||
export enum Format {
|
||||
QRCode = "QR_CODE",
|
||||
UPC_A = "UPC_A",
|
||||
UPC_E = "UPC_E",
|
||||
EAN8 = "EAN_8",
|
||||
EAN13 = "EAN_13",
|
||||
Code39 = "CODE_39",
|
||||
Code93 = "CODE_93",
|
||||
Code128 = "CODE_128",
|
||||
Codabar = "CODABAR",
|
||||
ITF = "ITF",
|
||||
Aztec = "AZTEC",
|
||||
DataMatrix = "DATA_MATRIX",
|
||||
PDF417 = "PDF_417",
|
||||
}
|
||||
|
||||
export interface ScanOptions {
|
||||
cameraDirection?: "back" | "front";
|
||||
formats?: Format[];
|
||||
windowed?: boolean;
|
||||
}
|
||||
|
||||
export interface Scanned {
|
||||
content: string;
|
||||
format: Format;
|
||||
bounds: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start scanning.
|
||||
* @param options
|
||||
*/
|
||||
export async function scan(options?: ScanOptions): Promise<Scanned> {
|
||||
return await invoke("plugin:barcodeScanner|scan", { ...options });
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the current scan process.
|
||||
*/
|
||||
export async function cancel(): Promise<void> {
|
||||
return await invoke("plugin:barcodeScanner|cancel");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get permission state.
|
||||
*/
|
||||
export async function checkPermissions(): Promise<PermissionState> {
|
||||
return await invoke<{ camera: PermissionState }>(
|
||||
"plugin:barcodeScanner|checkPermissions",
|
||||
).then((r) => r.camera);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request permissions to use the camera.
|
||||
*/
|
||||
export async function requestPermissions(): Promise<PermissionState> {
|
||||
return await invoke<{ camera: PermissionState }>(
|
||||
"plugin:barcodeScanner|requestPermissions",
|
||||
).then((r) => r.camera);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open application settings. Useful if permission was denied and the user must manually enable it.
|
||||
*/
|
||||
export async function openAppSettings(): Promise<void> {
|
||||
return await invoke("plugin:barcodeScanner|openAppSettings");
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// swift-tools-version:5.3
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "tauri-plugin-barcode-scanner",
|
||||
platforms: [
|
||||
.iOS(.v13)
|
||||
],
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "tauri-plugin-barcode-scanner",
|
||||
type: .static,
|
||||
targets: ["tauri-plugin-barcode-scanner"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(name: "Tauri", path: "../.tauri/tauri-api")
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||
.target(
|
||||
name: "tauri-plugin-barcode-scanner",
|
||||
dependencies: [
|
||||
.byName(name: "Tauri")
|
||||
],
|
||||
path: "Sources")
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
# Tauri Plugin Barcode Scanner
|
||||
|
||||
A description of this package.
|
||||
@@ -0,0 +1,300 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import AVFoundation
|
||||
import Tauri
|
||||
import UIKit
|
||||
import WebKit
|
||||
|
||||
enum SupportedFormat: String, CaseIterable {
|
||||
// UPC_A not supported
|
||||
case UPC_E
|
||||
case EAN_8
|
||||
case EAN_13
|
||||
case CODE_39
|
||||
case CODE_93
|
||||
case CODE_128
|
||||
// CODABAR not supported
|
||||
case ITF
|
||||
case AZTEC
|
||||
case DATA_MATRIX
|
||||
case PDF_417
|
||||
case QR_CODE
|
||||
|
||||
var value: AVMetadataObject.ObjectType {
|
||||
switch self {
|
||||
case .UPC_E: return AVMetadataObject.ObjectType.upce
|
||||
case .EAN_8: return AVMetadataObject.ObjectType.ean8
|
||||
case .EAN_13: return AVMetadataObject.ObjectType.ean13
|
||||
case .CODE_39: return AVMetadataObject.ObjectType.code39
|
||||
case .CODE_93: return AVMetadataObject.ObjectType.code93
|
||||
case .CODE_128: return AVMetadataObject.ObjectType.code128
|
||||
case .ITF: return AVMetadataObject.ObjectType.interleaved2of5
|
||||
case .AZTEC: return AVMetadataObject.ObjectType.aztec
|
||||
case .DATA_MATRIX: return AVMetadataObject.ObjectType.dataMatrix
|
||||
case .PDF_417: return AVMetadataObject.ObjectType.pdf417
|
||||
case .QR_CODE: return AVMetadataObject.ObjectType.qr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum CaptureError: Error {
|
||||
case backCameraUnavailable
|
||||
case frontCameraUnavailable
|
||||
case couldNotCaptureInput(error: NSError)
|
||||
}
|
||||
|
||||
class BarcodeScannerPlugin: Plugin, AVCaptureMetadataOutputObjectsDelegate {
|
||||
var webView: WKWebView!
|
||||
var cameraView: CameraView!
|
||||
var captureSession: AVCaptureSession?
|
||||
var captureVideoPreviewLayer: AVCaptureVideoPreviewLayer?
|
||||
var metaOutput: AVCaptureMetadataOutput?
|
||||
|
||||
var currentCamera = 0
|
||||
var frontCamera: AVCaptureDevice?
|
||||
var backCamera: AVCaptureDevice?
|
||||
|
||||
var isScanning = false
|
||||
|
||||
var windowed = false
|
||||
var previousBackgroundColor: UIColor? = UIColor.white
|
||||
|
||||
var invoke: Invoke? = nil
|
||||
|
||||
var scanFormats = [AVMetadataObject.ObjectType]()
|
||||
|
||||
public override func load(webview: WKWebView) {
|
||||
self.webView = webview
|
||||
loadCamera()
|
||||
}
|
||||
|
||||
private func loadCamera() {
|
||||
cameraView = CameraView(
|
||||
frame: CGRect(
|
||||
x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
|
||||
cameraView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
}
|
||||
|
||||
public func metadataOutput(
|
||||
_ captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject],
|
||||
from connection: AVCaptureConnection
|
||||
) {
|
||||
if metadataObjects.count == 0 || !self.isScanning {
|
||||
// while nothing is detected, or if scanning is false, do nothing.
|
||||
return
|
||||
}
|
||||
|
||||
let found = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
|
||||
if scanFormats.contains(found.type) {
|
||||
var jsObject: JsonObject = [:]
|
||||
|
||||
jsObject["format"] = formatStringFromMetadata(found.type)
|
||||
if found.stringValue != nil {
|
||||
jsObject["content"] = found.stringValue
|
||||
}
|
||||
|
||||
invoke?.resolve(jsObject)
|
||||
destroy()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private func setupCamera(direction: String, windowed: Bool) {
|
||||
do {
|
||||
var cameraDirection = direction
|
||||
cameraView.backgroundColor = UIColor.clear
|
||||
if windowed {
|
||||
webView.superview?.insertSubview(cameraView, belowSubview: webView)
|
||||
} else {
|
||||
webView.superview?.insertSubview(cameraView, aboveSubview: webView)
|
||||
}
|
||||
|
||||
let availableVideoDevices = discoverCaptureDevices()
|
||||
for device in availableVideoDevices {
|
||||
if device.position == AVCaptureDevice.Position.back {
|
||||
backCamera = device
|
||||
} else if device.position == AVCaptureDevice.Position.front {
|
||||
frontCamera = device
|
||||
}
|
||||
}
|
||||
|
||||
// older iPods have no back camera
|
||||
if cameraDirection == "back" {
|
||||
if backCamera == nil {
|
||||
cameraDirection = "front"
|
||||
}
|
||||
} else {
|
||||
if frontCamera == nil {
|
||||
cameraDirection = "back"
|
||||
}
|
||||
}
|
||||
|
||||
let input: AVCaptureDeviceInput
|
||||
input = try createCaptureDeviceInput(
|
||||
cameraDirection: cameraDirection, backCamera: backCamera, frontCamera: frontCamera)
|
||||
captureSession = AVCaptureSession()
|
||||
captureSession!.addInput(input)
|
||||
metaOutput = AVCaptureMetadataOutput()
|
||||
captureSession!.addOutput(metaOutput!)
|
||||
metaOutput!.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
|
||||
captureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
|
||||
cameraView.addPreviewLayer(captureVideoPreviewLayer)
|
||||
|
||||
self.windowed = windowed
|
||||
if windowed {
|
||||
self.previousBackgroundColor = self.webView.backgroundColor
|
||||
self.webView.isOpaque = false
|
||||
self.webView.backgroundColor = UIColor.clear
|
||||
self.webView.scrollView.backgroundColor = UIColor.clear
|
||||
}
|
||||
} catch CaptureError.backCameraUnavailable {
|
||||
//
|
||||
} catch CaptureError.frontCameraUnavailable {
|
||||
//
|
||||
} catch CaptureError.couldNotCaptureInput {
|
||||
//
|
||||
} catch {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
private func dismantleCamera() {
|
||||
if self.captureSession != nil {
|
||||
self.captureSession!.stopRunning()
|
||||
self.cameraView.removePreviewLayer()
|
||||
self.captureVideoPreviewLayer = nil
|
||||
self.metaOutput = nil
|
||||
self.captureSession = nil
|
||||
self.frontCamera = nil
|
||||
self.backCamera = nil
|
||||
}
|
||||
|
||||
self.isScanning = false
|
||||
}
|
||||
|
||||
private func destroy() {
|
||||
dismantleCamera()
|
||||
invoke = nil
|
||||
if windowed {
|
||||
let backgroundColor = previousBackgroundColor ?? UIColor.white
|
||||
webView.isOpaque = true
|
||||
webView.backgroundColor = backgroundColor
|
||||
webView.scrollView.backgroundColor = backgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
private func getPermissionState() -> String {
|
||||
var permissionState: String
|
||||
|
||||
switch AVCaptureDevice.authorizationStatus(for: .video) {
|
||||
case .authorized:
|
||||
permissionState = "granted"
|
||||
case .denied:
|
||||
permissionState = "denied"
|
||||
default:
|
||||
permissionState = "prompt"
|
||||
}
|
||||
|
||||
return permissionState
|
||||
}
|
||||
|
||||
@objc override func checkPermissions(_ invoke: Invoke) {
|
||||
let permissionState = getPermissionState()
|
||||
invoke.resolve(["camera": permissionState])
|
||||
}
|
||||
|
||||
@objc override func requestPermissions(_ invoke: Invoke) {
|
||||
let state = getPermissionState()
|
||||
if state == "prompt" {
|
||||
AVCaptureDevice.requestAccess(for: .video) { (authorized) in
|
||||
invoke.resolve(["camera": authorized ? "granted" : "denied"])
|
||||
}
|
||||
} else {
|
||||
invoke.resolve(["camera": state])
|
||||
}
|
||||
}
|
||||
|
||||
@objc func openAppSettings(_ invoke: Invoke) {
|
||||
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
|
||||
return
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if UIApplication.shared.canOpenURL(settingsUrl) {
|
||||
UIApplication.shared.open(
|
||||
settingsUrl,
|
||||
completionHandler: { (success) in
|
||||
invoke.resolve()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func runScanner(_ invoke: Invoke) {
|
||||
scanFormats = [AVMetadataObject.ObjectType]()
|
||||
|
||||
if (invoke.data["formats"]) != nil {
|
||||
let _scanFormats = invoke.getArray("formats", String.self)
|
||||
|
||||
if _scanFormats != nil && _scanFormats?.count ?? 0 > 0 {
|
||||
_scanFormats?.forEach { targetedFormat in
|
||||
if let value = SupportedFormat(rawValue: targetedFormat)?.value {
|
||||
scanFormats.append(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if scanFormats.count == 0 {
|
||||
for supportedFormat in SupportedFormat.allCases {
|
||||
scanFormats.append(supportedFormat.value)
|
||||
}
|
||||
}
|
||||
|
||||
self.metaOutput!.metadataObjectTypes = self.scanFormats
|
||||
self.captureSession!.startRunning()
|
||||
|
||||
self.isScanning = true
|
||||
}
|
||||
|
||||
@objc private func scan(_ invoke: Invoke) {
|
||||
self.invoke = invoke
|
||||
|
||||
var iOS14min: Bool = false
|
||||
if #available(iOS 14.0, *) { iOS14min = true }
|
||||
if !iOS14min && self.getPermissionState() != "granted" {
|
||||
var authorized = false
|
||||
AVCaptureDevice.requestAccess(for: .video) { (isAuthorized) in
|
||||
authorized = isAuthorized
|
||||
}
|
||||
if !authorized {
|
||||
invoke.reject("denied by the user")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async { [self] in
|
||||
self.loadCamera()
|
||||
self.dismantleCamera()
|
||||
self.setupCamera(
|
||||
direction: invoke.getString("cameraDirection") ?? "back",
|
||||
windowed: invoke.getBool("windowed") ?? false
|
||||
)
|
||||
self.runScanner(invoke)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func cancel(_ invoke: Invoke) {
|
||||
self.invoke?.reject("cancelled")
|
||||
|
||||
destroy()
|
||||
invoke.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("init_plugin_barcode_scanner")
|
||||
func initPlugin() -> Plugin {
|
||||
return BarcodeScannerPlugin()
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import AVFoundation
|
||||
import UIKit
|
||||
|
||||
class CameraView: UIView {
|
||||
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
|
||||
|
||||
func interfaceOrientationToVideoOrientation(_ orientation: UIInterfaceOrientation)
|
||||
-> AVCaptureVideoOrientation
|
||||
{
|
||||
switch orientation {
|
||||
case UIInterfaceOrientation.portrait:
|
||||
return AVCaptureVideoOrientation.portrait
|
||||
case UIInterfaceOrientation.portraitUpsideDown:
|
||||
return AVCaptureVideoOrientation.portraitUpsideDown
|
||||
case UIInterfaceOrientation.landscapeLeft:
|
||||
return AVCaptureVideoOrientation.landscapeLeft
|
||||
case UIInterfaceOrientation.landscapeRight:
|
||||
return AVCaptureVideoOrientation.landscapeRight
|
||||
default:
|
||||
return AVCaptureVideoOrientation.portraitUpsideDown
|
||||
}
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
if let sublayers = self.layer.sublayers {
|
||||
for layer in sublayers {
|
||||
layer.frame = self.bounds
|
||||
}
|
||||
}
|
||||
|
||||
if let interfaceOrientation = UIApplication.shared.windows.first(where: { $0.isKeyWindow })?
|
||||
.windowScene?.interfaceOrientation
|
||||
{
|
||||
self.videoPreviewLayer?.connection?.videoOrientation = interfaceOrientationToVideoOrientation(
|
||||
interfaceOrientation)
|
||||
}
|
||||
}
|
||||
|
||||
func addPreviewLayer(_ previewLayer: AVCaptureVideoPreviewLayer?) {
|
||||
previewLayer!.videoGravity = AVLayerVideoGravity.resizeAspectFill
|
||||
previewLayer!.frame = self.bounds
|
||||
self.layer.addSublayer(previewLayer!)
|
||||
self.videoPreviewLayer = previewLayer
|
||||
}
|
||||
|
||||
func removePreviewLayer() {
|
||||
if self.videoPreviewLayer != nil {
|
||||
self.videoPreviewLayer!.removeFromSuperlayer()
|
||||
self.videoPreviewLayer = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import AVFoundation
|
||||
|
||||
func createCaptureDeviceInput(
|
||||
cameraDirection: String, backCamera: AVCaptureDevice?, frontCamera: AVCaptureDevice?
|
||||
) throws
|
||||
-> AVCaptureDeviceInput
|
||||
{
|
||||
var captureDevice: AVCaptureDevice
|
||||
if cameraDirection == "back" {
|
||||
if backCamera != nil {
|
||||
captureDevice = backCamera!
|
||||
} else {
|
||||
throw CaptureError.backCameraUnavailable
|
||||
}
|
||||
} else {
|
||||
if frontCamera != nil {
|
||||
captureDevice = frontCamera!
|
||||
} else {
|
||||
throw CaptureError.frontCameraUnavailable
|
||||
}
|
||||
}
|
||||
let captureDeviceInput: AVCaptureDeviceInput
|
||||
do {
|
||||
captureDeviceInput = try AVCaptureDeviceInput(device: captureDevice)
|
||||
} catch let error as NSError {
|
||||
throw CaptureError.couldNotCaptureInput(error: error)
|
||||
}
|
||||
return captureDeviceInput
|
||||
}
|
||||
|
||||
func discoverCaptureDevices() -> [AVCaptureDevice] {
|
||||
if #available(iOS 13.0, *) {
|
||||
return AVCaptureDevice.DiscoverySession(
|
||||
deviceTypes: [
|
||||
.builtInTripleCamera, .builtInDualCamera, .builtInTelephotoCamera,
|
||||
.builtInTrueDepthCamera,
|
||||
.builtInUltraWideCamera, .builtInDualWideCamera, .builtInWideAngleCamera,
|
||||
], mediaType: .video, position: .unspecified
|
||||
).devices
|
||||
} else {
|
||||
return AVCaptureDevice.DiscoverySession(
|
||||
deviceTypes: [
|
||||
.builtInDualCamera, .builtInWideAngleCamera, .builtInTelephotoCamera,
|
||||
.builtInTrueDepthCamera,
|
||||
], mediaType: .video, position: .unspecified
|
||||
).devices
|
||||
}
|
||||
}
|
||||
|
||||
func formatStringFromMetadata(_ type: AVMetadataObject.ObjectType) -> String {
|
||||
switch type {
|
||||
case AVMetadataObject.ObjectType.upce:
|
||||
return "UPC_E"
|
||||
case AVMetadataObject.ObjectType.ean8:
|
||||
return "EAN_8"
|
||||
case AVMetadataObject.ObjectType.ean13:
|
||||
return "EAN_13"
|
||||
case AVMetadataObject.ObjectType.code39:
|
||||
return "CODE_39"
|
||||
case AVMetadataObject.ObjectType.code93:
|
||||
return "CODE_93"
|
||||
case AVMetadataObject.ObjectType.code128:
|
||||
return "CODE_128"
|
||||
case AVMetadataObject.ObjectType.interleaved2of5:
|
||||
return "ITF"
|
||||
case AVMetadataObject.ObjectType.aztec:
|
||||
return "AZTEC"
|
||||
case AVMetadataObject.ObjectType.dataMatrix:
|
||||
return "DATA_MATRIX"
|
||||
case AVMetadataObject.ObjectType.pdf417:
|
||||
return "PDF_417"
|
||||
case AVMetadataObject.ObjectType.qr:
|
||||
return "QR_CODE"
|
||||
default:
|
||||
return type.rawValue
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import ExamplePlugin
|
||||
|
||||
final class ExamplePluginTests: XCTestCase {
|
||||
func testExample() throws {
|
||||
let plugin = ExamplePlugin()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@tauri-apps/plugin-barcode-scanner",
|
||||
"version": "2.0.0-alpha.0",
|
||||
"description": "Scan QR codes, EAN-13 and other kinds of barcodes on Android and iOS",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
"Tauri Programme within The Commons Conservancy"
|
||||
],
|
||||
"type": "module",
|
||||
"browser": "dist-js/index.min.js",
|
||||
"module": "dist-js/index.mjs",
|
||||
"types": "dist-js/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist-js/index.mjs",
|
||||
"types": "./dist-js/index.d.ts",
|
||||
"browser": "./dist-js/index.min.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c"
|
||||
},
|
||||
"files": [
|
||||
"dist-js",
|
||||
"!dist-js/**/*.map",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"devDependencies": {
|
||||
"tslib": "^2.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "2.0.0-alpha.8"
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { createConfig } from "../../shared/rollup.config.mjs";
|
||||
export default createConfig({
|
||||
input: "guest-js/index.ts",
|
||||
pkg: JSON.parse(
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
|
||||
),
|
||||
external: [/^@tauri-apps\/api/],
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_BARCODESCANNER__=function(e){"use strict";var n=Object.defineProperty,t=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},r=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e)),a=(e,n,r,a)=>(t(e,n,"write to private field"),a?a.call(e,r):n.set(e,r),r);function i(e,n=!1){let t=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${t}`;return Object.defineProperty(window,r,{value:t=>(n&&Reflect.deleteProperty(window,r),e?.(t)),writable:!1,configurable:!0}),t}((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})({},{Channel:()=>c,PluginListener:()=>_,addPluginListener:()=>l,convertFileSrc:()=>u,invoke:()=>d,transformCallback:()=>i});var o,c=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,o,(()=>{})),this.id=i((e=>{r(this,o).call(this,e)}))}set onmessage(e){a(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var s,_=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return d(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function l(e,n,t){let r=new c;return r.onmessage=t,d(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new _(e,n,r.id)))}async function d(e,n={},t){return new Promise(((r,a)=>{let o=i((e=>{r(e),Reflect.deleteProperty(window,`_${c}`)}),!0),c=i((e=>{a(e),Reflect.deleteProperty(window,`_${o}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:o,error:c,payload:n,options:t})}))}function u(e,n="asset"){return window.__TAURI__.convertFileSrc(e,n)}return e.Format=void 0,(s=e.Format||(e.Format={})).QRCode="QR_CODE",s.UPC_A="UPC_A",s.UPC_E="UPC_E",s.EAN8="EAN_8",s.EAN13="EAN_13",s.Code39="CODE_39",s.Code93="CODE_93",s.Code128="CODE_128",s.Codabar="CODABAR",s.ITF="ITF",s.Aztec="AZTEC",s.DataMatrix="DATA_MATRIX",s.PDF417="PDF_417",e.cancel=async function(){return await d("plugin:barcodeScanner|cancel")},e.checkPermissions=async function(){return await d("plugin:barcodeScanner|checkPermissions").then((e=>e.camera))},e.openAppSettings=async function(){return await d("plugin:barcodeScanner|openAppSettings")},e.requestPermissions=async function(){return await d("plugin:barcodeScanner|requestPermissions").then((e=>e.camera))},e.scan=async function(e){return await d("plugin:barcodeScanner|scan",{...e})},e}({});Object.defineProperty(window.__TAURI__,"barcodeScanner",{value:__TAURI_BARCODESCANNER__})}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use serde::{ser::Serializer, Serialize};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
#[cfg(mobile)]
|
||||
#[error(transparent)]
|
||||
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
|
||||
}
|
||||
|
||||
impl Serialize for Error {
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(self.to_string().as_ref())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#![cfg(mobile)]
|
||||
|
||||
use tauri::{
|
||||
plugin::{Builder, PluginHandle, TauriPlugin},
|
||||
Manager, Runtime,
|
||||
};
|
||||
|
||||
pub use models::*;
|
||||
|
||||
mod error;
|
||||
mod models;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
const PLUGIN_IDENTIFIER: &str = "app.tauri.barcodescanner";
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
tauri::ios_plugin_binding!(init_plugin_barcode_scanner);
|
||||
|
||||
/// Access to the scanner APIs.
|
||||
pub struct BarcodeScanner<R: Runtime>(PluginHandle<R>);
|
||||
|
||||
impl<R: Runtime> BarcodeScanner<R> {}
|
||||
|
||||
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the barcode scanner APIs.
|
||||
pub trait BarcodeScannerExt<R: Runtime> {
|
||||
fn barcode_scanner(&self) -> &BarcodeScanner<R>;
|
||||
}
|
||||
|
||||
impl<R: Runtime, T: Manager<R>> crate::BarcodeScannerExt<R> for T {
|
||||
fn barcode_scanner(&self) -> &BarcodeScanner<R> {
|
||||
self.state::<BarcodeScanner<R>>().inner()
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes the plugin.
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("barcodeScanner")
|
||||
.setup(|app, api| {
|
||||
#[cfg(target_os = "android")]
|
||||
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "BarcodeScannerPlugin")?;
|
||||
#[cfg(target_os = "ios")]
|
||||
let handle = api.register_ios_plugin(init_plugin_barcode_scanner)?;
|
||||
app.manage(BarcodeScanner(handle));
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
@@ -0,0 +1,3 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["guest-js/*.ts"]
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
[package]
|
||||
name = "tauri-plugin-camera"
|
||||
version = "0.0.0"
|
||||
version = "1.0.0"
|
||||
description = "Ask the user take a photo with the camera or select an image from the gallery."
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
exclude.workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
|
||||
Vendored
+27
-27
@@ -1,38 +1,38 @@
|
||||
export declare enum Source {
|
||||
Prompt = "PROMPT",
|
||||
Camera = "CAMERA",
|
||||
Photos = "PHOTOS",
|
||||
Prompt = "PROMPT",
|
||||
Camera = "CAMERA",
|
||||
Photos = "PHOTOS"
|
||||
}
|
||||
export declare enum ResultType {
|
||||
Uri = "uri",
|
||||
Base64 = "base64",
|
||||
DataUrl = "dataUrl",
|
||||
Uri = "uri",
|
||||
Base64 = "base64",
|
||||
DataUrl = "dataUrl"
|
||||
}
|
||||
export declare enum CameraDirection {
|
||||
Rear = "REAR",
|
||||
Front = "FRONT",
|
||||
Rear = "REAR",
|
||||
Front = "FRONT"
|
||||
}
|
||||
export interface ImageOptions {
|
||||
quality?: number;
|
||||
allowEditing?: boolean;
|
||||
resultType?: ResultType;
|
||||
saveToGallery?: boolean;
|
||||
width?: number;
|
||||
height?: number;
|
||||
correctOrientation?: boolean;
|
||||
source?: Source;
|
||||
direction?: CameraDirection;
|
||||
presentationStyle?: "fullscreen" | "popover";
|
||||
promptLabelHeader?: string;
|
||||
promptLabelCancel?: string;
|
||||
promptLabelPhoto?: string;
|
||||
promptLabelPicture?: string;
|
||||
quality?: number;
|
||||
allowEditing?: boolean;
|
||||
resultType?: ResultType;
|
||||
saveToGallery?: boolean;
|
||||
width?: number;
|
||||
height?: number;
|
||||
correctOrientation?: boolean;
|
||||
source?: Source;
|
||||
direction?: CameraDirection;
|
||||
presentationStyle?: "fullscreen" | "popover";
|
||||
promptLabelHeader?: string;
|
||||
promptLabelCancel?: string;
|
||||
promptLabelPhoto?: string;
|
||||
promptLabelPicture?: string;
|
||||
}
|
||||
export interface Image {
|
||||
data: string;
|
||||
assetUrl?: string;
|
||||
format: string;
|
||||
saved: boolean;
|
||||
exif: unknown;
|
||||
data: string;
|
||||
assetUrl?: string;
|
||||
format: string;
|
||||
saved: boolean;
|
||||
exif: unknown;
|
||||
}
|
||||
export declare function getPhoto(options?: ImageOptions): Promise<Image>;
|
||||
|
||||
Vendored
+13
-47
@@ -1,63 +1,29 @@
|
||||
var d$1 = Object.defineProperty;
|
||||
var e = (c, a) => {
|
||||
for (var b in a) d$1(c, b, { get: a[b], enumerable: !0 });
|
||||
};
|
||||
var f$1=Object.defineProperty;var g=(a,b)=>{for(var c in b)f$1(a,c,{get:b[c],enumerable:!0});};var e=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)};var h$1=(a,b,c)=>(e(a,b,"read from private field"),c?c.call(a):b.get(a)),i$1=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c);},j=(a,b,c,d)=>(e(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);
|
||||
|
||||
var w = {};
|
||||
e(w, { convertFileSrc: () => u, invoke: () => d, transformCallback: () => s });
|
||||
function l() {
|
||||
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||
}
|
||||
function s(r, n = !1) {
|
||||
let e = l(),
|
||||
t = `_${e}`;
|
||||
return (
|
||||
Object.defineProperty(window, t, {
|
||||
value: (o) => (n && Reflect.deleteProperty(window, t), r?.(o)),
|
||||
writable: !1,
|
||||
configurable: !0,
|
||||
}),
|
||||
e
|
||||
);
|
||||
}
|
||||
async function d(r, n = {}) {
|
||||
return new Promise((e, t) => {
|
||||
let o = s((i) => {
|
||||
e(i), Reflect.deleteProperty(window, `_${a}`);
|
||||
}, !0),
|
||||
a = s((i) => {
|
||||
t(i), Reflect.deleteProperty(window, `_${o}`);
|
||||
}, !0);
|
||||
window.__TAURI_IPC__({ cmd: r, callback: o, error: a, ...n });
|
||||
});
|
||||
}
|
||||
function u(r, n = "asset") {
|
||||
let e = encodeURIComponent(r);
|
||||
return navigator.userAgent.includes("Windows")
|
||||
? `https://${n}.localhost/${e}`
|
||||
: `${n}://localhost/${e}`;
|
||||
}
|
||||
var h={};g(h,{Channel:()=>o,PluginListener:()=>a,addPluginListener:()=>m,convertFileSrc:()=>y,invoke:()=>u,transformCallback:()=>s});function f(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function s(n,e=!1){let t=f(),r=`_${t}`;return Object.defineProperty(window,r,{value:c=>(e&&Reflect.deleteProperty(window,r),n?.(c)),writable:!1,configurable:!0}),t}var i,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0;i$1(this,i,()=>{});this.id=s(e=>{h$1(this,i).call(this,e);});}set onmessage(e){j(this,i,e);}get onmessage(){return h$1(this,i)}toJSON(){return `__CHANNEL__:${this.id}`}};i=new WeakMap;var a=class{constructor(e,t,r){this.plugin=e,this.event=t,this.channelId=r;}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function m(n,e,t){let r=new o;return r.onmessage=t,u(`plugin:${n}|register_listener`,{event:e,handler:r}).then(()=>new a(n,e,r.id))}async function u(n,e={},t){return new Promise((r,c)=>{let g=s(d=>{r(d),Reflect.deleteProperty(window,`_${_}`);},!0),_=s(d=>{c(d),Reflect.deleteProperty(window,`_${g}`);},!0);window.__TAURI_IPC__({cmd:n,callback:g,error:_,payload:e,options:t});})}function y(n,e="asset"){return window.__TAURI__.convertFileSrc(n,e)}
|
||||
|
||||
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
var Source;
|
||||
(function (Source) {
|
||||
Source["Prompt"] = "PROMPT";
|
||||
Source["Camera"] = "CAMERA";
|
||||
Source["Photos"] = "PHOTOS";
|
||||
Source["Prompt"] = "PROMPT";
|
||||
Source["Camera"] = "CAMERA";
|
||||
Source["Photos"] = "PHOTOS";
|
||||
})(Source || (Source = {}));
|
||||
var ResultType;
|
||||
(function (ResultType) {
|
||||
ResultType["Uri"] = "uri";
|
||||
ResultType["Base64"] = "base64";
|
||||
ResultType["DataUrl"] = "dataUrl";
|
||||
ResultType["Uri"] = "uri";
|
||||
ResultType["Base64"] = "base64";
|
||||
ResultType["DataUrl"] = "dataUrl";
|
||||
})(ResultType || (ResultType = {}));
|
||||
var CameraDirection;
|
||||
(function (CameraDirection) {
|
||||
CameraDirection["Rear"] = "REAR";
|
||||
CameraDirection["Front"] = "FRONT";
|
||||
CameraDirection["Rear"] = "REAR";
|
||||
CameraDirection["Front"] = "FRONT";
|
||||
})(CameraDirection || (CameraDirection = {}));
|
||||
async function getPhoto(options) {
|
||||
return await d("plugin:camera|getPhoto", { ...options });
|
||||
return await u("plugin:camera|getPhoto", { ...options });
|
||||
}
|
||||
|
||||
export { CameraDirection, ResultType, Source, getPhoto };
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,25 +1,27 @@
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
|
||||
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
var Source;
|
||||
(function (Source) {
|
||||
Source["Prompt"] = "PROMPT";
|
||||
Source["Camera"] = "CAMERA";
|
||||
Source["Photos"] = "PHOTOS";
|
||||
Source["Prompt"] = "PROMPT";
|
||||
Source["Camera"] = "CAMERA";
|
||||
Source["Photos"] = "PHOTOS";
|
||||
})(Source || (Source = {}));
|
||||
var ResultType;
|
||||
(function (ResultType) {
|
||||
ResultType["Uri"] = "uri";
|
||||
ResultType["Base64"] = "base64";
|
||||
ResultType["DataUrl"] = "dataUrl";
|
||||
ResultType["Uri"] = "uri";
|
||||
ResultType["Base64"] = "base64";
|
||||
ResultType["DataUrl"] = "dataUrl";
|
||||
})(ResultType || (ResultType = {}));
|
||||
var CameraDirection;
|
||||
(function (CameraDirection) {
|
||||
CameraDirection["Rear"] = "REAR";
|
||||
CameraDirection["Front"] = "FRONT";
|
||||
CameraDirection["Rear"] = "REAR";
|
||||
CameraDirection["Front"] = "FRONT";
|
||||
})(CameraDirection || (CameraDirection = {}));
|
||||
async function getPhoto(options) {
|
||||
return await invoke("plugin:camera|getPhoto", { ...options });
|
||||
return await invoke("plugin:camera|getPhoto", { ...options });
|
||||
}
|
||||
|
||||
export { CameraDirection, ResultType, Source, getPhoto };
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.mjs","sources":["../guest-js/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;IAKY,OAIX;AAJD,CAAA,UAAY,MAAM,EAAA;AAChB,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACnB,CAAC,EAJW,MAAM,KAAN,MAAM,GAIjB,EAAA,CAAA,CAAA,CAAA;IAEW,WAIX;AAJD,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACX,IAAA,UAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,UAAA,CAAA,SAAA,CAAA,GAAA,SAAmB,CAAA;AACrB,CAAC,EAJW,UAAU,KAAV,UAAU,GAIrB,EAAA,CAAA,CAAA,CAAA;IAEW,gBAGX;AAHD,CAAA,UAAY,eAAe,EAAA;AACzB,IAAA,eAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACb,IAAA,eAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,GAG1B,EAAA,CAAA,CAAA,CAAA;AA2BM,eAAe,QAAQ,CAAC,OAAsB,EAAA;IACnD,OAAO,MAAM,MAAM,CAAC,wBAAwB,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;AAC/D;;;;"}
|
||||
{"version":3,"file":"index.mjs","sources":["../guest-js/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;AACA;AACA;IAGY,OAIX;AAJD,CAAA,UAAY,MAAM,EAAA;AAChB,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACnB,CAAC,EAJW,MAAM,KAAN,MAAM,GAIjB,EAAA,CAAA,CAAA,CAAA;IAEW,WAIX;AAJD,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACX,IAAA,UAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,UAAA,CAAA,SAAA,CAAA,GAAA,SAAmB,CAAA;AACrB,CAAC,EAJW,UAAU,KAAV,UAAU,GAIrB,EAAA,CAAA,CAAA,CAAA;IAEW,gBAGX;AAHD,CAAA,UAAY,eAAe,EAAA;AACzB,IAAA,eAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACb,IAAA,eAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,GAG1B,EAAA,CAAA,CAAA,CAAA;AA2BM,eAAe,QAAQ,CAAC,OAAsB,EAAA;IACnD,OAAO,MAAM,MAAM,CAAC,wBAAwB,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAChE;;;;"}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tauri-plugin-camera-api",
|
||||
"version": "0.0.0",
|
||||
"name": "@tauri-apps/plugin-camera",
|
||||
"version": "1.0.0",
|
||||
"description": "Ask the user take a photo with the camera or select an image from the gallery.",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
@@ -28,6 +28,6 @@
|
||||
"tslib": "^2.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.0.0-alpha.0"
|
||||
"@tauri-apps/api": "2.0.0-alpha.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_CAMERA__=function(e){"use strict";var t=Object.defineProperty,r=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},n=(e,t,n)=>(r(e,t,"read from private field"),n?n.call(e):t.get(e)),i=(e,t,n,i)=>(r(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n);function a(e,t=!1){let r=window.crypto.getRandomValues(new Uint32Array(1))[0],n=`_${r}`;return Object.defineProperty(window,n,{value:r=>(t&&Reflect.deleteProperty(window,n),e?.(r)),writable:!1,configurable:!0}),r}((e,r)=>{for(var n in r)t(e,n,{get:r[n],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>d,addPluginListener:()=>u,convertFileSrc:()=>w,invoke:()=>h,transformCallback:()=>a});var o,s=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)})(this,o,(()=>{})),this.id=a((e=>{n(this,o).call(this,e)}))}set onmessage(e){i(this,o,e)}get onmessage(){return n(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var l,c,_,d=class{constructor(e,t,r){this.plugin=e,this.event=t,this.channelId=r}async unregister(){return h(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,t,r){let n=new s;return n.onmessage=r,h(`plugin:${e}|register_listener`,{event:t,handler:n}).then((()=>new d(e,t,n.id)))}async function h(e,t={},r){return new Promise(((n,i)=>{let o=a((e=>{n(e),Reflect.deleteProperty(window,`_${s}`)}),!0),s=a((e=>{i(e),Reflect.deleteProperty(window,`_${o}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:o,error:s,payload:t,options:r})}))}function w(e,t="asset"){return window.__TAURI__.convertFileSrc(e,t)}return e.Source=void 0,(l=e.Source||(e.Source={})).Prompt="PROMPT",l.Camera="CAMERA",l.Photos="PHOTOS",e.ResultType=void 0,(c=e.ResultType||(e.ResultType={})).Uri="uri",c.Base64="base64",c.DataUrl="dataUrl",e.CameraDirection=void 0,(_=e.CameraDirection||(e.CameraDirection={})).Rear="REAR",_.Front="FRONT",e.getPhoto=async function(e){return await h("plugin:camera|getPhoto",{...e})},e}({});Object.defineProperty(window.__TAURI__,"camera",{value:__TAURI_CAMERA__})}
|
||||
@@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.2]
|
||||
|
||||
- [`4e2cef9`](https://github.com/tauri-apps/plugins-workspace/commit/4e2cef9b702bbbb9cf4ee17de50791cb21f1b2a4)([#593](https://github.com/tauri-apps/plugins-workspace/pull/593)) Update to alpha.12.
|
||||
|
||||
## \[2.0.0-alpha.1]
|
||||
|
||||
- [`d74fc0a`](https://github.com/tauri-apps/plugins-workspace/commit/d74fc0a097996e90a37be8f57d50b7d1f6ca616f)([#555](https://github.com/tauri-apps/plugins-workspace/pull/555)) Update to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
te to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
+14
-10
@@ -1,14 +1,18 @@
|
||||
[package]
|
||||
name = "tauri-plugin-cli"
|
||||
version = "0.0.0"
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
version = "2.0.0-alpha.2"
|
||||
description = "Parse arguments from your Tauri application's command line interface."
|
||||
edition = { workspace = true }
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [ "tauri/dox" ]
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
tauri.workspace = true
|
||||
log.workspace = true
|
||||
thiserror.workspace = true
|
||||
clap = { version = "4", features = ["string"] }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
log = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
clap = { version = "4", features = [ "string" ] }
|
||||
|
||||
+34
-7
@@ -1,10 +1,12 @@
|
||||

|
||||

|
||||
|
||||
<!-- description -->
|
||||
Parse arguments from your Command Line Interface.
|
||||
|
||||
- Supported platforms: Windows, Linux and macOS.
|
||||
|
||||
## Install
|
||||
|
||||
_This plugin requires a Rust version of at least **1.64**_
|
||||
_This plugin requires a Rust version of at least **1.65**_
|
||||
|
||||
There are three general methods of installation that we can recommend.
|
||||
|
||||
@@ -17,8 +19,11 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
`src-tauri/Cargo.toml`
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri-plugin-cli = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "next" }
|
||||
# you can add the dependencies on the `[dependencies]` section if you do not target mobile
|
||||
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
|
||||
tauri-plugin-cli = "2.0.0-alpha"
|
||||
# alternatively with Git:
|
||||
tauri-plugin-cli = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
||||
@@ -26,6 +31,13 @@ You can install the JavaScript Guest bindings using your preferred JavaScript pa
|
||||
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
||||
|
||||
```sh
|
||||
pnpm add @tauri-apps/plugin-cli
|
||||
# or
|
||||
npm add @tauri-apps/plugin-cli
|
||||
# or
|
||||
yarn add @tauri-apps/plugin-cli
|
||||
|
||||
# alternatively with Git:
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-cli#v2
|
||||
# or
|
||||
npm add https://github.com/tauri-apps/tauri-plugin-cli#v2
|
||||
@@ -42,7 +54,11 @@ First you need to register the core plugin with Tauri:
|
||||
```rust
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_cli::init())
|
||||
.setup(|app| {
|
||||
#[cfg(desktop)]
|
||||
app.handle().plugin(tauri_plugin_cli::init())?;
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -51,7 +67,18 @@ fn main() {
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
|
||||
import { getMatches } from "@tauri-apps/plugin-cli";
|
||||
const matches = await getMatches();
|
||||
if (matches.subcommand?.name === "run") {
|
||||
// `./your-app run $ARGS` was executed
|
||||
const args = matches.subcommand?.matches.args;
|
||||
if ("debug" in args) {
|
||||
// `./your-app run --debug` was executed
|
||||
}
|
||||
} else {
|
||||
const args = matches.args;
|
||||
// `./your-app $ARGS` was executed
|
||||
}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
@@ -8,10 +8,14 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @since 2.0.0
|
||||
*/
|
||||
interface ArgMatch {
|
||||
/**
|
||||
@@ -27,7 +31,7 @@ interface ArgMatch {
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @since 2.0.0
|
||||
*/
|
||||
interface SubcommandMatch {
|
||||
name: string;
|
||||
@@ -35,7 +39,7 @@ interface SubcommandMatch {
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @since 2.0.0
|
||||
*/
|
||||
interface CliMatches {
|
||||
args: Record<string, ArgMatch>;
|
||||
@@ -47,7 +51,7 @@ interface CliMatches {
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { getMatches } from 'tauri-plugin-cli-api';
|
||||
* import { getMatches } from '@tauri-apps/plugin-cli';
|
||||
* const matches = await getMatches();
|
||||
* if (matches.subcommand?.name === 'run') {
|
||||
* // `./your-app run $ARGS` was executed
|
||||
@@ -61,10 +65,10 @@ interface CliMatches {
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function getMatches(): Promise<CliMatches> {
|
||||
return await invoke("plugin:cli|cli_matches");
|
||||
return await window.__TAURI_INVOKE__("plugin:cli|cli_matches");
|
||||
}
|
||||
|
||||
export type { ArgMatch, SubcommandMatch, CliMatches };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tauri-plugin-cli-api",
|
||||
"version": "0.0.0",
|
||||
"name": "@tauri-apps/plugin-cli",
|
||||
"version": "2.0.0-alpha.1",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
"Tauri Programme within The Commons Conservancy"
|
||||
@@ -27,6 +27,6 @@
|
||||
"tslib": "^2.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.2.0"
|
||||
"@tauri-apps/api": "2.0.0-alpha.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { createConfig } from "../../shared/rollup.config.mjs";
|
||||
export default createConfig({
|
||||
input: "guest-js/index.ts",
|
||||
pkg: JSON.parse(
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
||||
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
|
||||
),
|
||||
external: [/^@tauri-apps\/api/],
|
||||
});
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_CLI__=function(_){"use strict";return _.getMatches=async function(){return await window.__TAURI_INVOKE__("plugin:cli|cli_matches")},_}({});Object.defineProperty(window.__TAURI__,"cli",{value:__TAURI_CLI__})}
|
||||
@@ -1,3 +1,7 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
||||
+19
-4
@@ -1,3 +1,18 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//! [](https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/cli)
|
||||
//!
|
||||
//! Parse arguments from your Command Line Interface.
|
||||
//!
|
||||
//! - Supported platforms: Windows, Linux and macOS.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
|
||||
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
||||
)]
|
||||
|
||||
use tauri::{
|
||||
plugin::{Builder, PluginApi, TauriPlugin},
|
||||
AppHandle, Manager, Runtime, State,
|
||||
@@ -11,12 +26,11 @@ use config::{Arg, Config};
|
||||
pub use error::Error;
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
// TODO: use PluginApi#app when 2.0.0-alpha.9 is released
|
||||
pub struct Cli<R: Runtime>(PluginApi<R, Config>, AppHandle<R>);
|
||||
pub struct Cli<R: Runtime>(PluginApi<R, Config>);
|
||||
|
||||
impl<R: Runtime> Cli<R> {
|
||||
pub fn matches(&self) -> Result<parser::Matches> {
|
||||
parser::get_matches(self.0.config(), self.1.package_info())
|
||||
parser::get_matches(self.0.config(), self.0.app().package_info())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +51,10 @@ fn cli_matches<R: Runtime>(_app: AppHandle<R>, cli: State<'_, Cli<R>>) -> Result
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R, Config> {
|
||||
Builder::new("cli")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
.invoke_handler(tauri::generate_handler![cli_matches])
|
||||
.setup(|app, api| {
|
||||
app.manage(Cli(api, app.clone()));
|
||||
app.manage(Cli(api));
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
|
||||
@@ -72,10 +72,10 @@ impl Matches {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// use tauri_plugin_cli::get_matches;
|
||||
/// use tauri_plugin_cli::CliExt;
|
||||
/// tauri::Builder::default()
|
||||
/// .setup(|app| {
|
||||
/// let matches = get_matches(app.config().tauri.cli.as_ref().unwrap(), app.package_info())?;
|
||||
/// let matches = app.cli().matches()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/.tauri
|
||||
@@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.2]
|
||||
|
||||
- [`4e2cef9`](https://github.com/tauri-apps/plugins-workspace/commit/4e2cef9b702bbbb9cf4ee17de50791cb21f1b2a4)([#593](https://github.com/tauri-apps/plugins-workspace/pull/593)) Update to alpha.12.
|
||||
|
||||
## \[2.0.0-alpha.1]
|
||||
|
||||
- [`d74fc0a`](https://github.com/tauri-apps/plugins-workspace/commit/d74fc0a097996e90a37be8f57d50b7d1f6ca616f)([#555](https://github.com/tauri-apps/plugins-workspace/pull/555)) Update to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
te to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
@@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "tauri-plugin-clipboard-manager"
|
||||
version = "2.0.0-alpha.2"
|
||||
description = "Read and write to the system clipboard."
|
||||
edition = { workspace = true }
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
links = "tauri-plugin-clipboard-manager"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [ "tauri/dox" ]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
log = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
|
||||
arboard = "3"
|
||||
@@ -0,0 +1,20 @@
|
||||
SPDXVersion: SPDX-2.1
|
||||
DataLicense: CC0-1.0
|
||||
PackageName: tauri
|
||||
DataFormat: SPDXRef-1
|
||||
PackageSupplier: Organization: The Tauri Programme in the Commons Conservancy
|
||||
PackageHomePage: https://tauri.app
|
||||
PackageLicenseDeclared: Apache-2.0
|
||||
PackageLicenseDeclared: MIT
|
||||
PackageCopyrightText: 2019-2022, The Tauri Programme in the Commons Conservancy
|
||||
PackageSummary: <text>Tauri is a rust project that enables developers to make secure
|
||||
and small desktop applications using a web frontend.
|
||||
</text>
|
||||
PackageComment: <text>The package includes the following libraries; see
|
||||
Relationship information.
|
||||
</text>
|
||||
Created: 2019-05-20T09:00:00Z
|
||||
PackageDownloadLocation: git://github.com/tauri-apps/tauri
|
||||
PackageDownloadLocation: git+https://github.com/tauri-apps/tauri.git
|
||||
PackageDownloadLocation: git+ssh://github.com/tauri-apps/tauri.git
|
||||
Creator: Person: Daniel Thompson-Yvetot
|
||||
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 - Present Tauri Apps Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,76 @@
|
||||

|
||||
|
||||
Read and write to the system clipboard.
|
||||
|
||||
## Install
|
||||
|
||||
_This plugin requires a Rust version of at least **1.65**_
|
||||
|
||||
There are three general methods of installation that we can recommend.
|
||||
|
||||
1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
|
||||
2. Pull sources directly from Github using git tags / revision hashes (most secure)
|
||||
3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
|
||||
|
||||
Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
|
||||
`src-tauri/Cargo.toml`
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri-plugin-clipboard-manager = "2.0.0-alpha"
|
||||
# alternatively with Git:
|
||||
tauri-plugin-clipboard-manager = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
||||
|
||||
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
||||
|
||||
```sh
|
||||
pnpm add @tauri-apps/plugin-clipboard-manager
|
||||
# or
|
||||
npm add @tauri-apps/plugin-clipboard-manager
|
||||
# or
|
||||
yarn add @tauri-apps/plugin-clipboard-manager
|
||||
|
||||
# alternatively with Git:
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-clipboard-manager#v2
|
||||
# or
|
||||
npm add https://github.com/tauri-apps/tauri-plugin-clipboard-manager#v2
|
||||
# or
|
||||
yarn add https://github.com/tauri-apps/tauri-plugin-clipboard-manager#v2
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
First you need to register the core plugin with Tauri:
|
||||
|
||||
`src-tauri/src/main.rs`
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { writeText, readText } from "@tauri-apps/plugin-clipboard-manager";
|
||||
await writeText("Tauri is awesome!");
|
||||
assert(await readText(), "Tauri is awesome!");
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
|
||||
|
||||
## License
|
||||
|
||||
Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
|
||||
|
||||
MIT or MIT/Apache 2.0 where applicable.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user