refactor-initialize #221

Open
anomalist wants to merge 13 commits from refactor-initialize into master
2 changed files with 34 additions and 24 deletions
Showing only changes of commit cb8d8bed4c - Show all commits

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;