Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/barcode-scanner/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature
android:name="android.hardware.camera.flash"
android:required="false" />


<uses-feature android:name="android.hardware.camera.any"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class ScanOptions {
var cameraDirection: String? = null
}

@InvokeArg
class TorchArgs {
var enabled: Boolean = false
}


@TauriPlugin(
permissions = [
Permission(strings = [Manifest.permission.CAMERA], alias = "camera")
Expand Down Expand Up @@ -353,6 +359,21 @@ class BarcodeScannerPlugin(private val activity: Activity) : Plugin(activity),
}
}


@Command
fun setTorch(invoke: Invoke) {
val args = invoke.parseArgs(TorchArgs::class.java)

activity.runOnUiThread {
try {
camera?.cameraControl?.enableTorch(args.enabled)
invoke.resolve()
} catch (e: Exception) {
invoke.reject("TORCH_ERROR", e.message)
}
}
}

@SuppressLint("ObsoleteSdkInt")
@PermissionCallback
fun cameraPermissionCallback(invoke: Invoke) {
Expand Down
53 changes: 52 additions & 1 deletion plugins/barcode-scanner/api-iife.js
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
if("__TAURI__"in window){var __TAURI_PLUGIN_BARCODE_SCANNER__=function(n){"use strict";async function a(n,a={},e){return window.__TAURI_INTERNALS__.invoke(n,a,e)}var e;return"function"==typeof SuppressedError&&SuppressedError,n.Format=void 0,(e=n.Format||(n.Format={})).QRCode="QR_CODE",e.UPC_A="UPC_A",e.UPC_E="UPC_E",e.EAN8="EAN_8",e.EAN13="EAN_13",e.Code39="CODE_39",e.Code93="CODE_93",e.Code128="CODE_128",e.Codabar="CODABAR",e.ITF="ITF",e.Aztec="AZTEC",e.DataMatrix="DATA_MATRIX",e.PDF417="PDF_417",e.GS1DataBar="GS1_DATA_BAR",e.GS1DataBarLimited="GS1_DATA_BAR_LIMITED",e.GS1DataBarExpanded="GS1_DATA_BAR_EXPANDED",n.cancel=async function(){await a("plugin:barcode-scanner|cancel")},n.checkPermissions=async function(){return await async function(n){return a(`plugin:${n}|check_permissions`)}("barcode-scanner").then((n=>n.camera))},n.openAppSettings=async function(){await a("plugin:barcode-scanner|open_app_settings")},n.requestPermissions=async function(){return await async function(n){return a(`plugin:${n}|request_permissions`)}("barcode-scanner").then((n=>n.camera))},n.scan=async function(n){return await a("plugin:barcode-scanner|scan",{...n})},n}({});Object.defineProperty(window.__TAURI__,"barcodeScanner",{value:__TAURI_PLUGIN_BARCODE_SCANNER__})}
if ("__TAURI__" in window) {
var __TAURI_PLUGIN_BARCODE_SCANNER__ = function(n) {
"use strict";
async function a(n, a = {}, e) {
return window.__TAURI_INTERNALS__.invoke(n, a, e)
}
var e;
return "function" == typeof SuppressedError && SuppressedError,
n.Format = void 0,
(e = n.Format || (n.Format = {})).QRCode = "QR_CODE",
e.UPC_A = "UPC_A", e.UPC_E = "UPC_E",
e.EAN8 = "EAN_8", e.EAN13 = "EAN_13",
e.Code39 = "CODE_39",
e.Code93 = "CODE_93",
e.Code128 = "CODE_128",
e.Codabar = "CODABAR",
e.ITF = "ITF",
e.Aztec = "AZTEC",
e.DataMatrix = "DATA_MATRIX",
e.PDF417 = "PDF_417",
e.GS1DataBar = "GS1_DATA_BAR",
e.GS1DataBarLimited = "GS1_DATA_BAR_LIMITED",
e.GS1DataBarExpanded = "GS1_DATA_BAR_EXPANDED",
n.cancel = async function() {
await a("plugin:barcode-scanner|cancel")
},
n.checkPermissions = async function() {
return await async function(n) {
return a(`plugin:${n}|check_permissions`)
}("barcode-scanner").then((n => n.camera))
},
n.openAppSettings = async function() {
await a("plugin:barcode-scanner|open_app_settings")
},
n.requestPermissions = async function() {
return await async function(n) {
return a(`plugin:${n}|request_permissions`)
}("barcode-scanner").then((n => n.camera))
},
n.scan = async function(n) {
return await a("plugin:barcode-scanner|scan",
{ ...n })
},
n.setTorch = async function(args) {
return await a("plugin:barcode-scanner|set_torch", { ...args })
},
n
}({}); Object.defineProperty(window.__TAURI__,
"barcodeScanner",
{ value: __TAURI_PLUGIN_BARCODE_SCANNER__ })
}

1 change: 1 addition & 0 deletions plugins/barcode-scanner/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const COMMANDS: &[&str] = &[
"request_permissions",
"check_permissions",
"open_app_settings",
"set_torch",
"vibrate",
];

Expand Down
14 changes: 14 additions & 0 deletions plugins/barcode-scanner/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export interface Scanned {
bounds: unknown
}

export interface TorchOptions {
enabled: boolean
}

/**
* Start scanning.
* @param options
Expand Down Expand Up @@ -95,3 +99,13 @@ export async function requestPermissions(): Promise<PermissionState> {
export async function openAppSettings(): Promise<void> {
await invoke('plugin:barcode-scanner|open_app_settings')
}


/**
* Turn flashlight on/off.
* @param options.enabled true = on, false = off
*/
export async function setTorch(options: TorchOptions): Promise<void> {
await invoke('plugin:barcode-scanner|set_torch', { ...options })
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-set-torch"
description = "Enables the set_torch command without any pre-configured scope."
commands.allow = ["set_torch"]

[[permission]]
identifier = "deny-set-torch"
description = "Denies the set_torch command without any pre-configured scope."
commands.deny = ["set_torch"]
1 change: 1 addition & 0 deletions plugins/barcode-scanner/permissions/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ permissions = [
"allow-open-app-settings",
"allow-request-permissions",
"allow-scan",
"allow-set-torch",
"allow-vibrate",
]
14 changes: 13 additions & 1 deletion plugins/barcode-scanner/permissions/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@
"const": "deny-scan",
"markdownDescription": "Denies the scan command without any pre-configured scope."
},
{
"description": "Enables the set_torch command without any pre-configured scope.",
"type": "string",
"const": "allow-set-torch",
"markdownDescription": "Enables the set_torch command without any pre-configured scope."
},
{
"description": "Denies the set_torch command without any pre-configured scope.",
"type": "string",
"const": "deny-set-torch",
"markdownDescription": "Denies the set_torch command without any pre-configured scope."
},
{
"description": "Enables the vibrate command without any pre-configured scope.",
"type": "string",
Expand All @@ -375,4 +387,4 @@
]
}
}
}
}
Loading