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

Loading…
Cancel
Save