import ActivityScheduleService from "./module/Config/ActivityScheduleService"; import HomeActivityEntryLayout from "./HomeActivityEntryLayout"; const { ccclass } = cc._decorator; /** Refresh on entering/returning home; scheduled ticks only check local time boundaries. */ @ccclass export default class HomeActivitySchedule extends cc.Component { private visibility = 0; lateUpdate(): void { const load = this.node.getChildByName("Load"); HomeActivityEntryLayout.refresh(load && load.getChildByName("Top")); } onEnable(): void { cc.game.on(cc.game.EVENT_SHOW, this.onShow, this); cc.game.on(cc.game.EVENT_HIDE, this.onHide, this); this.show(true); } private tick = (): void => { ActivityScheduleService.tick(); }; private onShow = (): void => { this.show(false); }; private show(entering: boolean): void { const visibility = ++this.visibility; const query = entering ? ActivityScheduleService.enterHome() : ActivityScheduleService.onForeground(); this.unschedule(this.tick); this.schedule(this.tick, 1); this.tick(); void query.then(ok => { if (ok && visibility === this.visibility) return ActivityScheduleService.checkCloudRiseOpening(() => visibility === this.visibility, false); }); } private onHide = (): void => { this.visibility++; this.unschedule(this.tick); ActivityScheduleService.onBackground(); }; onDisable(): void { this.onHide(); cc.game.off(cc.game.EVENT_SHOW, this.onShow, this); cc.game.off(cc.game.EVENT_HIDE, this.onHide, this); } }