using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using asap.core; using game; using GameCore; using UnityEngine; public class RTServiceBgFgManager : MonoBehaviour { public static bool keepAlive = false; private async void OnApplicationFocus(bool focus) { if (focus) { var rtService = GContext.container.Resolve(); var userService = GContext.container.Resolve(); var mailService = GContext.container.Resolve(); if(rtService != null && userService != null && userService.IsLogin) { if(await NeedReboot()) { RebootAlert(); } else { try { await rtService.Connect(); } catch (Exception ex) { Debug.LogException(ex); } await mailService.FetchMail(); } } } } private void OnApplicationPause(bool pause) { if (pause && !keepAlive) { var rtService = GContext.container.Resolve(); var userService = GContext.container.Resolve(); if(rtService != null && userService != null && userService.IsLogin) { rtService.Disconnect(); } } } private async void RebootAlert() { GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel); var noticeConfirmPopupPanel = go.GetComponent(); string title = LocalizationMgr.GetText("UI_NoticePopupPanel_3"); string info = LocalizationMgr.GetText("UI_NoticePopupPanel_4"); string label = LocalizationMgr.GetText("UI_COMMON_confirm"); noticeConfirmPopupPanel.Init(1, title, info, onClickLeft: RootCtx.ExitGame, onClose: RootCtx.ExitGame, btn_left_text: label); } private async Task NeedReboot() { var userService = GContext.container.Resolve(); var config = GContext.container.Resolve(); if(userService == null || !userService.IsLogin) { return false; } if (config == null) return false; var loginTime = userService.LoginTime; var duration = ZZTimeHelper.UtcNow() - loginTime; if(duration.Days >=1) { var localVer = VersionTool.FromLocal(); var remoteConfig = await ConfigExtension.GetRemoteConfig(); if(remoteConfig == null) return false; var remoteVerStr = remoteConfig[GConstant.K_Ver]; var remoteVer = VersionTool.FromString(remoteVerStr); return remoteVer > localVer || remoteVer.Build != localVer.Build; } return false; } }