({
client,
children,
}: {
client: Pushy | Cresc;
children: ReactNode;
})
| 30 | import { assertWeb, log } from './utils'; |
| 31 | |
| 32 | export const UpdateProvider = ({ |
| 33 | client, |
| 34 | children, |
| 35 | }: { |
| 36 | client: Pushy | Cresc; |
| 37 | children: ReactNode; |
| 38 | }) => { |
| 39 | client = useRef(client).current; |
| 40 | const { options } = client; |
| 41 | |
| 42 | const stateListener = useRef<NativeEventSubscription>(undefined); |
| 43 | const [updateInfo, setUpdateInfo] = useState<CheckResult>(); |
| 44 | const updateInfoRef = useRef(updateInfo); |
| 45 | const [progress, setProgress] = useState<ProgressData>(); |
| 46 | const [lastError, setLastError] = useState<Error>(); |
| 47 | const lastChecking = useRef(0); |
| 48 | |
| 49 | const throwErrorIfEnabled = useCallback( |
| 50 | (e: Error) => { |
| 51 | if (options.throwError) { |
| 52 | throw e; |
| 53 | } |
| 54 | }, |
| 55 | [options.throwError], |
| 56 | ); |
| 57 | |
| 58 | const dismissError = useCallback(() => { |
| 59 | setLastError(undefined); |
| 60 | }, []); |
| 61 | |
| 62 | const alertUpdate = useCallback( |
| 63 | (...args: Parameters<typeof Alert.alert>) => { |
| 64 | if ( |
| 65 | options.updateStrategy === 'alwaysAlert' || |
| 66 | options.updateStrategy === 'alertUpdateAndIgnoreError' |
| 67 | ) { |
| 68 | Alert.alert(...args); |
| 69 | } |
| 70 | }, |
| 71 | [options.updateStrategy], |
| 72 | ); |
| 73 | |
| 74 | const alertError = useCallback( |
| 75 | (...args: Parameters<typeof Alert.alert>) => { |
| 76 | if (options.updateStrategy === 'alwaysAlert') { |
| 77 | Alert.alert(...args); |
| 78 | } |
| 79 | }, |
| 80 | [options.updateStrategy], |
| 81 | ); |
| 82 | |
| 83 | const switchVersion = useCallback( |
| 84 | async (info: CheckResult | undefined = updateInfoRef.current) => { |
| 85 | if (info && info.hash) { |
| 86 | return client.switchVersion(info.hash); |
| 87 | } |
| 88 | }, |
| 89 | [client], |
nothing calls this directly
no test coverage detected