Browse Source

update with lint-fix

pull/133/head
Trent Larson 3 weeks ago
parent
commit
4d0463f7f7
  1. 5
      src/components/QuickNav.vue
  2. 76
      src/services/QRScanner/WebInlineQRScanner.ts
  3. 8
      src/views/ContactQRScanShowView.vue
  4. 4
      src/views/ContactQRScanView.vue

5
src/components/QuickNav.vue

@ -1,6 +1,9 @@
<template> <template>
<!-- QUICK NAV --> <!-- QUICK NAV -->
<nav id="QuickNav" class="fixed bottom-0 left-0 right-0 bg-slate-200 z-50 pb-[env(safe-area-inset-bottom)]"> <nav
id="QuickNav"
class="fixed bottom-0 left-0 right-0 bg-slate-200 z-50 pb-[env(safe-area-inset-bottom)]"
>
<ul class="flex text-2xl px-6 py-2 gap-1 max-w-3xl mx-auto"> <ul class="flex text-2xl px-6 py-2 gap-1 max-w-3xl mx-auto">
<!-- Home Feed --> <!-- Home Feed -->
<li <li

76
src/services/QRScanner/WebInlineQRScanner.ts

@ -159,7 +159,9 @@ export class WebInlineQRScanner implements QRScannerService {
async isSupported(): Promise<boolean> { async isSupported(): Promise<boolean> {
try { try {
logger.error(`[WebInlineQRScanner:${this.id}] Checking browser support...`); logger.error(
`[WebInlineQRScanner:${this.id}] Checking browser support...`,
);
// Check for secure context first // Check for secure context first
if (!window.isSecureContext) { if (!window.isSecureContext) {
logger.error( logger.error(
@ -279,23 +281,29 @@ export class WebInlineQRScanner implements QRScannerService {
// Scan for QR code // Scan for QR code
const code = jsQR(imageData.data, imageData.width, imageData.height, { const code = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: "attemptBoth", // Try both normal and inverted inversionAttempts: "attemptBoth", // Try both normal and inverted
}); });
if (code) { if (code) {
// Check if the QR code is blurry by examining the location points // Check if the QR code is blurry by examining the location points
const { topRightCorner, topLeftCorner, bottomLeftCorner } = code.location; const { topRightCorner, topLeftCorner, bottomLeftCorner } =
code.location;
const width = Math.sqrt( const width = Math.sqrt(
Math.pow(topRightCorner.x - topLeftCorner.x, 2) + Math.pow(topRightCorner.y - topLeftCorner.y, 2) Math.pow(topRightCorner.x - topLeftCorner.x, 2) +
Math.pow(topRightCorner.y - topLeftCorner.y, 2),
); );
const height = Math.sqrt( const height = Math.sqrt(
Math.pow(bottomLeftCorner.x - topLeftCorner.x, 2) + Math.pow(bottomLeftCorner.y - topLeftCorner.y, 2) Math.pow(bottomLeftCorner.x - topLeftCorner.x, 2) +
Math.pow(bottomLeftCorner.y - topLeftCorner.y, 2),
); );
// Adjust minimum size based on canvas dimensions // Adjust minimum size based on canvas dimensions
const minSize = Math.min(this.canvas.width, this.canvas.height) * 0.1; // 10% of the smaller dimension const minSize = Math.min(this.canvas.width, this.canvas.height) * 0.1; // 10% of the smaller dimension
const isBlurry = width < minSize || height < minSize || const isBlurry =
!code.data || code.data.length === 0; width < minSize ||
height < minSize ||
!code.data ||
code.data.length === 0;
logger.error(`[WebInlineQRScanner:${this.id}] QR Code detected:`, { logger.error(`[WebInlineQRScanner:${this.id}] QR Code detected:`, {
data: code.data, data: code.data,
@ -309,21 +317,27 @@ export class WebInlineQRScanner implements QRScannerService {
canvasWidth: this.canvas.width, canvasWidth: this.canvas.width,
canvasHeight: this.canvas.height, canvasHeight: this.canvas.height,
relativeWidth: width / this.canvas.width, relativeWidth: width / this.canvas.width,
relativeHeight: height / this.canvas.height relativeHeight: height / this.canvas.height,
}, },
corners: { corners: {
topLeft: topLeftCorner, topLeft: topLeftCorner,
topRight: topRightCorner, topRight: topRightCorner,
bottomLeft: bottomLeftCorner bottomLeft: bottomLeftCorner,
} },
}); });
if (isBlurry) { if (isBlurry) {
if (this.scanListener?.onError) { if (this.scanListener?.onError) {
this.scanListener.onError(new Error("QR code detected but too blurry to read. Please hold the camera steady and ensure the QR code is well-lit.")); this.scanListener.onError(
new Error(
"QR code detected but too blurry to read. Please hold the camera steady and ensure the QR code is well-lit.",
),
);
} }
// Continue scanning if QR code is blurry // Continue scanning if QR code is blurry
this.animationFrameId = requestAnimationFrame(() => this.scanQRCode()); this.animationFrameId = requestAnimationFrame(() =>
this.scanQRCode(),
);
return; return;
} }
@ -342,17 +356,21 @@ export class WebInlineQRScanner implements QRScannerService {
error: error instanceof Error ? error.message : String(error), error: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined, stack: error instanceof Error ? error.stack : undefined,
attempt: this.scanAttempts, attempt: this.scanAttempts,
videoState: this.video ? { videoState: this.video
readyState: this.video.readyState, ? {
paused: this.video.paused, readyState: this.video.readyState,
ended: this.video.ended, paused: this.video.paused,
width: this.video.videoWidth, ended: this.video.ended,
height: this.video.videoHeight width: this.video.videoWidth,
} : null, height: this.video.videoHeight,
canvasState: this.canvas ? { }
width: this.canvas.width, : null,
height: this.canvas.height canvasState: this.canvas
} : null ? {
width: this.canvas.width,
height: this.canvas.height,
}
: null,
}); });
if (this.scanListener?.onError) { if (this.scanListener?.onError) {
this.scanListener.onError( this.scanListener.onError(
@ -375,7 +393,9 @@ export class WebInlineQRScanner implements QRScannerService {
logger.error(`[WebInlineQRScanner:${this.id}] Starting scan`); logger.error(`[WebInlineQRScanner:${this.id}] Starting scan`);
// Get camera stream // Get camera stream
logger.error(`[WebInlineQRScanner:${this.id}] Requesting camera stream...`); logger.error(
`[WebInlineQRScanner:${this.id}] Requesting camera stream...`,
);
this.stream = await navigator.mediaDevices.getUserMedia({ this.stream = await navigator.mediaDevices.getUserMedia({
video: { video: {
facingMode: "environment", facingMode: "environment",
@ -441,7 +461,9 @@ export class WebInlineQRScanner implements QRScannerService {
if (this.animationFrameId !== null) { if (this.animationFrameId !== null) {
cancelAnimationFrame(this.animationFrameId); cancelAnimationFrame(this.animationFrameId);
this.animationFrameId = null; this.animationFrameId = null;
logger.error(`[WebInlineQRScanner:${this.id}] Animation frame cancelled`); logger.error(
`[WebInlineQRScanner:${this.id}] Animation frame cancelled`,
);
} }
// Stop video // Stop video
@ -490,7 +512,9 @@ export class WebInlineQRScanner implements QRScannerService {
} }
onStream(callback: (stream: MediaStream | null) => void): void { onStream(callback: (stream: MediaStream | null) => void): void {
logger.error(`[WebInlineQRScanner:${this.id}] Adding stream event listener`); logger.error(
`[WebInlineQRScanner:${this.id}] Adding stream event listener`,
);
this.events.on("stream", callback); this.events.on("stream", callback);
} }

8
src/views/ContactQRScanShowView.vue

@ -141,7 +141,9 @@
@camera-off="onCameraOff" @camera-off="onCameraOff"
/> />
<div class="absolute bottom-4 inset-x-0 flex justify-center items-center"> <div
class="absolute bottom-4 inset-x-0 flex justify-center items-center"
>
<!-- Camera Stop Button --> <!-- Camera Stop Button -->
<button <button
class="text-center text-slate-600 leading-none bg-white p-2 rounded-full drop-shadow-lg" class="text-center text-slate-600 leading-none bg-white p-2 rounded-full drop-shadow-lg"
@ -154,7 +156,8 @@
</div> </div>
<div <div
v-else v-else
class="flex items-center justify-center aspect-square overflow-hidden bg-slate-800 w-[90vw] max-w-[40vh] mx-auto"> class="flex items-center justify-center aspect-square overflow-hidden bg-slate-800 w-[90vw] max-w-[40vh] mx-auto"
>
<button <button
v-if="isNativePlatform" v-if="isNativePlatform"
class="bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white text-lg px-3 py-2 rounded-lg" class="bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white text-lg px-3 py-2 rounded-lg"
@ -181,7 +184,6 @@ import { Component, Vue } from "vue-facing-decorator";
import { useClipboard } from "@vueuse/core"; import { useClipboard } from "@vueuse/core";
import { Capacitor } from "@capacitor/core"; import { Capacitor } from "@capacitor/core";
import { QrcodeStream } from "vue-qrcode-reader"; import { QrcodeStream } from "vue-qrcode-reader";
import type { RouteLocationNormalized, NavigationGuardNext } from "vue-router";
import QuickNav from "../components/QuickNav.vue"; import QuickNav from "../components/QuickNav.vue";
import UserNameDialog from "../components/UserNameDialog.vue"; import UserNameDialog from "../components/UserNameDialog.vue";

4
src/views/ContactQRScanView.vue

@ -1,7 +1,9 @@
<template> <template>
<!-- CONTENT --> <!-- CONTENT -->
<section id="Content" class="relativew-[100vw] h-[100vh]"> <section id="Content" class="relativew-[100vw] h-[100vh]">
<div class="absolute inset-x-0 bottom-0 bg-black/50 p-6 pb-[calc(env(safe-area-inset-bottom)+1.5rem)]"> <div
class="absolute inset-x-0 bottom-0 bg-black/50 p-6 pb-[calc(env(safe-area-inset-bottom)+1.5rem)]"
>
<p class="text-center text-white mb-3"> <p class="text-center text-white mb-3">
Point your camera at a TimeSafari contact QR code to scan it Point your camera at a TimeSafari contact QR code to scan it
automatically. automatically.

Loading…
Cancel
Save