diff --git a/.eslintrc.json b/.eslintrc.json index 1b583b7..c9940fe 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -35,6 +35,9 @@ "allow": ["arrowFunctions"] } ], + "@typescript-eslint/ban-ts-comment": [ + "off" + ], "sort-imports-es6-autofix/sort-imports-es6": [ 2 ], diff --git a/src/elements/QRScanner.js b/src/elements/QRScanner.ts similarity index 66% rename from src/elements/QRScanner.js rename to src/elements/QRScanner.ts index a3b8afb..8ca6b84 100644 --- a/src/elements/QRScanner.js +++ b/src/elements/QRScanner.ts @@ -2,30 +2,35 @@ import { Margin } from "./Margin"; import { makeElement } from "../htmlUtils"; import QrScanner from 'qr-scanner'; -/* eslint-disable import/no-unresolved */ +/* eslint-disable import/no-unresolved */ +// @ts-ignore import qrScannerWorkerSource from '!!raw-loader!qr-scanner/qr-scanner-worker.min.js'; QrScanner.WORKER_PATH = URL.createObjectURL(new Blob([qrScannerWorkerSource])); -export async function QRScanner(onScan) { - let webcamVideo = makeElement({ - tag: "video" - }) +interface QRScannerType extends HTMLElement { + deinit(): void; +} - let QRInput = makeElement({ +export async function QRScanner(onScan: (code: string) => void): Promise { + const webcamVideo = makeElement({ + tag: "video" + }) as HTMLVideoElement; + + const QRInput = makeElement({ tag: "div", children: [ Margin(webcamVideo), ] - }); + }) as QRScannerType; - let stream = await navigator.mediaDevices.getUserMedia({ + const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment', }, audio: false, }); webcamVideo.srcObject = stream; - let lastSeenValue = ""; + const lastSeenValue = ""; const qrScanner = new QrScanner(webcamVideo, function (value) { if (lastSeenValue == value) return; onScan(value); diff --git a/src/pages/Unseal.js b/src/pages/Unseal.js index b9d71d5..c3c609e 100644 --- a/src/pages/Unseal.js +++ b/src/pages/Unseal.js @@ -1,6 +1,6 @@ import { MarginInline } from "../elements/MarginInline"; import { Page } from "../types/Page"; -import { QRScanner } from "../elements/QRScanner.js"; +import { QRScanner } from "../elements/QRScanner"; import { changePage, setErrorText, setPageContent } from "../pageUtils"; import { getSealStatus } from "../api/getSealStatus"; import { makeElement } from "../htmlUtils";