Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const codePushStatusDidChange = (syncStatus: number) => {
switch (syncStatus) {
case CodePush.SyncStatus.UP_TO_DATE: // 已更新 0
console.info(`[CodePush]${syncStatus}: 已更新`)
break
case CodePush.SyncStatus.INSTALLING_UPDATE: // 下载更新 1
console.info(`[CodePush]${syncStatus}: 下载更新`)
break
case CodePush.SyncStatus.UPDATE_IGNORED: // 忽略更新 2
console.info(`[CodePush]${syncStatus}: 忽略更新`)
break
case CodePush.SyncStatus.UNKNOWN_ERROR: // 未知错误 3
console.info(`[CodePush]${syncStatus}: 未知错误`)
break
case CodePush.SyncStatus.SYNC_IN_PROGRESS: // 正在同步 4
console.info(`[CodePush]${syncStatus}: 正在同步`)
break
case CodePush.SyncStatus.CHECKING_FOR_UPDATE: // 检查更新 5
console.info(`[CodePush]${syncStatus}: 检查更新`)
break
case CodePush.SyncStatus.AWAITING_USER_ACTION: // 等待用户操作 6
console.info(`[CodePush]${syncStatus}: 等待用户操作`)
break
case CodePush.SyncStatus.DOWNLOADING_PACKAGE: // 正在下载 7
console.info(`[CodePush]${syncStatus}: 正在下载`)
(status) => {
switch (status) {
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
// this.setState({showDownloadingModal: true});
// this.refs.modal.open();
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
// this.setState({showInstalling: true});
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
// this.refs.modal.close();
// this.setState({showDownloadingModal: false});
break;
}
},
({ receivedBytes, totalBytes, }) => {
codePushStatusDidChange(status) {
// alert(111)
switch (status) {
case codePush.SyncStatus.DOWNLOADING_PACKAGE:
// Show "downloading" modal
Toast.show('正在下载更新...')
break
case codePush.SyncStatus.INSTALLING_UPDATE:
// Hide "downloading" modal
Toast.show('正在升级...')
break
case codePush.SyncStatus.UPDATE_INSTALLED:
Toast.show('更新成功')
break
}
}
backHandle = () => {
codePushStatusDidChange = (syncStatus) => {
switch(syncStatus) {
case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
Toast.show('正在检查更新');
break;
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
Toast.show('用户确认更新');
break;
case CodePush.SyncStatus.AWAITING_USER_ACTION:
Toast.show('等待用户确认');
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
// Toast.show('正在更新');
break;
case CodePush.SyncStatus.UP_TO_DATE:
Toast.show('已经是最新版本');
break;
case CodePush.SyncStatus.UPDATE_IGNORED:
Toast.show('用户取消更新');
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
Toast.show('安装更新成功,重启应用以完成更新');
setTimeout(function () {
BackAndroid.exitApp();
},2000);
break;
case CodePush.SyncStatus.UNKNOWN_ERROR:
Toast.show('未知错误');
codePushStatusDidChange(syncStatus) {
console.log("-codePushStatusDidChange-");
console.log(syncStatus);
let syncMessage = this.state.syncMessage;
switch (syncStatus) {
case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
this.syncMessage = "Checking for update";
syncMessage = "正在检查更新...";
break;
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
this.syncMessage = "Downloading package";
syncMessage = "下载更新包中...";
break;
case CodePush.SyncStatus.AWAITING_USER_ACTION:
this.syncMessage = "Awaiting user action";
syncMessage = "等待选择更新";
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
this.syncMessage = "Installing update";
syncMessage = "安装更新中...";
break;
case CodePush.SyncStatus.UP_TO_DATE:
codePushStatusDidChange(syncStatus) {
switch(syncStatus) {
case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
this.setState({ syncMessage: I18n.t('splash.update.checking') });
break;
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
this.setState({ syncMessage: I18n.t('splash.update.downloading') });
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
this.setState({ syncMessage: I18n.t('splash.update.installing') });
break;
case CodePush.SyncStatus.UP_TO_DATE:
this.setState({ syncMessage: I18n.t('splash.update.up_to_date'), progress: false });
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
this.setState({ syncMessage: I18n.t('splash.update.installed'), progress: false });
break;
case CodePush.SyncStatus.SYNC_IN_PROGRESS:
this.setState({ syncMessage: I18n.t('splash.update.sycn_in_progress'), progress: false });
break;
case CodePush.SyncStatus.UNKNOWN_ERROR:
this.setState({ syncMessage: I18n.t('splash.update.unknown_error'), progress: false });
break;
default:
this.setState({ progress: false });
break;
}
}
codePushStatusDidChange(syncStatus) {
switch (syncStatus) {
case CodePushLib.SyncStatus.CHECKING_FOR_UPDATE:
this.setState({ syncMessage: "Checking for update." });
break;
case CodePushLib.SyncStatus.DOWNLOADING_PACKAGE:
this.setState({ syncMessage: "Downloading package." });
break;
case CodePushLib.SyncStatus.AWAITING_USER_ACTION:
this.setState({ syncMessage: "Awaiting user action." });
break;
case CodePushLib.SyncStatus.INSTALLING_UPDATE:
this.setState({ syncMessage: "Installing update." });
break;
case CodePushLib.SyncStatus.UP_TO_DATE:
this.setState({ syncMessage: "App up to date.", progress: null });
break;
case CodePushLib.SyncStatus.UPDATE_IGNORED:
this.setState({ syncMessage: "Update cancelled by user.", progress: null });
break;
case CodePushLib.SyncStatus.UPDATE_INSTALLED:
this.setState({ syncMessage: "Update installed and will be applied on restart.", progress: null });
break;
case CodePushLib.SyncStatus.UNKNOWN_ERROR:
this.setState({ syncMessage: "An unknown error occurred.", progress: null });
break;
}
}
async onCodePushPress() {
this.isUpdating = true;
const config = codePushConfig();
config.installMode = CodePush.InstallMode.IMMEDIATE;
const update = await CodePush.sync(config, undefined, this.onDownloadProgress, this.onBinaryVersionMismatch);
this.isUpdating = false;
this.progress = null;
switch (update) {
case CodePush.SyncStatus.UP_TO_DATE:
Alert.alert(locales[Store.settings.language].NO_UPDATE_AVAILABLE);
break;
case CodePush.SyncStatus.UNKNOWN_ERROR:
Alert.alert('Unknown error');
break;
}
}
CodePush.sync(options, status => {
switch (status) {
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
this.refs.nav.push({
component: Loading,
title: ' ',
navigationBarHidden: true,
leftButtonTitle: '',
onLeftButtonPress: () => {}
})
break
case CodePush.SyncStatus.INSTALLING_UPDATE:
break
case CodePush.SyncStatus.AWAITING_USER_ACTION:
break
}
})
}
(status) => {
switch (status) {
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
this.setState({showDownloadingModal: true});
this.refs.modal.open();
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
this.setState({showInstalling: true});
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
this.refs.modal.close();
this.setState({showDownloadingModal: false});
break;
}
},
({ receivedBytes, totalBytes, }) => {