Пример #1
0
 private void AppFrame_Navigating(object sender, NavigatingCancelEventArgs e)
 {
     HelperMethods.EnableBackButton();
     HelperMethods.ShowSplitView();
     if (AppConstants.activeUser == null)
     {
         userTextBlock.Text = "Login";
     }
     else
     {
         userTextBlock.Text = AppConstants.activeUser.displayName;
     }
 }
Пример #2
0
        private async void page_Loaded(object sender, RoutedEventArgs e)
        {
            HelperMethods.HideSplitView();
            try
            {
                AppConstants.NetworkConnectionType connection = await HelperMethods.DetermineInternetConnection();
            }
            catch (Exception)
            {
                loadingText.Text = "no internet connection found";
                return;
            }
            ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
            StorageFolder            roamingFolder   = ApplicationData.Current.RoamingFolder;
            StorageFolder            localFolder     = ApplicationData.Current.LocalFolder;

            await DoEmotesStuff(localFolder);

            loadingText.Text = "loading settings";
            if (!roamingSettings.Values.ContainsKey("wifiStreamQuality"))
            {
                roamingSettings.Values["wifiStreamQuality"] = "Medium";
            }
            if (!roamingSettings.Values.ContainsKey("cellStreamQuality"))
            {
                roamingSettings.Values["cellStreamQuality"] = "Mobile";
            }
            AppConstants.WifiStreamQuality = HelperMethods.GetStreamQuality((string)roamingSettings.Values["wifiStreamQuality"]);
            AppConstants.CellStreamQuality = HelperMethods.GetStreamQuality((string)roamingSettings.Values["cellStreamQuality"]);
            StorageFile usersFile = await roamingFolder.CreateFileAsync("Users.json", CreationCollisionOption.OpenIfExists);

            string usersData = await FileIO.ReadTextAsync(usersFile);

            if (string.IsNullOrEmpty(usersData))
            {
                roamingSettings.Values["activeUser"] = string.Empty;
                AppConstants.activeUser = null;
                HelperMethods.ShowSplitView();
                Frame.Navigate(typeof(HomePage));
            }
            else
            {
                JArray usersA = JArray.Parse(usersData);
                Dictionary <string, User> tmpUsers = new Dictionary <string, User>();
                foreach (JObject userO in usersA)
                {
                    User   tmpUser     = null;
                    string name        = (string)userO["name"];
                    string accessToken = (string)userO["access_token"];
                    loadingText.Text = "loading " + name;
                    try
                    {
                        tmpUser = await AppConstants.Twixel.RetrieveUserWithAccessToken(accessToken);
                    }
                    catch (TwixelException ex)
                    {
                        if (ex.Message == $"{accessToken} is not a valid access token")
                        {
                            await HelperMethods.ShowMessageDialog($"The access token for {name} isn't currently valid.\nYou can fix this later in the settings menu.");
                        }
                        else
                        {
                            await HelperMethods.ShowMessageDialog($"Something went wrong when trying to talk to Twitch. You should probably try again later. Here's the error:\n{ex.Message}");
                        }
                    }
                    if (tmpUser == null)
                    {
                        AppConstants.users.Add(name, string.Empty);
                    }
                    else
                    {
                        tmpUsers.Add(name, tmpUser);
                        AppConstants.users.Add(name, accessToken);
                    }
                }
                if (!roamingSettings.Values.ContainsKey("activeUser"))
                {
                    roamingSettings.Values["activeUser"] = string.Empty;
                }
                string activeUser = (string)roamingSettings.Values["activeUser"];
                if (!string.IsNullOrEmpty(activeUser))
                {
                    if (AppConstants.users.ContainsKey(activeUser))
                    {
                        if (!string.IsNullOrEmpty(AppConstants.users[activeUser]))
                        {
                            AppConstants.activeUser = tmpUsers[activeUser];
                            Frame.Navigate(typeof(HomePage));
                        }
                        else
                        {
                            // need to choose a new active user
                            roamingSettings.Values["activeUser"] = string.Empty;
                            Frame.Navigate(typeof(HomePage));
                        }
                    }
                    else
                    {
                        // need to choose a new active user
                        roamingSettings.Values["activeUser"] = string.Empty;
                        Frame.Navigate(typeof(HomePage));
                    }
                }
                else
                {
                    // need to choose a new active user
                    roamingSettings.Values["activeUser"] = string.Empty;
                    Frame.Navigate(typeof(HomePage));
                }
            }
        }