import { createContext, useContext } from 'react'; import { CheckResult, ProgressData } from './type'; import { Pushy, Cresc } from './client'; const noop = () => {}; const asyncNoop = () => Promise.resolve(); export const defaultContext = { checkUpdate: asyncNoop, switchVersion: asyncNoop, switchVersionLater: asyncNoop, markSuccess: noop, dismissError: noop, downloadUpdate: asyncNoop, downloadAndInstallApk: asyncNoop, getCurrentVersionInfo: () => Promise.resolve({}), parseTestQrCode: () => false, currentHash: '', packageVersion: '', }; export const UpdateContext = createContext<{ checkUpdate: () => Promise; switchVersion: () => Promise; switchVersionLater: () => Promise; markSuccess: () => void; dismissError: () => void; downloadUpdate: () => Promise; downloadAndInstallApk: (url: string) => Promise; getCurrentVersionInfo: () => Promise<{ name?: string; description?: string; metaInfo?: string; }>; parseTestQrCode: (code: string) => boolean; currentHash: string; packageVersion: string; client?: Pushy | Cresc; progress?: ProgressData; updateInfo?: CheckResult; lastError?: Error; }>(defaultContext); export const usePushy = () => useContext(UpdateContext); export const useCresc = () => useContext(UpdateContext);