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 { if (!AppConfig.HotUpdateEnable || !NATIVE) { return LaunchStateId.PreloadLobby; } context.progress({ state: this.id, title: '检查资源更新' }); const result = await context.kernel.hotUpdate.update( AppConfig.HotUpdateUrl, (progress) => { const percent = progress.percent || progress.percentByFile; const title = progress.stage === 'retrying' ? `资源更新失败,正在重试(${progress.retryCount})` : progress.stage === 'finished' ? '资源更新完成' : progress.stage === 'downloading' ? `正在更新资源 ${progress.downloadedFiles}/${progress.totalFiles}` : '检查资源更新'; context.progress({ state: this.id, title, progress: 0.25 + percent * 0.4, }); }, ); if (result.restartRequired) { context.progress({ state: this.id, title: '更新完成,正在重启', progress: 0.65, }); context.kernel.hotUpdate.restart(); return null; } context.progress({ state: this.id, progress: 0.65 }); return LaunchStateId.PreloadLobby; } }