Esempio n. 1
0
        private async void LoginAction()
        {
            try
            {
                //immediately stop the auto-checker to avoid double checks
                tmrLoginDetection.Stop();

                //change UI accordingly
                lblInstructions.Text = TalkingToPlex;
                btnOK.Enabled        = false; //so the user can't click it twice

                //try and grab the new token
                var newPin = await Task.Run(() => PlexAuthHandler.FromPinEndpoint(PlexRequestPin));

                //it's only successful if a token was actually provided
                if (newPin != null)
                {
                    Success = !string.IsNullOrEmpty(newPin.AuthToken);
                }

                //apply the result
                Result = newPin;

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                UIMessages.Error($"An error occurred whilst logging into Plex.tv:\n\n{ex}");
            }
        }
Esempio n. 2
0
        private async void TmrLoginDetection_Tick(object sender, EventArgs e)
        {
            try
            {
                //Try and grab the new token.
                //~Run this on a background thread (avoids UI lockup)
                var newPin = await Task.Run(() => PlexAuthHandler.FromPinEndpoint(PlexRequestPin));

                //it's only successful if a token was actually provided
                if (newPin != null)
                {
                    if (!string.IsNullOrEmpty(newPin.AuthToken))
                    {
                        //disable the UI button to stop the user from
                        //attempting to start two checks
                        btnOK.Enabled = false;

                        tmrLoginDetection.Stop();

                        //specify this to avoid confusion with the UI handler on the other end
                        Success = true;

                        //apply the result
                        Result       = newPin;
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
            }
            catch
            {
                //if any errors occurs, disable the auto-checker
                //and revert to manual user input (via the 'OK' button)
                tmrLoginDetection.Stop();
            }
        }
Esempio n. 3
0
 public static string ToJson(this PlexAuth self) => JsonConvert.SerializeObject(self, Converter.Settings);