You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.2 KiB
141 lines
4.2 KiB
/**
|
|
* @file Capacitor Platform Entry Point
|
|
* @description Initializes the application for Capacitor platform (iOS/Android)
|
|
* @author Matthew Raymer
|
|
* @version 0.4.4
|
|
*
|
|
* Process Flow:
|
|
* 1. Initialization
|
|
* - Logs start of initialization
|
|
* - Logs current platform
|
|
* - Initializes core application via main.common
|
|
*
|
|
* 2. Error Handling Setup
|
|
* - Registers global unhandled promise rejection handler
|
|
* - Routes API errors to error handling system
|
|
*
|
|
* 3. Deep Linking Configuration
|
|
* - Registers URL scheme handler (timesafari://)
|
|
* - Supports 11 parameterized routes:
|
|
* * claim-add-raw
|
|
* * claim-cert
|
|
* * claim
|
|
* * confirm-gift
|
|
* * contact-edit
|
|
* * contact-import
|
|
* * did
|
|
* * invite-one-accept
|
|
* * offer-details
|
|
* * project
|
|
* * userProfile
|
|
*
|
|
* 4. Application Mounting
|
|
* - Mounts Vue application to DOM
|
|
* - Logs completion of mounting process
|
|
*
|
|
* Security Measures:
|
|
* - URL validation before processing
|
|
* - Type-safe error handling
|
|
* - Parameterized route pattern matching
|
|
* - Comprehensive error logging
|
|
*
|
|
* @example Deep Link Format
|
|
* timesafari://<route>/<parameter>
|
|
* timesafari://claim/01JMAAFZRNSRTQ0EBSD70A8E1H
|
|
*/
|
|
|
|
import { initializeApp } from "./main.common";
|
|
import { App } from "./lib/capacitor/app";
|
|
import router from "./router";
|
|
import { handleApiError } from "./services/api";
|
|
import { AxiosError } from "axios";
|
|
|
|
console.log("[Capacitor] Starting initialization");
|
|
console.log("[Capacitor] Platform:", process.env.VITE_PLATFORM);
|
|
|
|
const app = initializeApp();
|
|
|
|
// Initialize API error handling for unhandled promise rejections
|
|
window.addEventListener("unhandledrejection", (event) => {
|
|
if (event.reason?.response) {
|
|
handleApiError(event.reason, event.reason.config?.url || "unknown");
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Handles deep link routing for the application
|
|
* Processes URLs in the format timesafari://<route>/<param>
|
|
* Maps incoming deep links to corresponding router paths with parameters
|
|
*
|
|
* @param {Object} data - Deep link data object
|
|
* @param {string} data.url - The full deep link URL to process
|
|
* @returns {Promise<void>}
|
|
*
|
|
* @example
|
|
* // Handles URLs like:
|
|
* // timesafari://claim/01JMAAFZRNSRTQ0EBSD70A8E1H
|
|
* // timesafari://project/abc123
|
|
*
|
|
* @throws {Error} If URL format is invalid
|
|
*/
|
|
const handleDeepLink = async (data: { url: string }) => {
|
|
try {
|
|
console.log("[Capacitor Deep Link] START Handler");
|
|
console.log("[Capacitor Deep Link] Received URL:", data.url);
|
|
|
|
await router.isReady();
|
|
|
|
const parts = data.url.split("://");
|
|
if (parts.length !== 2) {
|
|
throw new Error("Invalid URL format");
|
|
}
|
|
|
|
const path = parts[1];
|
|
console.log("[Capacitor Deep Link] Parsed path:", path);
|
|
|
|
// Define supported parameterized routes and their regex patterns
|
|
const paramRoutes = {
|
|
"claim-add-raw": /^claim-add-raw\/(.+)$/,
|
|
"claim-cert": /^claim-cert\/(.+)$/,
|
|
claim: /^claim\/(.+)$/,
|
|
"confirm-gift": /^confirm-gift\/(.+)$/,
|
|
"contact-edit": /^contact-edit\/(.+)$/,
|
|
"contact-import": /^contact-import\/(.+)$/,
|
|
did: /^did\/(.+)$/,
|
|
"invite-one-accept": /^invite-one-accept\/(.+)$/,
|
|
"offer-details": /^offer-details\/(.+)$/,
|
|
project: /^project\/(.+)$/,
|
|
"user-profile": /^user-profile\/(.+)$/,
|
|
};
|
|
|
|
// Match route pattern and extract parameter
|
|
for (const [routeName, pattern] of Object.entries(paramRoutes)) {
|
|
const match = path.match(pattern);
|
|
if (match) {
|
|
console.log(
|
|
`[Capacitor Deep Link] Matched route: ${routeName}, param: ${match[1]}`,
|
|
);
|
|
await router.replace({
|
|
name: routeName,
|
|
params: { id: match[1] },
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Default fallback for non-parameterized routes
|
|
await router.replace("/" + path);
|
|
} catch (error) {
|
|
console.error("[Capacitor Deep Link] Error:", error);
|
|
if (error instanceof Error) {
|
|
handleApiError({ message: error.message } as AxiosError, "deep-link");
|
|
}
|
|
}
|
|
};
|
|
|
|
// Register deep link handler with Capacitor
|
|
App.addListener("appUrlOpen", handleDeepLink);
|
|
|
|
console.log("[Capacitor] Mounting app");
|
|
app.mount("#app");
|
|
console.log("[Capacitor] App mounted");
|
|
|