forked from jsnbuchanan/crowd-funder-for-time-pwa
- Add electron platform section to capacitor.config.json - Configure deep linking with timesafari:// scheme - Set up build options for macOS, Windows, and Linux - Configure output directory and file inclusion - Add platform-specific build targets (DMG, NSIS, AppImage) - Support both x64 and arm64 architectures for macOS - Set appropriate app categories for each platform This enables building TimeSafari as a native desktop application using Capacitor's Electron platform while maintaining existing mobile and web functionality.
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { PlatformService } from "./PlatformService";
|
|
import { WebPlatformService } from "./platforms/WebPlatformService";
|
|
import { CapacitorPlatformService } from "./platforms/CapacitorPlatformService";
|
|
|
|
/**
|
|
* Factory class for creating platform-specific service implementations.
|
|
* Implements the Singleton pattern to ensure only one instance of PlatformService exists.
|
|
*
|
|
* The factory determines which platform implementation to use based on the VITE_PLATFORM
|
|
* environment variable. Supported platforms are:
|
|
* - capacitor: Mobile platform using Capacitor
|
|
* - web: Default web platform (fallback)
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const platformService = PlatformServiceFactory.getInstance();
|
|
* await platformService.takePicture();
|
|
* ```
|
|
*/
|
|
export class PlatformServiceFactory {
|
|
private static instance: PlatformService | null = null;
|
|
|
|
/**
|
|
* Gets or creates the singleton instance of PlatformService.
|
|
* Creates the appropriate platform-specific implementation based on environment.
|
|
*
|
|
* @returns {PlatformService} The singleton instance of PlatformService
|
|
*/
|
|
public static getInstance(): PlatformService {
|
|
if (PlatformServiceFactory.instance) {
|
|
return PlatformServiceFactory.instance;
|
|
}
|
|
|
|
const platform = process.env.VITE_PLATFORM || "web";
|
|
|
|
switch (platform) {
|
|
case "capacitor":
|
|
PlatformServiceFactory.instance = new CapacitorPlatformService();
|
|
break;
|
|
case "web":
|
|
default:
|
|
PlatformServiceFactory.instance = new WebPlatformService();
|
|
break;
|
|
}
|
|
|
|
return PlatformServiceFactory.instance;
|
|
}
|
|
}
|