From cb8d8bed4c440b7c020757885dfe5443fae31523 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Mon, 10 Nov 2025 01:29:56 +0000 Subject: [PATCH] fix: improve deep link handling and consolidate cleanup methods - Fix window.location.href usage in DeepLinkRedirectView for Capacitor context: check if already in native app and use router navigation instead of window.location.href (which doesn't work in Capacitor) - Consolidate teardown() and _cleanupOnFailure() by extracting shared cleanup logic to _performCleanup() method - Make teardown() private since it's unused (kept for potential future use) - Ensure both cleanup paths reset initializationPromise for consistency This fixes navigation issues when DeepLinkRedirectView is accessed from within the Capacitor app and removes code duplication in cleanup logic. --- .../platforms/CapacitorPlatformService.ts | 42 ++++++++----------- src/views/DeepLinkRedirectView.vue | 16 +++++++ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/services/platforms/CapacitorPlatformService.ts b/src/services/platforms/CapacitorPlatformService.ts index 5a711d15..cb299784 100644 --- a/src/services/platforms/CapacitorPlatformService.ts +++ b/src/services/platforms/CapacitorPlatformService.ts @@ -164,13 +164,16 @@ export class CapacitorPlatformService } /** - * Cleanup database state on initialization failure (v3.2) + * Shared cleanup logic for database connection teardown + * Closes database connection and resets state + * + * @private Internal method used by both teardown and _cleanupOnFailure */ - private async _cleanupOnFailure(_error: unknown): Promise { + private async _performCleanup(): Promise { try { - if (this.db) { + if (await this.isDbOpen(this.db)) { try { - await this.db.close(); + await this.db?.close(); } catch (closeError) { logger.debug( "[CapacitorPlatformService] Error closing db during cleanup:", @@ -197,9 +200,17 @@ export class CapacitorPlatformService } finally { this.db = null; this.initialized = false; + this.initializationPromise = null; } } + /** + * Cleanup database state on initialization failure (v3.2) + */ + private async _cleanupOnFailure(_error: unknown): Promise { + await this._performCleanup(); + } + /** * Internal initialization method (v3.5 - Minimal refactor) * @@ -626,27 +637,10 @@ export class CapacitorPlatformService * * DO NOT call on route changes or component unmounts. * - * @public + * @private Unused - kept for potential future use */ - public async teardown(): Promise { - if (await this.isDbOpen(this.db)) { - try { - await this.db?.close(); - } catch { - // Ignore close errors - } - } - try { - await SQLITE.closeConnection( - CapacitorPlatformService.DB_NAME, - CapacitorPlatformService.READ_ONLY, - ); - } catch { - // Ignore close errors - } - this.db = null; - this.initialized = false; - this.initializationPromise = null; + private async teardown(): Promise { + await this._performCleanup(); this.connLog("teardown complete"); } diff --git a/src/views/DeepLinkRedirectView.vue b/src/views/DeepLinkRedirectView.vue index b16ec5fa..bb72e223 100644 --- a/src/views/DeepLinkRedirectView.vue +++ b/src/views/DeepLinkRedirectView.vue @@ -157,6 +157,22 @@ export default class DeepLinkRedirectView extends Vue { } try { + const capabilities = this.platformService.getCapabilities(); + + // If we're already in the native app, use router navigation instead + // of window.location.href (which doesn't work properly in Capacitor) + if (capabilities.isNativeApp) { + // Navigate directly using the router + const destinationPath = `/${this.destinationUrl}`; + this.$router.push(destinationPath).catch((error) => { + logger.error("Router navigation failed: " + errorStringForLog(error)); + this.pageError = + "Unable to navigate to the destination. Please use a manual option below."; + }); + return; + } + + // For web contexts, use window.location.href to redirect to app // For mobile, try the deep link URL; for desktop, use the web URL const redirectUrl = this.isMobile ? this.deepLinkUrl : this.webUrl;