-
Notifications
You must be signed in to change notification settings - Fork 1
/
CodePush.tsx
52 lines (48 loc) · 1.55 KB
/
CodePush.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { useEffect } from 'react';
import codePush from 'react-native-code-push';
import { CrashlyticsService } from '~/services';
import { useAlerts } from '~/utils';
const CodePush: React.FC = () => {
const { showInfo } = useAlerts();
const checkStatus = (status: any): void => {
try {
switch (status) {
case codePush.SyncStatus.DOWNLOADING_PACKAGE: // 7
case codePush.SyncStatus.INSTALLING_UPDATE: // 8
showInfo('Downloading update');
break;
case codePush.SyncStatus.CHECKING_FOR_UPDATE: // 5
case codePush.SyncStatus.UPDATE_IGNORED: // 2
case codePush.SyncStatus.UNKNOWN_ERROR: // 3
default:
break;
}
} catch (error) {
console.log('Error: ' + error);
CrashlyticsService.recordError(error as Error);
}
};
const syncCodeFromCodePush = () => {
try {
codePush.sync(
{
installMode: codePush.InstallMode.IMMEDIATE,
}, // options
(status) => checkStatus(status), // syncStatusChangedCallback
({ receivedBytes, totalBytes }) => {
const percent = `${(receivedBytes / totalBytes) * 100}%`;
console.log('LOG: : percent', percent);
}, // downloadProgressCallback
() => console.warn('Outdated app.'), // HandleBinaryVersionMismatchCallback
);
} catch (error) {
console.log('Error: ' + error);
CrashlyticsService.recordError(error as Error);
}
};
useEffect(() => {
syncCodeFromCodePush();
}, []);
return <></>;
};
export default CodePush;