ask for permission

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

@ -1,5 +1,5 @@
<script>
import { scan, Format } from "@tauri-apps/plugin-barcode-scanner";
import { scan, checkPermissions, requestPermissions, Format } from "@tauri-apps/plugin-barcode-scanner";
export let onMessage;
@ -8,17 +8,25 @@
let formats = [Format.QRCode];
const supportedFormats = [Format.QRCode, Format.EAN13];
function startScan() {
scanning = true;
scan({ windowed, formats })
.then((res) => {
scanning = false;
onMessage(res);
})
.catch((error) => {
scanning = false;
onMessage(error);
});
async function startScan() {
let permission = await checkPermissions();
if (permission === 'prompt') {
permission = await requestPermissions();
}
if (permission === 'granted') {
scanning = true;
scan({ windowed, formats })
.then((res) => {
scanning = false;
onMessage(res);
})
.catch((error) => {
scanning = false;
onMessage(error);
});
} else {
onMessage('Permission denied')
}
}
</script>

Loading…
Cancel
Save