mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-10-20 23:11:24 +02:00
feat: add torch plugin for iOS and Android (#3551)
* feat(barcode-scanner): add torch toggle * feat: torch plugin * fix --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
1 parent
c91a9e6af5
commit
d80b1be257
48 files changed
+1861
-4
No files matched your search
@@ -32,6 +32,7 @@
|
||||
"@tauri-apps/plugin-shell": "workspace:*",
|
||||
"@tauri-apps/plugin-sql": "workspace:*",
|
||||
"@tauri-apps/plugin-store": "workspace:*",
|
||||
"@tauri-apps/plugin-torch": "workspace:*",
|
||||
"@tauri-apps/plugin-updater": "workspace:*",
|
||||
"@tauri-apps/plugin-upload": "workspace:*",
|
||||
"@tauri-apps/plugin-websocket": "workspace:*",
|
||||
|
||||
@@ -79,6 +79,7 @@ tauri-plugin-barcode-scanner = { path = "../../../plugins/barcode-scanner/", ver
|
||||
tauri-plugin-nfc = { path = "../../../plugins/nfc", version = "2.4.2" }
|
||||
tauri-plugin-geolocation = { path = "../../../plugins/geolocation/", version = "2.4.2" }
|
||||
tauri-plugin-haptics = { path = "../../../plugins/haptics/", version = "2.4.2" }
|
||||
tauri-plugin-torch = { path = "../../../plugins/torch/", version = "2.0.0" }
|
||||
|
||||
[features]
|
||||
# Enables the WebDriver automation bridge; set by the e2e suite's build (packages/api-e2e).
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"haptics:allow-impact-feedback",
|
||||
"haptics:allow-notification-feedback",
|
||||
"haptics:allow-selection-feedback",
|
||||
"haptics:allow-vibrate"
|
||||
"haptics:allow-vibrate",
|
||||
"torch:default"
|
||||
]
|
||||
}
|
||||
@@ -95,6 +95,7 @@ pub fn run() {
|
||||
app.handle().plugin(tauri_plugin_nfc::init())?;
|
||||
app.handle().plugin(tauri_plugin_geolocation::init())?;
|
||||
app.handle().plugin(tauri_plugin_haptics::init())?;
|
||||
app.handle().plugin(tauri_plugin_torch::init())?;
|
||||
}
|
||||
|
||||
let mut webview_window_builder =
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
import Biometric from './views/Biometric.svelte'
|
||||
import Geolocation from './views/Geolocation.svelte'
|
||||
import Haptics from './views/Haptics.svelte'
|
||||
import Torch from './views/Torch.svelte'
|
||||
import Nfc from './views/Nfc.svelte'
|
||||
import Autostart from './views/Autostart.svelte'
|
||||
import DeepLink from './views/DeepLink.svelte'
|
||||
@@ -185,6 +186,11 @@
|
||||
label: 'Haptics',
|
||||
component: Haptics,
|
||||
icon: 'i-ph-vibrate'
|
||||
},
|
||||
isMobile && {
|
||||
label: 'Torch',
|
||||
component: Torch,
|
||||
icon: 'i-ph-flashlight'
|
||||
}
|
||||
].filter(Boolean) as {
|
||||
label: string
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
Format,
|
||||
cancel
|
||||
} from '@tauri-apps/plugin-barcode-scanner'
|
||||
import { toggle as toggleTorch } from '@tauri-apps/plugin-torch'
|
||||
|
||||
export let onMessage
|
||||
|
||||
@@ -35,6 +36,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleScanTorch() {
|
||||
toggleTorch()
|
||||
.then((on) => onMessage(`torch ${on ? 'on' : 'off'}`))
|
||||
.catch(onMessage)
|
||||
}
|
||||
|
||||
async function cancelScan() {
|
||||
await cancel()
|
||||
scanning = false
|
||||
@@ -67,6 +74,9 @@
|
||||
<p>Aim your camera at a QR code</p>
|
||||
<button class="btn" type="button" on:click={cancelScan}>Cancel</button
|
||||
>
|
||||
<button class="btn" type="button" on:click={toggleScanTorch}
|
||||
>Torch</button
|
||||
>
|
||||
</div>
|
||||
<div class="square surround-cover">
|
||||
<div class="barcode-scanner--area--outer surround-cover">
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import {
|
||||
enable,
|
||||
disable,
|
||||
toggle,
|
||||
isAvailable,
|
||||
isEnabled
|
||||
} from '@tauri-apps/plugin-torch'
|
||||
|
||||
export let onMessage
|
||||
|
||||
let available = null
|
||||
let enabled = null
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
available = await isAvailable()
|
||||
enabled = await isEnabled()
|
||||
} catch (e) {
|
||||
onMessage(e)
|
||||
}
|
||||
}
|
||||
|
||||
function run(action) {
|
||||
return () =>
|
||||
action()
|
||||
.then((res) => onMessage(res ?? 'ok'))
|
||||
.catch(onMessage)
|
||||
.finally(refresh)
|
||||
}
|
||||
|
||||
onMount(refresh)
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<p>
|
||||
Available: <b>{available ?? '...'}</b> / Enabled:
|
||||
<b>{enabled ?? '...'}</b>
|
||||
</p>
|
||||
|
||||
<button class="btn" id="torch-enable" on:click={run(enable)}>enable</button>
|
||||
<button class="btn" id="torch-disable" on:click={run(disable)}
|
||||
>disable</button
|
||||
>
|
||||
<button class="btn" id="torch-toggle" on:click={run(toggle)}>toggle</button>
|
||||
<button class="btn" id="torch-refresh" on:click={refresh}>refresh state</button
|
||||
>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<p>
|
||||
The torch can also be toggled while scanning from the Scanner page, which on
|
||||
Android goes through the barcode scanner's camera.
|
||||
</p>
|
||||
Reference in new issue
Block a user