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.
This commit is contained in:
Matthew Raymer
2025-11-10 01:29:56 +00:00
parent 11658140ae
commit cb8d8bed4c
2 changed files with 34 additions and 24 deletions

View File

@@ -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<void> {
private async _performCleanup(): Promise<void> {
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<void> {
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<void> {
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<void> {
await this._performCleanup();
this.connLog("teardown complete");
}

View File

@@ -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;