pull/536/head
Lucas Nogueira 2 years ago
parent 2aa719c50e
commit da4c7eb203
No known key found for this signature in database
GPG Key ID: 7C32FCA95C8C95D7

@ -56,11 +56,6 @@ pub fn run() {
app.handle().plugin(tauri_plugin_barcode_scanner::init())?;
}
#[cfg(mobile)]
{
app.handle().plugin(tauri_plugin_barcode_scanner::init())?;
}
let mut window_builder = WindowBuilder::new(app, "main", WindowUrl::default());
#[cfg(desktop)]
{

@ -1,12 +1,12 @@
<script>
import { scan } from "@tauri-apps/plugin-barcode-scanner";
import { scan, Format } from "@tauri-apps/plugin-barcode-scanner";
export let onMessage;
let scanning = false;
let windowed = true;
let formats = ["QR_CODE"];
const supportedFormats = ["QR_CODE", "EAN_13"];
let formats = [Format.QRCode];
const supportedFormats = [Format.QRCode, Format.EAN13];
function startScan() {
scanning = true;

@ -1,6 +1,6 @@
![Barcode Scanner](banner.jpg)
<!-- description -->
Allows your mobile application to use the camera to scan QR codes, EAN-13 and other kinds of barcodes.
## Install
@ -49,7 +49,7 @@ First you need to register the core plugin with Tauri:
```rust
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_barcode_scanner)
.plugin(tauri_plugin_barcode_scanner::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
@ -58,7 +58,12 @@ fn main() {
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

@ -1,29 +1,30 @@
import { invoke } from "@tauri-apps/api/tauri";
type PermissionState = "granted" | "denied" | "default";
export type PermissionState = "granted" | "denied" | "default";
type Format =
| "QR_CODE"
| "UPC_A"
| "UPC_E"
| "EAN_8"
| "EAN_13"
| "CODE_39"
| "CODE_93"
| "CODE_128"
| "CODABAR"
| "ITF"
| "AZTEC"
| "DATA_MATRIX"
| "PDF_417";
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"
}
interface ScanOptions {
export interface ScanOptions {
cameraDirection?: "back" | "front";
formats?: Format[];
windowed?: boolean;
}
interface Scanned {
export interface Scanned {
content: string;
format: Format;
bounds: unknown;

@ -1 +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:()=>o,addPluginListener:()=>l,convertFileSrc:()=>_,invoke:()=>u,transformCallback:()=>i});var s,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,s,(()=>{})),this.id=i((e=>{r(this,s).call(this,e)}))}set onmessage(e){a(this,s,e)}get onmessage(){return r(this,s)}toJSON(){return`__CHANNEL__:${this.id}`}};s=new WeakMap;var o=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return u(`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,u(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new o(e,n,r.id)))}async function u(e,n={}){return new Promise(((t,r)=>{let a=i((e=>{t(e),Reflect.deleteProperty(window,`_${s}`)}),!0),s=i((e=>{r(e),Reflect.deleteProperty(window,`_${a}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:a,error:s,...n})}))}function _(e,n="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${t}`:`${n}://localhost/${t}`}return e.cancel=async function(){return await u("plugin:barcodeScanner|cancel")},e.checkPermissions=async function(){return await u("plugin:barcodeScanner|check_permissions").then((e=>e.camera))},e.openAppSettings=async function(){return await u("plugin:barcodeScanner|open_app_settings")},e.requestPermissions=async function(){return await u("plugin:barcodeScanner|request_permissions").then((e=>e.camera))},e.scan=async function(e){return await u("plugin:barcodeScanner|scan",{...e})},e}({});Object.defineProperty(window.__TAURI__,"barcodeScanner",{value:__TAURI_BARCODESCANNER__})}
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:()=>s,PluginListener:()=>l,addPluginListener:()=>_,convertFileSrc:()=>u,invoke:()=>d,transformCallback:()=>i});var o,s=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 c,l=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 _(e,n,t){let r=new s;return r.onmessage=t,d(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new l(e,n,r.id)))}async function d(e,n={}){return new Promise(((t,r)=>{let a=i((e=>{t(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=i((e=>{r(e),Reflect.deleteProperty(window,`_${a}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:a,error:o,...n})}))}function u(e,n="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${t}`:`${n}://localhost/${t}`}return e.Format=void 0,(c=e.Format||(e.Format={})).QRCode="QR_CODE",c.UPC_A="UPC_A",c.UPC_E="UPC_E",c.EAN8="EAN_8",c.EAN13="EAN_13",c.Code39="CODE_39",c.Code93="CODE_93",c.Code128="CODE_128",c.Codabar="CODABAR",c.ITF="ITF",c.Aztec="AZTEC",c.DataMatrix="DATA_MATRIX",c.PDF417="PDF_417",e.cancel=async function(){return await d("plugin:barcodeScanner|cancel")},e.checkPermissions=async function(){return await d("plugin:barcodeScanner|check_permissions").then((e=>e.camera))},e.openAppSettings=async function(){return await d("plugin:barcodeScanner|open_app_settings")},e.requestPermissions=async function(){return await d("plugin:barcodeScanner|request_permissions").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__})}

Loading…
Cancel
Save