forked from Blendman974/faceclaw
iOS QR scanning for opening EvenHub apps
This commit is contained in:
1 parent
e2b35ada1a
commit
68b459751e
8 files changed
+242
-14
No files matched your search
@@ -0,0 +1,24 @@
|
||||
declare const FaceclawQrScanner: any
|
||||
|
||||
let activeScanner: any = null
|
||||
|
||||
export function isQrScannerAvailable(): boolean { return FaceclawQrScanner.isAvailable() }
|
||||
|
||||
export function scanQrCode(): Promise<string | null> {
|
||||
if (activeScanner) return Promise.reject(new Error('A QR scan is already open.'))
|
||||
return new Promise((resolve, reject) => {
|
||||
const scanner = FaceclawQrScanner.new()
|
||||
activeScanner = scanner
|
||||
let settled = false
|
||||
const finish = (text: string | null, error: string | null) => {
|
||||
if (settled) return
|
||||
settled = true
|
||||
if (activeScanner === scanner) activeScanner = null
|
||||
error ? reject(new Error(String(error))) : resolve(text == null ? null : String(text))
|
||||
}
|
||||
try { scanner.startWithCompletion(finish) }
|
||||
catch (error) { finish(null, String(error)) }
|
||||
})
|
||||
}
|
||||
|
||||
export function cancelQrScan(): void { activeScanner?.cancel() }
|
||||
@@ -22,6 +22,10 @@ const SCAN_ACTION = "com.google.zxing.client.android.SCAN";
|
||||
// Arbitrary, only has to be distinct from other startActivityForResult callers.
|
||||
const SCAN_REQUEST_CODE = 0x51d0;
|
||||
|
||||
// Android's scanner is owned by Play Services or another app. The load layer
|
||||
// ignores its late result if the user leaves; iOS also closes its own camera.
|
||||
export function cancelQrScan(): void {}
|
||||
|
||||
function currentActivity(): any {
|
||||
return Application.android?.foregroundActivity ?? Application.android?.startActivity ?? null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user