| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { LaunchContext, LaunchState, LaunchStateId } from './LaunchState';
- import AppConfig from '../../../app/AppConfig';
- import { NATIVE } from 'cc/env';
- export class HotUpdateState implements LaunchState {
- readonly id = LaunchStateId.HotUpdate;
- async enter(context: LaunchContext): Promise<LaunchStateId | null> {
- if (!AppConfig.HotUpdateEnable || !NATIVE) {
- return LaunchStateId.PreloadLobby;
- }
- const i18n = context.kernel.i18n;
- context.progress({ state: this.id, title: i18n.t('launch.check_res_version') });
- const result = await context.kernel.hotUpdate.update(
- AppConfig.HotUpdateUrl,
- (progress) => {
- const percent = progress.percent || progress.percentByFile;
- const title = progress.stage === 'retrying'
- ? i18n.t("launch.update_retry", progress.retryCount)
- : progress.stage === 'finished'
- ? i18n.t('launch.update_finished')
- : progress.stage === 'downloading'
- ? i18n.t('launch.updating_res', progress.downloadedFiles, progress.totalFiles)
- : i18n.t('launch.check_res_version');
- context.progress({
- state: this.id,
- title,
- progress: percent * 0.4,
- });
- },
- );
- if (result.restartRequired) {
- context.progress({
- state: this.id,
- title: i18n.t('launch.update_finished'),
- progress: 0.65,
- });
- context.kernel.hotUpdate.restart();
- return null;
- }
- context.progress({ state: this.id, progress: 0.65 });
- return LaunchStateId.PreloadLobby;
- }
- }
|