commit be8c5712669d85b7be177daacd93bc23bf7c1910
parent f9c0e8eb79b2d20ab76d421c51198102eb3f669e
Author: lash <dev@holbrook.no>
Date: Mon, 20 Feb 2023 21:42:15 +0000
Add abort for scan
Diffstat:
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/js/qrread.html b/js/qrread.html
@@ -44,6 +44,28 @@ window.addEventListener('load', () => {
const amount = document.getElementById("requestAmount").value;
return requestHandler(tokenBatch, amount);
});
+ document.getElementById('scanAbort').addEventListener("click", (o) => {
+ const e = new CustomEvent('uistate', {
+ detail: {
+ delta: STATE.SCAN_STOP,
+ settings: settings,
+ },
+ bubbles: true,
+ cancelable: true,
+ composed: false,
+ });
+ const ee = new CustomEvent('uistate', {
+ detail: {
+ delta: STATE.SCAN_DONE,
+ settings: settings,
+ },
+ bubbles: true,
+ cancelable: true,
+ composed: false,
+ });
+ window.dispatchEvent(e);
+ window.dispatchEvent(ee);
+ });
});
</script>
@@ -94,5 +116,6 @@ window.addEventListener('load', () => {
<div class="out">
<canvas id="qr-canvas" width="800" height="800"></canvas>
</div>
+ <button id="scanAbort">abort</button>
</div>
</html>
diff --git a/js/qrread.js b/js/qrread.js
@@ -4,9 +4,11 @@ const STATE = {
CHAIN_SETTINGS: 2,
CONTRACT_SETTINGS: 4,
MINT: 8,
- READ_WALLET: 16,
- TX_FLIGHT: 32,
- TX_RESULT: 64,
+ SCAN_START: 16,
+ SCAN_STOP: 32,
+ SCAN_DONE: 64,
+ TX_FLIGHT: 128,
+ TX_RESULT: 256,
};
var settings = {
diff --git a/js/qrread_ui.js b/js/qrread_ui.js
@@ -40,22 +40,34 @@ window.addEventListener('uistate', (e) => {
document.getElementById("read").style.display = "block";
live();
break;
+ case STATE.SCAN_STOP:
+ window.stream.getTracks().forEach(track => track.stop());
+ break;
+ case STATE.SCAN_DONE:
+ document.getElementById("read").style.display = "none";
+ document.getElementById("product").style.display = "block";
+ break;
+
default:
throw 'invalid state ' + e.detail.delta;
}
});
window.addEventListener('token', (e) => {
+ const ls = document.getElementById('tokenChooser');
const v = e.detail.tokenId + '.' + e.detail.batch;
const input = document.createElement('input');
input.setAttribute('id', 'tokenBatch');
input.setAttribute('name', 'tokenBatch');
input.setAttribute('type', 'radio');
input.setAttribute('value', v);
+ console.log('lastchild', ls.lastChild);
+ if (ls.lastChild === null) {
+ input.setAttribute('checked', 'checked');
+ }
const label = document.createElement('label');
label.setAttribute('for', v);
label.innerHTML = v;
- const ls = document.getElementById('tokenChooser');
ls.appendChild(input);
ls.appendChild(label);
});