From aa487d29f4d8140170dec104f94463c224a81596 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Fri, 4 Sep 2026 15:15:31 +0200 Subject: [PATCH] Gym check-in in the browser/PWA too The feature was gated behind MOBILE because scanning went through the native ML Kit plugin. iPhone users only have the PWA, so: route, Home card and Settings switch on every platform; photo import and a live camera sheet decode in the browser with BarcodeDetector where it exists and jsQR (Apache-2.0, lazy chunk) otherwise. The app build keeps ML Kit. Round-trip test lean-qr -> jsQR. --- NOTICE.md | 22 +++++-- frontend/package-lock.json | 6 ++ frontend/package.json | 1 + frontend/src/App.jsx | 8 +-- frontend/src/components/CameraScan.jsx | 69 +++++++++++++++++++++ frontend/src/index.css | 5 ++ frontend/src/lib/pt-br-locale.test.js | 2 +- frontend/src/lib/qr.js | 7 +-- frontend/src/lib/scan-web.js | 83 ++++++++++++++++++++++++++ frontend/src/lib/scan-web.test.js | 44 ++++++++++++++ frontend/src/lib/scan.js | 15 +++-- frontend/src/lib/scan.test.js | 15 +++-- frontend/src/locales/de.js | 3 + frontend/src/locales/es.js | 3 + frontend/src/locales/fr.js | 3 + frontend/src/locales/hi.js | 3 + frontend/src/locales/hu.js | 3 + frontend/src/locales/it.js | 3 + frontend/src/locales/ko.js | 3 + frontend/src/locales/pl.js | 3 + frontend/src/locales/pt-BR.js | 3 + frontend/src/locales/pt.js | 3 + frontend/src/locales/ru.js | 3 + frontend/src/locales/th.js | 3 + frontend/src/locales/tr.js | 3 + frontend/src/locales/zh.js | 3 + frontend/src/store/useStore.js | 4 +- frontend/src/views/CheckIn.jsx | 24 ++++++-- frontend/src/views/Home.jsx | 8 +-- frontend/src/views/Settings.jsx | 7 +-- 30 files changed, 315 insertions(+), 47 deletions(-) create mode 100644 frontend/src/components/CameraScan.jsx create mode 100644 frontend/src/lib/scan-web.js create mode 100644 frontend/src/lib/scan-web.test.js diff --git a/NOTICE.md b/NOTICE.md index 0ae5a0a..e5090bc 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -126,16 +126,18 @@ the source files. ## Gym check-in QR codes -The mobile-only gym check-in feature (a saved membership code shown as a QR/barcode on the phone, -added by typing, importing a photo, or scanning with the camera) uses two third-party packages. -Both are permissively licensed and compatible with openGym's AGPL, and both are bundled only in -the mobile build — the web and demo builds never ship them. +The gym check-in feature (a saved membership code shown as a QR code on the phone, added by +typing, importing a photo, or scanning with the camera) uses three third-party packages. All are +permissively licensed and compatible with openGym's AGPL, and all load on demand: the QR renderer +and the browser decoder only when a card is shown or scanned, the ML Kit plugin only in the +Android/iOS app. ### QR/barcode rendering — `lean-qr` openGym renders each saved code on the phone with [**lean-qr**](https://github.com/davidje13/lean-qr) by David Evans, used under the **MIT License** and reproduced below. Only the code's stored value is kept; the picture is generated fresh from that value each time it is shown, never stored. +It runs the same way in the app and in the browser/PWA. ``` MIT License @@ -161,9 +163,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` -### Camera scan & photo decode — `@capacitor-mlkit/barcode-scanning` +### Camera scan & photo decode in the browser — `jsQR` -Reading a code — from the camera or from an imported photo — uses the +In a browser (including the installed PWA), reading a code from the camera or from an imported +photo uses [**jsQR**](https://github.com/cozmo/jsQR) by Cosmo Wolfe, under the **Apache License +2.0** (text at and in the package's own `LICENSE`). +Where the browser has a native `BarcodeDetector`, that is tried first and jsQR is the fallback. +Video frames are decoded in memory and never uploaded or stored. + +### Camera scan & photo decode in the app — `@capacitor-mlkit/barcode-scanning` + +In the Android/iOS app, reading a code — from the camera or from an imported photo — uses the [**@capacitor-mlkit/barcode-scanning**](https://github.com/capawesome-team/capacitor-mlkit) plugin by the Capawesome Team (Robin Genz), a Capacitor wrapper around Google's ML Kit, used under the **Apache License 2.0**. openGym pins the `7.x` line to stay on Capacitor 7. The full license text is diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 9c3fcd0..5a2b94e 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -16,6 +16,7 @@ "@capacitor/filesystem": "^7.1.8", "@capacitor/local-notifications": "^7.0.7", "@capacitor/share": "^7.0.4", + "jsqr": "^1.4.0", "lean-qr": "^2.7.3", "react": "^19.2.7", "react-dom": "^19.2.7", @@ -3758,6 +3759,11 @@ "node": "*" } }, + "node_modules/jsqr": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jsqr/-/jsqr-1.4.0.tgz", + "integrity": "sha512-dxLob7q65Xg2DvstYkRpkYtmKm2sPJ9oFhrhmudT1dZvNFFTlroai3AWSpLey/w5vMcLBXRgOJsbXpdN9HzU/A==" + }, "node_modules/kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index e751b0e..39a2cf4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,6 +21,7 @@ "@capacitor/filesystem": "^7.1.8", "@capacitor/local-notifications": "^7.0.7", "@capacitor/share": "^7.0.4", + "jsqr": "^1.4.0", "lean-qr": "^2.7.3", "react": "^19.2.7", "react-dom": "^19.2.7", diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index bf5ed48..c9d70aa 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -5,7 +5,6 @@ import { useUI } from './store/useUI.js' import { bindUI } from './components/ui.jsx' import { ACCENTS } from './lib/format.js' import { setLang, useLang } from './lib/i18n.js' -import { MOBILE } from './lib/mobile.js' import { setNav } from './lib/nav.js' import { initBackButton } from './lib/back.js' import { useWakeLock } from './lib/wakelock.js' @@ -115,10 +114,9 @@ function Shell() { {!authed ? : needsMobileOnboarding ? : ( } /> - {/* Gym check-in is mobile-only — it needs the native scanner and showing a QR to - a turnstile makes no sense in a browser tab. Off mobile (or switched off in - Settings) the route falls through to the catch-all redirect below. */} - {MOBILE && S.checkIn !== false && } />} + {/* Gym check-in — switched off in Settings, the route falls through to the + catch-all redirect below. */} + {S.checkIn !== false && } />} } /> } /> } /> diff --git a/frontend/src/components/CameraScan.jsx b/frontend/src/components/CameraScan.jsx new file mode 100644 index 0000000..dc04aba --- /dev/null +++ b/frontend/src/components/CameraScan.jsx @@ -0,0 +1,69 @@ +import { useEffect, useRef, useState } from 'react' +import { t } from '../lib/i18n.js' +import { decodeSource } from '../lib/scan-web.js' +import { Button } from '../components/ui.jsx' + +// Live camera scanner for the browser/PWA (the app build uses ML Kit's own UI instead — see +// lib/scan.js). Opens the rear camera into a