fix: barcode scanner WASM loading and Android camera permission
All checks were successful
CI / update (push) Successful in 1m5s

- Exclude barcode-detector from Vite optimizeDeps to prevent WASM mangling
- Self-host ZXing WASM via Vite ?url import with prepareZXingModule
- Use barcode-detector/ponyfill instead of deprecated /pure export
- Separate barcode-detector/zxing-wasm into own chunk
- Add CAMERA permission to Android manifest for Tauri app
This commit is contained in:
2026-04-05 12:23:13 +02:00
parent b7397898e3
commit 3daa5b65c5
3 changed files with 21 additions and 2 deletions

View File

@@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.CAMERA" />
<!-- AndroidTV support --> <!-- AndroidTV support -->
<uses-feature android:name="android.software.leanback" android:required="false" /> <uses-feature android:name="android.software.leanback" android:required="false" />

View File

@@ -209,12 +209,24 @@
await videoEl.play(); await videoEl.play();
scanDebug += ` | video: ${videoEl.videoWidth}x${videoEl.videoHeight}`; scanDebug += ` | video: ${videoEl.videoWidth}x${videoEl.videoHeight}`;
// Import barcode-detector/pure — ZXing WASM-based ponyfill // Import barcode-detector ponyfill with self-hosted WASM
scanDebug += ' | importing detector…'; scanDebug += ' | importing detector…';
let BarcodeDetector; let BarcodeDetector;
try { try {
const mod = await import('barcode-detector/pure'); const mod = await import('barcode-detector/ponyfill');
BarcodeDetector = mod.BarcodeDetector; BarcodeDetector = mod.BarcodeDetector;
// Point ZXing WASM to our self-hosted copy via Vite ?url import
const { prepareZXingModule } = await import('barcode-detector/ponyfill');
const wasmModule = await import('zxing-wasm/reader/zxing_reader.wasm?url');
prepareZXingModule({
overrides: {
locateFile: (path, prefix) => {
if (path.endsWith('.wasm')) return wasmModule.default;
return prefix + path;
},
},
});
scanDebug += ' OK'; scanDebug += ' OK';
} catch (importErr) { } catch (importErr) {
scanDebug = `IMPORT ERROR: ${importErr?.message ?? importErr}`; scanDebug = `IMPORT ERROR: ${importErr?.message ?? importErr}`;

View File

@@ -6,6 +6,9 @@ export default defineConfig({
allowedHosts: ["bocken.org"] allowedHosts: ["bocken.org"]
}, },
plugins: [sveltekit()], plugins: [sveltekit()],
optimizeDeps: {
exclude: ['barcode-detector']
},
build: { build: {
minify: 'terser', minify: 'terser',
terserOptions: { terserOptions: {
@@ -25,6 +28,9 @@ export default defineConfig({
if (id.includes('@auth/sveltekit')) { if (id.includes('@auth/sveltekit')) {
return 'auth'; return 'auth';
} }
if (id.includes('barcode-detector') || id.includes('zxing-wasm')) {
return 'barcode';
}
} }
} }
} }