1.1 --- a/Server/FormMain.cs Sun Aug 21 19:31:08 2016 +0200
1.2 +++ b/Server/FormMain.cs Mon Aug 22 13:20:54 2016 +0200
1.3 @@ -1201,7 +1201,7 @@
1.4 checkBoxAutoStart.Checked = iStartupManager.Startup;
1.5
1.6 //Harmony settings
1.7 - iTextBoxHarmonyHubAddress.Text = Properties.Settings.Default.HarmonyHubAddress;
1.8 + iButtonHarmonyConnect.Enabled = Properties.Settings.Default.HarmonyEnabled;
1.9
1.10 //CEC settings
1.11 comboBoxHdmiPort.SelectedIndex = Properties.Settings.Default.CecHdmiPort - 1;
1.12 @@ -2525,7 +2525,7 @@
1.13 base.WndProc(ref aMessage);
1.14 }
1.15
1.16 - private void checkBoxCecEnabled_CheckedChanged(object sender, EventArgs e)
1.17 + private void iCheckBoxCecEnabled_CheckedChanged(object sender, EventArgs e)
1.18 {
1.19 //
1.20 ResetCec();
1.21 @@ -2566,20 +2566,19 @@
1.22 /// <summary>
1.23 ///
1.24 /// </summary>
1.25 - private async void ResetHarmony()
1.26 + private async void ResetHarmony(bool aForceAuth=false)
1.27 {
1.28 // ConnectAsync already if we have an existing session cookie
1.29 - if (Properties.Settings.Default.HarmonyEnabled && File.Exists("SessionToken"))
1.30 + if (Properties.Settings.Default.HarmonyEnabled)
1.31 {
1.32 -
1.33 - iButtonHarmonyConnect.Enabled = false;
1.34 try
1.35 {
1.36 - await ConnectHarmonyAsync();
1.37 + await ConnectHarmonyAsync(aForceAuth);
1.38 }
1.39 - finally
1.40 + catch (Exception ex)
1.41 {
1.42 - iButtonHarmonyConnect.Enabled = true;
1.43 + Console.WriteLine("Exception thrown by ConnectHarmonyAsync");
1.44 + Console.WriteLine(ex.ToString());
1.45 }
1.46 }
1.47 }
1.48 @@ -2587,6 +2586,28 @@
1.49 /// <summary>
1.50 ///
1.51 /// </summary>
1.52 + /// <param name="sender"></param>
1.53 + /// <param name="e"></param>
1.54 + private void iButtonHarmonyConnect_Click(object sender, EventArgs e)
1.55 + {
1.56 + // User is explicitaly trying to connect
1.57 + //Reset Harmony Hub connection forcing authentication
1.58 + ResetHarmony(true);
1.59 + }
1.60 +
1.61 + /// <summary>
1.62 + ///
1.63 + /// </summary>
1.64 + /// <param name="sender"></param>
1.65 + /// <param name="e"></param>
1.66 + private void iCheckBoxHarmonyEnabled_CheckedChanged(object sender, EventArgs e)
1.67 + {
1.68 + iButtonHarmonyConnect.Enabled = iCheckBoxHarmonyEnabled.Checked;
1.69 + }
1.70 +
1.71 + /// <summary>
1.72 + ///
1.73 + /// </summary>
1.74 private void SetupCecLogLevel()
1.75 {
1.76 //Setup log level
1.77 @@ -2975,31 +2996,8 @@
1.78 /// <summary>
1.79 ///
1.80 /// </summary>
1.81 - /// <param name="sender"></param>
1.82 - /// <param name="e"></param>
1.83 - private async void iButtonHarmonyConnect_Click(object sender, EventArgs e)
1.84 - {
1.85 - //Save hub address
1.86 - Properties.Settings.Default.HarmonyHubAddress = iTextBoxHarmonyHubAddress.Text;
1.87 - Properties.Settings.Default.Save();
1.88 -
1.89 - iButtonHarmonyConnect.Enabled = false;
1.90 - try
1.91 - {
1.92 - await ConnectHarmonyAsync();
1.93 - }
1.94 - catch (Exception)
1.95 - {
1.96 - iButtonHarmonyConnect.Enabled = true;
1.97 - }
1.98 -
1.99 - }
1.100 -
1.101 - /// <summary>
1.102 - ///
1.103 - /// </summary>
1.104 /// <returns></returns>
1.105 - private async Task ConnectHarmonyAsync()
1.106 + private async Task ConnectHarmonyAsync(bool aForceAuth=false)
1.107 {
1.108 if (Program.HarmonyClient != null)
1.109 {
1.110 @@ -3013,7 +3011,7 @@
1.111 Console.WriteLine("Harmony: Connecting... ");
1.112 Program.HarmonyClient = new HarmonyHub.Client(iTextBoxHarmonyHubAddress.Text);
1.113 //First create our client and login
1.114 - if (File.Exists("SessionToken"))
1.115 + if (File.Exists("SessionToken") && !aForceAuth)
1.116 {
1.117 var sessionToken = File.ReadAllText("SessionToken");
1.118 Console.WriteLine("Harmony: Reusing token: {0}", sessionToken);
1.119 @@ -3087,5 +3085,6 @@
1.120 await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name);
1.121 }
1.122 }
1.123 +
1.124 }
1.125 }