native.ts

848 B · raw

1// Mobile platform detection helpers used by popup views to gate Capacitor-only paths.2// Kept tiny and runtime-only — never import @capacitor/core at module scope, since3// desktop builds must not pull it.45// eslint-disable-next-line @typescript-eslint/no-explicit-any6type Cap = { isNativePlatform?: () => boolean; Plugins?: Record<string, any> };78function cap(): Cap | null {9  const g = globalThis as unknown as { Capacitor?: Cap };10  return g.Capacitor ?? null;11}1213export function isNativePlatform(): boolean {14  const c = cap();15  if (!c) return false;16  if (typeof c.isNativePlatform === "function") return c.isNativePlatform();17  return false;18}1920// eslint-disable-next-line @typescript-eslint/no-explicit-any21export function nativePlugin<T = any>(name: string): T | null {22  return (cap()?.Plugins?.[name] as T | undefined) ?? null;23}