Browse Source
- Create QRNavigationService to handle platform-specific QR routing - Remove direct Capacitor imports from ContactsView, ProjectsView, HelpView - Replace duplicated QR routing logic with centralized service calls - Update HelpView template to use platform service methods (isCapacitor, capabilities) - Add export data prompt after successfully adding a contact - Add NOTIFY_EXPORT_DATA_PROMPT notification constant - Implement exportContactData() method with platform service integration - Fix TypeScript compatibility for Vue Router route parameters - Maintain consistent QR navigation behavior across all views Eliminates code duplication and improves platform abstraction by using PlatformService instead of direct Capacitor references. Enhances user experience with automatic export prompts for data backup.pull/152/head
5 changed files with 194 additions and 25 deletions
@ -0,0 +1,99 @@ |
|||
import { PlatformServiceFactory } from "./PlatformServiceFactory"; |
|||
import { PlatformService } from "./PlatformService"; |
|||
import { logger } from "@/utils/logger"; |
|||
|
|||
/** |
|||
* QR Navigation Service |
|||
* |
|||
* Handles platform-specific routing logic for QR scanning operations. |
|||
* Removes coupling between views and routing logic by centralizing |
|||
* navigation decisions based on platform capabilities. |
|||
* |
|||
* @author Matthew Raymer |
|||
*/ |
|||
export class QRNavigationService { |
|||
private static instance: QRNavigationService | null = null; |
|||
private platformService: PlatformService; |
|||
|
|||
private constructor() { |
|||
this.platformService = PlatformServiceFactory.getInstance(); |
|||
} |
|||
|
|||
/** |
|||
* Get singleton instance of QRNavigationService |
|||
*/ |
|||
public static getInstance(): QRNavigationService { |
|||
if (!QRNavigationService.instance) { |
|||
QRNavigationService.instance = new QRNavigationService(); |
|||
} |
|||
return QRNavigationService.instance; |
|||
} |
|||
|
|||
/** |
|||
* Get the appropriate QR scanner route based on platform |
|||
* |
|||
* @returns Object with route name and parameters for QR scanning |
|||
*/ |
|||
public getQRScannerRoute(): { |
|||
name: string; |
|||
params?: Record<string, string | number>; |
|||
} { |
|||
const isCapacitor = this.platformService.isCapacitor(); |
|||
|
|||
logger.debug("QR Navigation - Platform detection:", { |
|||
isCapacitor, |
|||
platform: this.platformService.getCapabilities(), |
|||
}); |
|||
|
|||
if (isCapacitor) { |
|||
// Use native scanner on mobile platforms
|
|||
return { name: "contact-qr-scan-full" }; |
|||
} else { |
|||
// Use web scanner on other platforms
|
|||
return { name: "contact-qr" }; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get the appropriate QR display route based on platform |
|||
* |
|||
* @returns Object with route name and parameters for QR display |
|||
*/ |
|||
public getQRDisplayRoute(): { |
|||
name: string; |
|||
params?: Record<string, string | number>; |
|||
} { |
|||
const isCapacitor = this.platformService.isCapacitor(); |
|||
|
|||
logger.debug("QR Navigation - Display route detection:", { |
|||
isCapacitor, |
|||
platform: this.platformService.getCapabilities(), |
|||
}); |
|||
|
|||
if (isCapacitor) { |
|||
// Use dedicated display view on mobile
|
|||
return { name: "contact-qr-scan-show" }; |
|||
} else { |
|||
// Use combined view on web
|
|||
return { name: "contact-qr" }; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Check if native QR scanning is available on current platform |
|||
* |
|||
* @returns true if native scanning is available, false otherwise |
|||
*/ |
|||
public isNativeScanningAvailable(): boolean { |
|||
return this.platformService.isCapacitor(); |
|||
} |
|||
|
|||
/** |
|||
* Get platform capabilities for QR operations |
|||
* |
|||
* @returns Platform capabilities object |
|||
*/ |
|||
public getPlatformCapabilities() { |
|||
return this.platformService.getCapabilities(); |
|||
} |
|||
} |
Loading…
Reference in new issue