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:
0xbizkandLucas Nogueira authored and GitHub committed 2026-10-13 05:37:04 -03:00
1 parent c91a9e6af5
commit d80b1be257
48 files changed
+1861 -4

No files matched your search

+6
View File
@@ -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
+10
View File
@@ -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">
+56
View File
@@ -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>