Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,7 @@ export default {

// Whether we should show the compose input or not
SHOULD_SHOW_COMPOSE_INPUT: 'shouldShowComposeInput',

// Is app in beta version
IS_BETA: 'isBeta',
};
14 changes: 13 additions & 1 deletion src/libs/Environment/betaChecker/index.android.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import semver from 'semver';
import Onyx from 'react-native-onyx';
import CONST from '../../../CONST';
import pkg from '../../../../package.json';
import ONYXKEYS from '../../../ONYXKEYS';
import * as AppUpdate from '../../actions/AppUpdate';

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
Expand All @@ -14,15 +23,18 @@ function isBetaBuild() {
.then((json) => {
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(() => {
resolve(false);
// Use isLastSavedBeta in case we fail to fetch the new one, e.g. when we are offline
resolve(isLastSavedBeta);
});
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/libs/actions/AppUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ function triggerUpdateAvailable() {
Onyx.set(ONYXKEYS.UPDATE_AVAILABLE, true);
}

/**
* @param {Boolean} isBeta
*/
function setIsAppInBeta(isBeta) {
Onyx.set(ONYXKEYS.IS_BETA, isBeta);
}

export {
// eslint-disable-next-line import/prefer-default-export
triggerUpdateAvailable,
setIsAppInBeta,
};