Compare commits

...
5 Commits
15 changed files with 307 additions and 120 deletions
+3 -3
View File
@@ -1154,7 +1154,7 @@ export GEM_PATH=$shortened_path
###### 1. Bump the version in package.json & CHANGELOG.md for `MARKETING_VERSION`, then `grep CURRENT_PROJECT_VERSION ios/App/App.xcodeproj/project.pbxproj` and add 1 for the numbered version here:
```bash
cd ios/App && xcrun agvtool new-version 78 && perl -p -i -e "s/MARKETING_VERSION = .*;/MARKETING_VERSION = 1.4.12;/g" App.xcodeproj/project.pbxproj && cd -
cd ios/App && xcrun agvtool new-version 79 && perl -p -i -e "s/MARKETING_VERSION = .*;/MARKETING_VERSION = 1.4.13;/g" App.xcodeproj/project.pbxproj && cd -
# Unfortunately this edits Info.plist directly.
#xcrun agvtool new-marketing-version 0.4.5
```
@@ -1446,8 +1446,8 @@ The recommended way to build for Android is using the automated build script:
##### 1. Bump the version in package.json, then update these versions & run:
```bash
perl -p -i -e 's/versionCode .*/versionCode 78/g' android/app/build.gradle
perl -p -i -e 's/versionName .*/versionName "1.4.12"/g' android/app/build.gradle
perl -p -i -e 's/versionCode .*/versionCode 79/g' android/app/build.gradle
perl -p -i -e 's/versionName .*/versionName "1.4.13"/g' android/app/build.gradle
```
##### 2. Build
+2 -1
View File
@@ -6,10 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.4.13]
## [1.4.13] - 2026.11.10
### Fixed
- Tapping the New Activity notification opens New Activity, including when that tap is what launches the app. Receiving the notification does not open it.
### Changed
- SMS notifications are the default in settings, followed by advanced ones: push, on-device, and reminder.
- The iOS camera and location permission prompts say Giftopia. The location prompts say it is used to find people and projects nearby, and the "always" location prompt has a message too.
+2 -2
View File
@@ -39,8 +39,8 @@ android {
applicationId "app.timesafari.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 78
versionName "1.4.12"
versionCode 79
versionName "1.4.13"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
+8 -8
View File
@@ -568,7 +568,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = App/AppDebug.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 78;
CURRENT_PROJECT_VERSION = 79;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_APP_SANDBOX = NO;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -580,7 +580,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.12;
MARKETING_VERSION = 1.4.13;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -599,7 +599,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 78;
CURRENT_PROJECT_VERSION = 79;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_APP_SANDBOX = NO;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -611,7 +611,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.12;
MARKETING_VERSION = 1.4.13;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
@@ -629,7 +629,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = TimeSafariShareExtension/TimeSafariShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 78;
CURRENT_PROJECT_VERSION = 79;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
FIREBASE_ENABLED = YES;
@@ -645,7 +645,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.4.12;
MARKETING_VERSION = 1.4.13;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari.TimeSafariShareExtension;
@@ -669,7 +669,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = TimeSafariShareExtension/TimeSafariShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 78;
CURRENT_PROJECT_VERSION = 79;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
FIREBASE_ENABLED = YES;
@@ -685,7 +685,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.4.12;
MARKETING_VERSION = 1.4.13;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari.TimeSafariShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "giftopia",
"version": "1.4.13-beta",
"version": "1.4.14-beta",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "giftopia",
"version": "1.4.13-beta",
"version": "1.4.14-beta",
"dependencies": {
"@capacitor-community/electron": "^5.0.1",
"@capacitor-community/sqlite": "^7.0.3",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "giftopia",
"version": "1.4.13-beta",
"version": "1.4.14-beta",
"description": "Giftopia App",
"author": {
"name": "Gift Economies Team"
+2 -2
View File
@@ -516,9 +516,9 @@ export default class ImageMethodDialog extends Vue {
}
/**
* Lifecycle hook: Cleans up camera stream when component is destroyed
* Lifecycle hook: Cleans up camera stream when component is unmounted
*/
beforeDestroy() {
beforeUnmount() {
this.stopCameraPreview();
}
+1 -1
View File
@@ -844,7 +844,7 @@ export default class MeetingMembersList extends Vue {
}
}
beforeDestroy() {
beforeUnmount() {
this.stopAutoRefresh();
}
}
+2 -2
View File
@@ -288,9 +288,9 @@ export default class PhotoDialog extends Vue {
}
/**
* Lifecycle hook: Cleans up camera stream when component is destroyed
* Lifecycle hook: Cleans up camera stream when component is unmounted
*/
beforeDestroy() {
beforeUnmount() {
this.stopCameraPreview();
}
+34 -3
View File
@@ -20,13 +20,40 @@
<code class="text-[11px] break-all">{{ activeBackendUrl }}</code>
</p>
<button
class="w-full text-sm mb-4 px-3 py-2 rounded border border-slate-300 bg-white"
v-if="backendUrlDraft.trim() !== savedBackendUrl"
class="w-full text-sm mb-2 px-3 py-1 rounded bg-blue-600 border border-blue-700 text-white"
:disabled="busy"
:class="{ 'opacity-50 cursor-not-allowed': busy }"
@click="onSaveBackendUrl"
>
Save Backend URL
Confirm this change
</button>
<div class="mb-4" role="group" aria-label="Quick notify server selection">
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
aria-label="Use production notify server URL"
:disabled="busy"
@click="backendUrlDraft = AppString.PROD_NOTIFY_API_SERVER"
>
Use Prod
</button>
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
aria-label="Use test notify server URL"
:disabled="busy"
@click="backendUrlDraft = AppString.TEST_NOTIFY_API_SERVER"
>
Use Test
</button>
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
aria-label="Use local notify server URL"
:disabled="busy"
@click="backendUrlDraft = AppString.LOCAL_NOTIFY_API_SERVER"
>
Use Local
</button>
</div>
<label class="flex items-center gap-2 text-sm mb-4 cursor-pointer">
<input
@@ -263,6 +290,7 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
import { AppString } from "@/constants/app";
import { copyToClipboard } from "@/services/ClipboardService";
import { subscribe } from "@/services/notifications/NotificationDebugEvents";
import { NotificationDebugService } from "@/services/notifications/NotificationDebugService";
@@ -279,6 +307,8 @@ const busy = ref(false);
const pending = ref<PendingInfo[]>([]);
const pendingInspectorMessage = ref<string | null>(null);
const backendUrlDraft = ref("");
/** The saved override ("" when using the default), to detect an unconfirmed draft. */
const savedBackendUrl = ref("");
const testModeEnabled = ref(NotificationDebugService.isTestModeEnabled());
const bypassAuthEnabled = ref(NotificationDebugService.isBypassAuthEnabled());
const fcmToken = ref<string | null>(NotificationDebugService.getFcmToken());
@@ -335,8 +365,9 @@ async function onClearNotifications(): Promise<void> {
}
function syncBackendState(): void {
backendUrlDraft.value =
savedBackendUrl.value =
NotificationDebugService.getBackendUrlOverride() ?? "";
backendUrlDraft.value = savedBackendUrl.value;
testModeEnabled.value = NotificationDebugService.isTestModeEnabled();
bypassAuthEnabled.value = NotificationDebugService.isBypassAuthEnabled();
fcmToken.value = NotificationDebugService.getFcmToken();
+25
View File
@@ -71,6 +71,17 @@ const routes: Array<RouteRecordRaw> = [
path: "/contact-qr",
name: "contact-qr",
component: () => import("../views/ContactQRScanShowView.vue"),
// This view scans with the in-page web reader; native platforms use the
// full-screen view, which wires up the native scanner.
beforeEnter: async (to) => {
const { QRNavigationService } = await import(
"../services/QRNavigationService"
);
const target = QRNavigationService.getInstance().getQRScannerRoute();
return target.name === to.name
? true
: { name: target.name, query: to.query, replace: true };
},
},
{
path: "/contact-qr-scan-full",
@@ -464,8 +475,22 @@ router.beforeEach(async (to, _from, next) => {
}
});
const QR_SCAN_ROUTE_NAMES = new Set(["contact-qr", "contact-qr-scan-full"]);
// Add navigation success logging and scroll-to-top (app uses #app as scroll container, not window)
router.afterEach((to, from) => {
// Fallback for the scan views' beforeRouteLeave cleanup: a native scanner left
// running keeps the WebView transparent, with the camera showing behind every
// page. The module is already loaded whenever a scan view was the "from" route.
if (
QR_SCAN_ROUTE_NAMES.has(String(from?.name)) &&
!QR_SCAN_ROUTE_NAMES.has(String(to.name))
) {
import("../services/QRScanner/QRScannerFactory")
.then(({ QRScannerFactory }) => QRScannerFactory.cleanup())
.catch((error) => logger.error("[Router] QR scanner cleanup:", error));
}
const app = document.getElementById("app");
if (app) {
app.scrollTop = 0;
+89 -15
View File
@@ -21,6 +21,9 @@ export class CapacitorQRScanner implements QRScannerService {
private cameraStateListeners: Set<CameraStateListener> = new Set();
private currentState: CameraState = "off";
private currentStateMessage?: string;
/** Incremented by every stopScan(); lets an in-progress start notice it. */
private scanGeneration = 0;
private startPromise: Promise<void> | null = null;
async checkPermissions(): Promise<boolean> {
try {
@@ -77,28 +80,68 @@ export class CapacitorQRScanner implements QRScannerService {
}
async startScan(options?: QRScannerOptions): Promise<void> {
// Serialize starts: a start that is still finishing could otherwise call
// the native stopScan() after this one has started the camera.
// Re-check after each wait, since another caller may have started meanwhile.
for (;;) {
if (this.startPromise) {
await this.startPromise.catch(() => undefined);
} else if (this.cleanupPromise) {
logger.debug("Waiting for previous cleanup to complete");
await this.cleanupPromise.catch(() => undefined);
} else {
break;
}
}
if (this.isScanning) {
logger.debug("Scanner already running");
return;
}
if (this.cleanupPromise) {
logger.debug("Waiting for previous cleanup to complete");
await this.cleanupPromise;
const startPromise = this.runStartScan(options);
this.startPromise = startPromise;
try {
await startPromise;
} finally {
if (this.startPromise === startPromise) {
this.startPromise = null;
}
}
}
/**
* Starts the native scanner. Every stopScan() increments scanGeneration; when
* it changes during one of the awaits below, the start is abandoned, and a
* camera that already started is stopped again. Without this, a stop that
* lands mid-start is a no-op and the camera stays on behind a transparent
* WebView.
*/
private async runStartScan(options?: QRScannerOptions): Promise<void> {
this.isScanning = true;
const generation = ++this.scanGeneration;
const stopRequested = () => generation !== this.scanGeneration;
try {
this.updateCameraState("initializing", "Starting camera...");
// Ensure we have permissions before starting
if (!(await this.checkPermissions())) {
this.updateCameraState("permission_denied", "Camera permission denied");
logger.debug("Requesting camera permissions");
const granted = await this.requestPermissions();
if (!granted) {
this.updateCameraState(
"permission_denied",
"Camera permission denied",
);
throw new Error("Camera permission denied");
}
}
if (stopRequested()) {
logger.debug("Stop requested during permission check; not starting");
this.updateCameraState("off", "Camera stopped");
return;
}
// Check if scanning is supported
if (!(await this.isSupported())) {
@@ -108,10 +151,13 @@ export class CapacitorQRScanner implements QRScannerService {
);
throw new Error("QR scanning not supported on this device");
}
if (stopRequested()) {
logger.debug("Stop requested during support check; not starting");
this.updateCameraState("off", "Camera stopped");
return;
}
logger.info("Starting MLKit scanner");
this.isScanning = true;
this.updateCameraState("active", "Camera is active");
const scanOptions: StartScanOptions = {
formats: [BarcodeFormat.QrCode],
@@ -121,7 +167,7 @@ export class CapacitorQRScanner implements QRScannerService {
logger.debug("Scanner options:", scanOptions);
// Add listener for barcode scans
// Add listener for barcode scans; stopScan() removes it again
const handle = await BarcodeScanner.addListener(
"barcodesScanned",
(result) => {
@@ -131,9 +177,24 @@ export class CapacitorQRScanner implements QRScannerService {
},
);
this.listenerHandles.push(handle.remove);
if (stopRequested()) {
logger.debug("Stop requested while adding listener; not starting");
await this.removeNativeListeners();
this.updateCameraState("off", "Camera stopped");
return;
}
// Start continuous scanning
await BarcodeScanner.startScan(scanOptions);
if (stopRequested()) {
logger.debug("Stop requested while camera was starting; stopping it");
await this.removeNativeListeners();
await BarcodeScanner.stopScan();
this.updateCameraState("off", "Camera stopped");
return;
}
this.updateCameraState("active", "Camera is active");
logger.info("MLKit scanner started successfully");
} catch (error) {
const wrappedError =
@@ -142,7 +203,9 @@ export class CapacitorQRScanner implements QRScannerService {
error: wrappedError.message,
stack: wrappedError.stack,
});
this.isScanning = false;
if (generation === this.scanGeneration) {
this.isScanning = false;
}
this.updateCameraState("error", wrappedError.message);
await this.cleanup();
this.scanListener?.onError?.(wrappedError);
@@ -151,6 +214,10 @@ export class CapacitorQRScanner implements QRScannerService {
}
async stopScan(): Promise<void> {
// Invalidate any start that is still in progress, even when the native
// camera has not started yet.
this.scanGeneration++;
if (!this.isScanning) {
logger.debug("Scanner not running");
return;
@@ -159,6 +226,7 @@ export class CapacitorQRScanner implements QRScannerService {
try {
logger.debug("Stopping QR scanner");
this.updateCameraState("off", "Camera stopped");
await this.removeNativeListeners();
await BarcodeScanner.stopScan();
logger.info("QR scanner stopped successfully");
} catch (error) {
@@ -176,6 +244,18 @@ export class CapacitorQRScanner implements QRScannerService {
}
}
private async removeNativeListeners(): Promise<void> {
const handles = this.listenerHandles;
this.listenerHandles = [];
for (const remove of handles) {
try {
await remove();
} catch (error) {
logger.warn("Error removing listener:", error);
}
}
}
addListener(listener: ScanListener): void {
this.scanListener = listener;
}
@@ -196,13 +276,7 @@ export class CapacitorQRScanner implements QRScannerService {
}
// Remove all listeners
for (const handle of this.listenerHandles) {
try {
await handle();
} catch (error) {
logger.warn("Error removing listener:", error);
}
}
await this.removeNativeListeners();
logger.info("QR scanner cleanup completed");
} catch (error) {
+8 -29
View File
@@ -846,17 +846,11 @@
</div>
<button
v-if="apiServerInput != apiServer"
class="w-full px-4 rounded bg-yellow-500 border border-slate-400"
class="w-full mt-2 px-4 py-1 rounded bg-blue-600 border border-blue-700 text-white"
aria-label="Save API server URL"
@click="onClickSaveApiServer()"
>
<font-awesome
icon="floppy-disk"
class="fa-fw"
color="white"
aria-hidden="true"
></font-awesome>
<span class="text-white">Unsaved</span>
Confirm this change
</button>
<div class="mt-2" role="group" aria-label="Quick server selection">
<button
@@ -946,15 +940,10 @@
/>
<button
v-if="webPushServerInput != webPushServer"
class="w-full px-4 rounded bg-yellow-500 border border-slate-400"
class="w-full mt-2 px-4 py-1 rounded bg-blue-600 border border-blue-700 text-white"
@click="onClickSavePushServer()"
>
<font-awesome
icon="floppy-disk"
class="fa-fw"
color="white"
></font-awesome>
<span class="text-white">Unsaved</span>
Confirm this change
</button>
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
@@ -993,15 +982,10 @@
/>
<button
v-if="partnerApiServerInput != partnerApiServer"
class="w-full px-4 rounded bg-yellow-500 border border-slate-400"
class="w-full mt-2 px-4 py-1 rounded bg-blue-600 border border-blue-700 text-white"
@click="onClickSavePartnerServer()"
>
<font-awesome
icon="floppy-disk"
class="fa-fw"
color="white"
></font-awesome>
<span class="text-white">Unsaved</span>
Confirm this change
</button>
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
@@ -1043,15 +1027,10 @@
/>
<button
v-if="imageServerInput != imageServer"
class="w-full px-4 rounded bg-yellow-500 border border-slate-400"
class="w-full mt-2 px-4 py-1 rounded bg-blue-600 border border-blue-700 text-white"
@click="onClickSaveImageServer()"
>
<font-awesome
icon="floppy-disk"
class="fa-fw"
color="white"
></font-awesome>
<span class="text-white">Unsaved</span>
Confirm this change
</button>
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
+41 -8
View File
@@ -108,7 +108,7 @@
<script lang="ts">
import { Buffer } from "buffer/";
import QRCodeVue3 from "qr-code-generator-vue3";
import { Component, Vue } from "vue-facing-decorator";
import { Component, Hook, Vue } from "vue-facing-decorator";
import { Router } from "vue-router";
import { copyToClipboard } from "../services/ClipboardService";
@@ -230,6 +230,10 @@ export default class ContactQRScanFull extends Vue {
// Add cleanup tracking
private isCleaningUp = false;
private isMounted = false;
// Incremented by stopScanning() so an in-progress startScanning() can bail out
private scanRequestId = 0;
private resumeScanOnResume = false;
private pendingPauseStop: Promise<void> | null = null;
/**
* Computed property for QR code container CSS classes
@@ -333,6 +337,8 @@ export default class ContactQRScanFull extends Vue {
return;
}
const requestId = ++this.scanRequestId;
const stopRequested = () => requestId !== this.scanRequestId;
try {
this.error = null;
this.isScanning = true;
@@ -364,6 +370,11 @@ export default class ContactQRScanFull extends Vue {
return;
}
}
// A stop (route leave, app pause) may have arrived during the awaits above
if (stopRequested()) {
logger.debug("Scan stopped before camera start; not starting");
return;
}
// Add scan listener
scanner.addListener({
@@ -388,6 +399,7 @@ export default class ContactQRScanFull extends Vue {
* @throws Will log error if stopping scan fails
*/
async stopScanning() {
this.scanRequestId++;
try {
const scanner = QRScannerFactory.getInstance();
await scanner.stopScan();
@@ -708,10 +720,21 @@ export default class ContactQRScanFull extends Vue {
}
/**
* Vue lifecycle hook - component before destruction
* Route guard - stops the native camera before navigating away, for every
* exit (hardware back, swipe-back, links), not only the in-page back button.
* Unlike beforeUnmount, a route guard can wait for the native stop.
*/
@Hook
async beforeRouteLeave() {
this.isMounted = false;
await this.cleanupScanner();
}
/**
* Vue lifecycle hook - component before unmount
* Cleans up event listeners and scanner resources
*/
beforeDestroy() {
beforeUnmount() {
this.isMounted = false;
document.removeEventListener("pause", this.handleAppPause);
document.removeEventListener("resume", this.handleAppResume);
@@ -725,17 +748,27 @@ export default class ContactQRScanFull extends Vue {
if (!this.isMounted) return;
logger.debug("App paused, stopping scanner");
await this.stopScanning();
// A pause can arrive mid-start, e.g. from the Android camera permission dialog
this.resumeScanOnResume = this.isScanning;
this.pendingPauseStop = this.stopScanning();
await this.pendingPauseStop;
}
/**
* Handles app resume event by resetting scanner state
* Handles app resume event by restarting the scanner if a pause stopped it
*/
handleAppResume() {
async handleAppResume() {
if (!this.isMounted) return;
logger.debug("App resumed, scanner can be restarted by user");
this.isScanning = false;
await this.pendingPauseStop;
this.pendingPauseStop = null;
if (this.resumeScanOnResume && this.isMounted) {
logger.debug("App resumed, restarting scanner");
this.resumeScanOnResume = false;
await this.startScanning();
} else {
this.isScanning = false;
}
}
/**
+87 -43
View File
@@ -145,7 +145,7 @@
import { AxiosError } from "axios";
import { Buffer } from "buffer/";
import QRCodeVue3 from "qr-code-generator-vue3";
import { Component, Vue } from "vue-facing-decorator";
import { Component, Hook, Vue } from "vue-facing-decorator";
import { copyToClipboard } from "../services/ClipboardService";
import { QrcodeStream } from "vue-qrcode-reader";
@@ -167,7 +167,7 @@ import * as libsUtil from "../libs/util";
import { Router } from "vue-router";
import { logger } from "../utils/logger";
import { QRScannerFactory } from "@/services/QRScanner/QRScannerFactory";
import { CameraState } from "@/services/QRScanner/types";
import { CameraState, CameraStateListener } from "@/services/QRScanner/types";
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
import { createNotifyHelpers } from "@/utils/notify";
import { showSeedPhraseReminder } from "@/utils/seedPhraseReminder";
@@ -250,6 +250,12 @@ export default class ContactQRScanShow extends Vue {
// Add cleanup tracking
private isCleaningUp = false;
private isMounted = false;
// Incremented by stopScanning() so an in-progress startScanning() can bail out
private scanRequestId = 0;
// Registered once and removed on cleanup, so restarts don't pile up listeners
private cameraStateListener: CameraStateListener | null = null;
private resumeScanOnResume = false;
private pendingPauseStop: Promise<void> | null = null;
// Add property to track if we're on desktop
private isDesktop = false;
@@ -350,6 +356,7 @@ export default class ContactQRScanShow extends Vue {
return;
}
const requestId = ++this.scanRequestId;
try {
this.error = null;
this.isScanning = true;
@@ -358,42 +365,48 @@ export default class ContactQRScanShow extends Vue {
const scanner = QRScannerFactory.getInstance();
// Add camera state listener
scanner.addCameraStateListener({
onStateChange: (state, message) => {
this.cameraState = state;
this.cameraStateMessage = message;
// Add camera state listener (once; the scanner keeps them in a Set)
if (!this.cameraStateListener) {
this.cameraStateListener = {
onStateChange: (state, message) => {
this.cameraState = state;
this.cameraStateMessage = message;
// Update UI based on camera state
switch (state) {
case "in_use":
this.error = "Camera is in use by another application";
this.isScanning = false;
this.notify.warning(
NOTIFY_QR_CAMERA_IN_USE.message,
QR_TIMEOUT_LONG,
);
break;
case "permission_denied":
this.error = "Camera permission denied";
this.isScanning = false;
this.notify.warning(
NOTIFY_QR_CAMERA_ACCESS_REQUIRED.message,
QR_TIMEOUT_LONG,
);
break;
case "not_found":
this.error = "No camera found";
this.isScanning = false;
this.notify.warning(NOTIFY_QR_NO_CAMERA.message, QR_TIMEOUT_LONG);
break;
case "error":
this.error = this.cameraStateMessage || "Camera error";
this.isScanning = false;
break;
}
},
});
// Update UI based on camera state
switch (state) {
case "in_use":
this.error = "Camera is in use by another application";
this.isScanning = false;
this.notify.warning(
NOTIFY_QR_CAMERA_IN_USE.message,
QR_TIMEOUT_LONG,
);
break;
case "permission_denied":
this.error = "Camera permission denied";
this.isScanning = false;
this.notify.warning(
NOTIFY_QR_CAMERA_ACCESS_REQUIRED.message,
QR_TIMEOUT_LONG,
);
break;
case "not_found":
this.error = "No camera found";
this.isScanning = false;
this.notify.warning(
NOTIFY_QR_NO_CAMERA.message,
QR_TIMEOUT_LONG,
);
break;
case "error":
this.error = this.cameraStateMessage || "Camera error";
this.isScanning = false;
break;
}
},
};
}
scanner.addCameraStateListener(this.cameraStateListener);
// Check if scanning is supported first
if (!(await scanner.isSupported())) {
@@ -403,8 +416,12 @@ export default class ContactQRScanShow extends Vue {
this.notify.warning(NOTIFY_QR_HTTPS_REQUIRED.message, QR_TIMEOUT_LONG);
return;
}
if (requestId !== this.scanRequestId) {
logger.debug("Scan stopped before camera start; not starting");
return;
}
// Start scanning
// Start scanning (the scanner abandons this start if stopScan() is called)
await scanner.startScan();
} catch (error) {
this.error = error instanceof Error ? error.message : String(error);
@@ -417,6 +434,7 @@ export default class ContactQRScanShow extends Vue {
}
async stopScanning() {
this.scanRequestId++;
try {
const scanner = QRScannerFactory.getInstance();
await scanner.stopScan();
@@ -441,6 +459,11 @@ export default class ContactQRScanShow extends Vue {
try {
logger.debug("Cleaning up QR scanner resources");
await this.stopScanning();
if (this.cameraStateListener) {
QRScannerFactory.getInstance().removeCameraStateListener(
this.cameraStateListener,
);
}
await QRScannerFactory.cleanup();
} catch (error) {
logger.error("Error during scanner cleanup:", {
@@ -692,7 +715,18 @@ export default class ContactQRScanShow extends Vue {
}, 1000);
}
beforeDestroy() {
/**
* Stop the native camera before navigating away. This covers every exit
* (hardware back, swipe-back, links), not only the in-page back button.
* Unlike beforeUnmount, a route guard can wait for the native stop.
*/
@Hook
async beforeRouteLeave() {
this.isMounted = false;
await this.cleanupScanner();
}
beforeUnmount() {
this.isMounted = false;
document.removeEventListener("pause", this.handleAppPause);
document.removeEventListener("resume", this.handleAppResume);
@@ -703,14 +737,24 @@ export default class ContactQRScanShow extends Vue {
if (!this.isMounted) return;
logger.debug("App paused, stopping scanner");
await this.stopScanning();
// A pause can arrive mid-start, e.g. from the Android camera permission dialog
this.resumeScanOnResume = this.isScanning;
this.pendingPauseStop = this.stopScanning();
await this.pendingPauseStop;
}
handleAppResume() {
async handleAppResume() {
if (!this.isMounted) return;
logger.debug("App resumed, scanner can be restarted by user");
this.isScanning = false;
await this.pendingPauseStop;
this.pendingPauseStop = null;
if (this.resumeScanOnResume && this.isMounted) {
logger.debug("App resumed, restarting scanner");
this.resumeScanOnResume = false;
await this.startScanning();
} else {
this.isScanning = false;
}
}
async addNewContact(contact: Contact) {