timesafari
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.
 
 
 

100 lines
2.9 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";
import { DeepLinkHandler } from "./services/deepLinks";
import { logConsoleAndDb } from "./db";
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");
}
});
const deepLinkHandler = new DeepLinkHandler(router);
/**
* 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 {
await router.isReady();
await deepLinkHandler.handleDeepLink(data.url);
} catch (error) {
logConsoleAndDb("[DeepLink] Error handling deep link: " + error, true);
handleApiError(error, "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");