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:
@@ -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 {
|
try {
|
||||||
if (this.db) {
|
if (await this.isDbOpen(this.db)) {
|
||||||
try {
|
try {
|
||||||
await this.db.close();
|
await this.db?.close();
|
||||||
} catch (closeError) {
|
} catch (closeError) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"[CapacitorPlatformService] Error closing db during cleanup:",
|
"[CapacitorPlatformService] Error closing db during cleanup:",
|
||||||
@@ -197,9 +200,17 @@ export class CapacitorPlatformService
|
|||||||
} finally {
|
} finally {
|
||||||
this.db = null;
|
this.db = null;
|
||||||
this.initialized = false;
|
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)
|
* Internal initialization method (v3.5 - Minimal refactor)
|
||||||
*
|
*
|
||||||
@@ -626,27 +637,10 @@ export class CapacitorPlatformService
|
|||||||
*
|
*
|
||||||
* DO NOT call on route changes or component unmounts.
|
* DO NOT call on route changes or component unmounts.
|
||||||
*
|
*
|
||||||
* @public
|
* @private Unused - kept for potential future use
|
||||||
*/
|
*/
|
||||||
public async teardown(): Promise<void> {
|
private async teardown(): Promise<void> {
|
||||||
if (await this.isDbOpen(this.db)) {
|
await this._performCleanup();
|
||||||
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;
|
|
||||||
this.connLog("teardown complete");
|
this.connLog("teardown complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,6 +157,22 @@ export default class DeepLinkRedirectView extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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
|
// For mobile, try the deep link URL; for desktop, use the web URL
|
||||||
const redirectUrl = this.isMobile ? this.deepLinkUrl : this.webUrl;
|
const redirectUrl = this.isMobile ? this.deepLinkUrl : this.webUrl;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user