-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.android.ts
50 lines (45 loc) · 1.58 KB
/
index.android.ts
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
import Onyx from 'react-native-onyx';
import semver from 'semver';
import * as AppUpdate from '@libs/actions/AppUpdate';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import pkg from '../../../../package.json';
import type {IsBetaBuild} from './types';
type GithubReleaseJSON = {
// eslint-disable-next-line @typescript-eslint/naming-convention
tag_name: string | semver.SemVer;
};
let isLastSavedBeta = false;
Onyx.connect({
key: ONYXKEYS.IS_BETA,
callback: (value) => {
isLastSavedBeta = !!value;
},
});
/**
* Check the GitHub releases to see if the current build is a beta build or production build
*/
function isBetaBuild(): IsBetaBuild {
return new Promise((resolve) => {
fetch(CONST.GITHUB_RELEASE_URL)
.then((res) => res.json())
.then((json: GithubReleaseJSON) => {
const productionVersion = json.tag_name;
if (!productionVersion) {
AppUpdate.setIsAppInBeta(false);
resolve(false);
}
// If the current version we are running is greater than the production version, we are on a beta version of Android
const isBeta = semver.gt(pkg.version, productionVersion);
AppUpdate.setIsAppInBeta(isBeta);
resolve(isBeta);
})
.catch(() => {
// Use isLastSavedBeta in case we fail to fetch the new one, e.g. when we are offline
resolve(isLastSavedBeta);
});
});
}
export default {
isBetaBuild,
};