From d93801501e31f68b01aca87f40477cbb22d7068d Mon Sep 17 00:00:00 2001 From: Marvin Sextro Date: Sun, 25 Jul 2021 02:14:09 +0200 Subject: [PATCH] Error to enforce Safari --- components/Form.tsx | 17 +++++++++++++++-- public/locales/de/errors.yml | 3 ++- public/locales/en/errors.yml | 3 ++- public/locales/fi/errors.yml | 3 ++- public/locales/fr/errors.yml | 3 ++- public/locales/nl/errors.yml | 3 ++- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/components/Form.tsx b/components/Form.tsx index 6115285..05e6b47 100644 --- a/components/Form.tsx +++ b/components/Form.tsx @@ -73,7 +73,14 @@ function Form(): JSX.Element { const codeReader = new BrowserQRCodeReader(); // Needs to be called before any camera can be accessed - const deviceList = await BrowserQRCodeReader.listVideoInputDevices(); + let deviceList: MediaDeviceInfo[]; + + try { + deviceList = await BrowserQRCodeReader.listVideoInputDevices(); + } catch (e) { + setErrorMessage('noCameraAccess'); + return; + } // Check access to camera device if (deviceList.length == 0) { @@ -101,7 +108,7 @@ function Form(): JSX.Element { setIsCameraOpen(false); } if (error !== undefined) { - setErrorMessage("noCameraAccess"); + setErrorMessage(error.message); } } ) @@ -115,6 +122,12 @@ function Form(): JSX.Element { event.preventDefault(); setLoading(true); + if(navigator.userAgent.match('CriOS')) { + setErrorMessage('safariSupportOnly'); + setLoading(false); + return; + } + if (!file && !qrCode) { setErrorMessage('noFileOrQrCode') setLoading(false); diff --git a/public/locales/de/errors.yml b/public/locales/de/errors.yml index 84f374f..6933e7a 100644 --- a/public/locales/de/errors.yml +++ b/public/locales/de/errors.yml @@ -16,4 +16,5 @@ certificateType: Kein gültiger Zertifikatstyp gefunden invalidTestResult: Ungültiges Testergebnis invalidTestType: Ungültiger Testtyp noCameraAccess: Kein Zugriff auf die Kamera möglich. Überprüfe die Berechtigungen unter Einstellungen > Safari > Kamera. -noCameraFound: Keine Kamera gefunden. \ No newline at end of file +noCameraFound: Keine Kamera gefunden. +safariSupportOnly: Bitte verwende unter iOS den Safari Browser. \ No newline at end of file diff --git a/public/locales/en/errors.yml b/public/locales/en/errors.yml index cfea084..0dcc155 100644 --- a/public/locales/en/errors.yml +++ b/public/locales/en/errors.yml @@ -16,4 +16,5 @@ certificateType: No valid certificate type found invalidTestResult: Invalid test result invalidTestType: Invalid test type noCameraAccess: Could not access camera. Check permissions under Settings > Safari > Camera. -noCameraFound: Could not find camera. \ No newline at end of file +noCameraFound: Could not find camera. +safariSupportOnly: On iOS, please use the Safari Browser. \ No newline at end of file diff --git a/public/locales/fi/errors.yml b/public/locales/fi/errors.yml index 7159ffe..35ab1fd 100644 --- a/public/locales/fi/errors.yml +++ b/public/locales/fi/errors.yml @@ -16,4 +16,5 @@ certificateType: Kelvollista varmennetyyppiä ei löytynyt invalidTestResult: Virheellinen testitulos invalidTestType: Virheellinen testityyppi noCameraAccess: Kameraan ei päässyt käsiksi. Tarkista käyttöoikeudet kohdasta Asetukset > Safari > Kamera. -noCameraFound: En löytänyt kameraa. \ No newline at end of file +noCameraFound: En löytänyt kameraa. +safariSupportOnly: Käytä iOS:ssä Safari-selainta. \ No newline at end of file diff --git a/public/locales/fr/errors.yml b/public/locales/fr/errors.yml index 4b6e6fc..dc3119e 100644 --- a/public/locales/fr/errors.yml +++ b/public/locales/fr/errors.yml @@ -16,4 +16,5 @@ certificateType: Aucun type de certificat valide n'a été trouvé invalidTestResult: Résultat du test non valide invalidTestType: Type de test non valide noCameraAccess: Impossible d'accéder à la caméra. Vérifiez les autorisations sous Paramètres > Safari > Appareil photo. -noCameraFound: Impossible de trouver la caméra. \ No newline at end of file +noCameraFound: Impossible de trouver la caméra. +safariSupportOnly: Sur iOS, veuillez utiliser le navigateur Safari. \ No newline at end of file diff --git a/public/locales/nl/errors.yml b/public/locales/nl/errors.yml index cf7f86e..1677032 100644 --- a/public/locales/nl/errors.yml +++ b/public/locales/nl/errors.yml @@ -16,4 +16,5 @@ certificateType: Geen geldig certificaattype gevonden invalidTestResult: Ongeldig testresultaat invalidTestType: Ongeldig testtype noCameraAccess: Kon geen toegang krijgen tot de camera. Controleer de machtigingen onder Instellingen > Safari > Camera. -noCameraFound: Ik kon de camera niet vinden. \ No newline at end of file +noCameraFound: Ik kon de camera niet vinden. +safariSupportOnly: Gebruik op iOS de Safari-browser. \ No newline at end of file