#pragma warning disable IDE1006 // Naming Styles protected override async void OnActivated(IActivatedEventArgs args) #pragma warning restore IDE1006 // Naming Styles { bool loadAppData = AppData.Current == null; bool loadInsiderInfo = InsiderInfo.Current == null; Task loadAppDataTask = null; Task loadInsiderInfoTask = null; if (loadAppData) { loadAppDataTask = AppData.LoadAsync(); } if (loadInsiderInfo) { loadInsiderInfoTask = InsiderInfo.LoadAsync(); } systemNavigationManager = SystemNavigationManager.GetForCurrentView(); rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; rootFrame.Navigated += (sender, e) => { systemNavigationManager.AppViewBackButtonVisibility = rootFrame.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }; systemNavigationManager.BackRequested += (sender, e) => { if (rootFrame.CanGoBack) { e.Handled = true; rootFrame.GoBack(); } }; Window.Current.Content = rootFrame; await BarsHelper.Current.SetTitleBarColorModeAsync(BarsHelperColorMode.Accent); await BarsHelper.Current.SetStatusBarColorModeAsync(BarsHelperColorMode.Accent); await BarsHelper.Current.InitializeForCurrentViewAsync(); if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView")) { ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(330, 460)); } Window.Current.Activated += (sender, e) => { if (e.WindowActivationState != CoreWindowActivationState.Deactivated) { CurrentTheme = RequestedTheme == ApplicationTheme.Light ? ElementTheme.Light : ElementTheme.Dark; } }; } LaunchActivatedEventArgs launchArgs = args as LaunchActivatedEventArgs; if (loadAppData) { await loadAppDataTask; } if (loadInsiderInfo) { await loadInsiderInfoTask; } if (launchArgs?.PrelaunchActivated != true) { if (rootFrame.Content == null) { rootFrame.Navigate(typeof(MainPage), launchArgs?.Arguments); } Window.Current.Activate(); } }
public static async Task LoadAsync() { bool initialLoad = Current == null; ShowLoadingError = false; if (initialLoad) { Current = new InsiderInfo(); } Current.IsLoading = true; if (NetworkInformation.GetInternetConnectionProfile()?.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess) { using (HttpClient httpClient = new HttpClient()) { string insideTenApiJson = await httpClient.GetStringAsync("https://raw.githubusercontent.com/MehediH/InsideTen/gh-pages/api.json"); Debug.WriteLine(DebugHelper.GetOperationInfoString("Inside Ten api.json", "downloading", true)); if (!string.IsNullOrWhiteSpace(insideTenApiJson)) { bool assignFromInsideTenApiResult = Current.AssignFromInsideTenApi(await Task.Run(() => JsonConvert.DeserializeObject <InsideTenApi>(insideTenApiJson))); if (assignFromInsideTenApiResult || AppData.Current.InsiderInfoLastUpdate == null) { AppData.Current.InsiderInfoLastUpdate = DateTime.Now; if (assignFromInsideTenApiResult) { Debug.WriteLine($"{nameof(InsiderInfo)}.{nameof(Current)} updated at {AppData.Current.InsiderInfoLastUpdate:HH:mm:ss}"); } } Current.IsSuccessfullyLoaded = true; try { await FileIO.WriteTextAsync(await folder.CreateFileAsync(FILE_NAME, CreationCollisionOption.OpenIfExists), insideTenApiJson); } catch { } } } } else if (initialLoad) { try { StorageFile file = await folder.GetFileAsync(FILE_NAME); string json = await FileIO.ReadTextAsync(file); if (!string.IsNullOrWhiteSpace(json)) { Current.AssignFromInsideTenApi(await Task.Run(() => JsonConvert.DeserializeObject <InsideTenApi>(json))); Current.IsSuccessfullyLoaded = true; } else { ShowLoadingError = true; } } catch { ShowLoadingError = true; } } Current.IsLoading = false; }