code-craft-studio
Version:
A comprehensive QR code and barcode scanning/generation library for React. Works with or without Capacitor. Supports 22+ QR data types and 14+ barcode formats (EAN, UPC, Code 128, etc.), with customizable designs, analytics, and React components. Provider
66 lines • 1.94 kB
JavaScript
class PlatformDetectorImpl {
constructor() {
this._isCapacitor = null;
}
isCapacitor() {
if (this._isCapacitor === null) {
this._isCapacitor = this.detectCapacitor();
}
return this._isCapacitor;
}
isWeb() {
return typeof window !== 'undefined' && typeof document !== 'undefined';
}
isNative() {
return this.isCapacitor() && (this.isIOS() || this.isAndroid());
}
getPlatformName() {
if (this.isCapacitor()) {
if (this.isIOS())
return 'ios';
if (this.isAndroid())
return 'android';
return 'capacitor-web';
}
return 'web';
}
detectCapacitor() {
if (typeof window === 'undefined')
return false;
// Check for Capacitor global
if ('Capacitor' in window && window.Capacitor) {
return true;
}
// Check for @capacitor/core module dynamically
try {
// Use dynamic import check
if (typeof window !== 'undefined' && window.__capacitor_loaded__) {
return true;
}
}
catch (_a) {
// Ignore errors
}
return false;
}
isIOS() {
if (!this.isCapacitor())
return false;
// Check if we have Capacitor global
if (typeof window !== 'undefined' && window.Capacitor) {
return window.Capacitor.getPlatform() === 'ios';
}
return false;
}
isAndroid() {
if (!this.isCapacitor())
return false;
// Check if we have Capacitor global
if (typeof window !== 'undefined' && window.Capacitor) {
return window.Capacitor.getPlatform() === 'android';
}
return false;
}
}
export const platformDetector = new PlatformDetectorImpl();
//# sourceMappingURL=detector.js.map