Skip to content

Commit

Permalink
Added surpress token-refresh notifications option
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeiren committed Oct 28, 2013
1 parent 1a47a28 commit b43ea0d
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 21 deletions.
14 changes: 14 additions & 0 deletions EasyImgur/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 21 additions & 20 deletions EasyImgur/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ public Form1()
notifyIcon1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.NotifyIcon1_MouseDoubleClick);
tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);

ImgurAPI.obtainedAuthorization += new ImgurAPI.AuthorizationEventHandler(this.ObtainedOrRefreshedAPIAuthorization);
ImgurAPI.obtainedAuthorization += new ImgurAPI.AuthorizationEventHandler(this.ObtainedAPIAuthorization);
ImgurAPI.refreshedAuthorization += new ImgurAPI.AuthorizationEventHandler(this.ObtainedOrRefreshedAPIAuthorization);
ImgurAPI.refreshedAuthorization += new ImgurAPI.AuthorizationEventHandler(this.RefreshedAPIAuthorization);
ImgurAPI.lostAuthorization += new ImgurAPI.AuthorizationEventHandler(this.LostAPIAuthorization);

notifyIcon1.ShowBalloonTip(2000, "EasyImgur", "Right-click EasyImgur's icon in the tray to use it!", ToolTipIcon.Info);
notifyIcon1.ShowBalloonTip(2000, "EasyImgur is ready for use!", "Right-click EasyImgur's icon in the tray to use it!", ToolTipIcon.Info);

ImgurAPI.AttemptRefreshTokensFromDisk();
}
Expand All @@ -42,34 +40,34 @@ private void ApplicationExit( object sender, EventArgs e )
ImgurAPI.OnMainThreadExit();
}

private void ObtainedOrRefreshedAPIAuthorization()
{
uploadClipboardToolStripMenuItem.Enabled = true;
uploadFromFileToolStripMenuItem.Enabled = true;
label13.Text = "Authorized";
label13.ForeColor = System.Drawing.Color.Green;
buttonForceTokenRefresh.Enabled = true;
buttonForgetTokens.Enabled = true;
}

private void ObtainedAPIAuthorization()
{
SetAuthorizationStatusUI(true);
notifyIcon1.ShowBalloonTip(2000, "EasyImgur", "EasyImgur has received authorization to use your Imgur account!", ToolTipIcon.Info);
}

private void RefreshedAPIAuthorization()
{
notifyIcon1.ShowBalloonTip(2000, "EasyImgur", "EasyImgur has successfully refreshed authorization tokens!", ToolTipIcon.Info);
SetAuthorizationStatusUI(true);
if (Properties.Settings.Default.showNotificationOnTokenRefresh)
{
notifyIcon1.ShowBalloonTip(2000, "EasyImgur", "EasyImgur has successfully refreshed authorization tokens!", ToolTipIcon.Info);
}
}

private void SetAuthorizationStatusUI( bool _IsAuthorized )
{
uploadClipboardToolStripMenuItem.Enabled = _IsAuthorized;
uploadFromFileToolStripMenuItem.Enabled = _IsAuthorized;
label13.Text = _IsAuthorized ? "Authorized" : "Not authorized";
label13.ForeColor = _IsAuthorized ? System.Drawing.Color.Green : System.Drawing.Color.DarkBlue;
buttonForceTokenRefresh.Enabled = _IsAuthorized;
buttonForgetTokens.Enabled = _IsAuthorized;
}

private void LostAPIAuthorization()
{
uploadClipboardToolStripMenuItem.Enabled = false;
uploadFromFileToolStripMenuItem.Enabled = false;
label13.Text = "Not authorized";
label13.ForeColor = System.Drawing.Color.DarkBlue;
buttonForceTokenRefresh.Enabled = false;
buttonForgetTokens.Enabled = false;
SetAuthorizationStatusUI(false);
notifyIcon1.ShowBalloonTip(2000, "EasyImgur", "EasyImgur no longer has authorization to use your Imgur account!", ToolTipIcon.Info);
}

Expand Down Expand Up @@ -258,6 +256,7 @@ private void Form1_VisibleChanged(object sender, EventArgs e)
textBoxTitleFormat.Text = Properties.Settings.Default.titleFormat;
textBoxDescriptionFormat.Text = Properties.Settings.Default.descriptionFormat;
comboBoxImageFormat.SelectedIndex = Properties.Settings.Default.imageFormat;
checkBoxShowTokenRefreshNotification.Checked = Properties.Settings.Default.showNotificationOnTokenRefresh;


// Check the registry for a key describing whether EasyImgur should be started on boot.
Expand Down Expand Up @@ -293,6 +292,7 @@ private void SaveSettings()
Properties.Settings.Default.titleFormat = textBoxTitleFormat.Text;
Properties.Settings.Default.descriptionFormat = textBoxDescriptionFormat.Text;
Properties.Settings.Default.imageFormat = comboBoxImageFormat.SelectedIndex;
Properties.Settings.Default.showNotificationOnTokenRefresh = checkBoxShowTokenRefreshNotification.Checked;

Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (checkBoxLaunchAtBoot.Checked)
Expand Down Expand Up @@ -401,6 +401,7 @@ private void buttonRemoveFromImgur_Click(object sender, EventArgs e)

private void buttonForceTokenRefresh_Click(object sender, EventArgs e)
{
SetAuthorizationStatusUI(false);
ImgurAPI.ForceRefreshTokens();
}

Expand Down
11 changes: 10 additions & 1 deletion EasyImgur/ImgurAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,16 @@ static private bool RefreshTokens()
return false;
}

APIResponses.TokenResponse resp = Newtonsoft.Json.JsonConvert.DeserializeObject<APIResponses.TokenResponse>(responseString, new Newtonsoft.Json.JsonSerializerSettings { PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects });
APIResponses.TokenResponse resp = null;
try
{
resp = Newtonsoft.Json.JsonConvert.DeserializeObject<APIResponses.TokenResponse>(responseString, new Newtonsoft.Json.JsonSerializerSettings { PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects });
}
catch (Newtonsoft.Json.JsonReaderException ex)
{
Log.Error("Newtonsoft.Json.JsonReaderException occurred while trying to deserialize the following string:\n" + responseString + " (Line: " + ex.LineNumber + ", Position: " + ex.LinePosition + ", Message: " + ex.Message + ")");
resp = null;
}
if (resp != null && resp.access_token != null && resp.refresh_token != null)
{
StoreNewTokens(resp.expires_in, resp.access_token, resp.refresh_token);
Expand Down
12 changes: 12 additions & 0 deletions EasyImgur/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions EasyImgur/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
<Setting Name="refreshToken" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="showNotificationOnTokenRefresh" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
3 changes: 3 additions & 0 deletions EasyImgur/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<setting name="refreshToken" serializeAs="String">
<value />
</setting>
<setting name="showNotificationOnTokenRefresh" serializeAs="String">
<value>False</value>
</setting>
</EasyImgur.Properties.Settings>
</userSettings>
</configuration>
Binary file modified dist/Debug/EasyImgur.exe
Binary file not shown.
Binary file modified dist/Release/EasyImgur.exe
Binary file not shown.

0 comments on commit b43ea0d

Please sign in to comment.