forked from jsnbuchanan/crowd-funder-for-time-pwa
De-coupled web and mobile scanners
This commit is contained in:
@@ -83,12 +83,20 @@
|
|||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<router-link
|
<button
|
||||||
:to="{ name: 'contact-qr-scan' }"
|
v-if="isNativePlatform"
|
||||||
|
@click="$router.push({ name: 'contact-qr-scan' })"
|
||||||
class="bg-blue-500 text-white px-4 py-2 rounded-md mt-4"
|
class="bg-blue-500 text-white px-4 py-2 rounded-md mt-4"
|
||||||
>
|
>
|
||||||
Start Scanning
|
Start Scanning
|
||||||
</router-link>
|
</button>
|
||||||
|
<button
|
||||||
|
v-else
|
||||||
|
@click="startScanning"
|
||||||
|
class="bg-blue-500 text-white px-4 py-2 rounded-md mt-4"
|
||||||
|
>
|
||||||
|
Start Scanning
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<span v-if="error" class="text-red-500 block mt-2">{{ error }}</span>
|
<span v-if="error" class="text-red-500 block mt-2">{{ error }}</span>
|
||||||
<span v-else class="block mt-2">
|
<span v-else class="block mt-2">
|
||||||
@@ -96,6 +104,14 @@
|
|||||||
permissions.
|
permissions.
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- QR Scanner Dialog for Web -->
|
||||||
|
<QRScannerDialog
|
||||||
|
v-if="showScannerDialog"
|
||||||
|
:on-scan="onScanDetect"
|
||||||
|
:on-error="onScanError"
|
||||||
|
:on-close="closeScannerDialog"
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -104,9 +120,11 @@ import { AxiosError } from "axios";
|
|||||||
import QRCodeVue3 from "qr-code-generator-vue3";
|
import QRCodeVue3 from "qr-code-generator-vue3";
|
||||||
import { Component, Vue } from "vue-facing-decorator";
|
import { Component, Vue } from "vue-facing-decorator";
|
||||||
import { useClipboard } from "@vueuse/core";
|
import { useClipboard } from "@vueuse/core";
|
||||||
|
import { Capacitor } from "@capacitor/core";
|
||||||
|
|
||||||
import QuickNav from "../components/QuickNav.vue";
|
import QuickNav from "../components/QuickNav.vue";
|
||||||
import UserNameDialog from "../components/UserNameDialog.vue";
|
import UserNameDialog from "../components/UserNameDialog.vue";
|
||||||
|
import QRScannerDialog from "../components/QRScanner/QRScannerDialog.vue";
|
||||||
import { NotificationIface } from "../constants/app";
|
import { NotificationIface } from "../constants/app";
|
||||||
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
import { db, retrieveSettingsForActiveAccount } from "../db/index";
|
||||||
import { Contact } from "../db/tables/contacts";
|
import { Contact } from "../db/tables/contacts";
|
||||||
@@ -137,6 +155,7 @@ interface IUserNameDialog {
|
|||||||
QRCodeVue3,
|
QRCodeVue3,
|
||||||
QuickNav,
|
QuickNav,
|
||||||
UserNameDialog,
|
UserNameDialog,
|
||||||
|
QRScannerDialog,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class ContactQRScanShow extends Vue {
|
export default class ContactQRScanShow extends Vue {
|
||||||
@@ -151,6 +170,8 @@ export default class ContactQRScanShow extends Vue {
|
|||||||
qrValue = "";
|
qrValue = "";
|
||||||
isScanning = false;
|
isScanning = false;
|
||||||
error: string | null = null;
|
error: string | null = null;
|
||||||
|
showScannerDialog = false;
|
||||||
|
isNativePlatform = Capacitor.isNativePlatform();
|
||||||
|
|
||||||
ETHR_DID_PREFIX = ETHR_DID_PREFIX;
|
ETHR_DID_PREFIX = ETHR_DID_PREFIX;
|
||||||
|
|
||||||
@@ -251,7 +272,13 @@ export default class ContactQRScanShow extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add scan listener
|
// Show the scanner dialog for web
|
||||||
|
if (!this.isNativePlatform) {
|
||||||
|
this.showScannerDialog = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For native platforms, use the scanner service
|
||||||
scanner.addListener({
|
scanner.addListener({
|
||||||
onScan: this.onScanDetect,
|
onScan: this.onScanDetect,
|
||||||
onError: this.onScanError,
|
onError: this.onScanError,
|
||||||
@@ -574,6 +601,11 @@ export default class ContactQRScanShow extends Vue {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeScannerDialog() {
|
||||||
|
this.showScannerDialog = false;
|
||||||
|
this.isScanning = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Lifecycle hooks
|
// Lifecycle hooks
|
||||||
mounted() {
|
mounted() {
|
||||||
this.isMounted = true;
|
this.isMounted = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user