diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index a4fa7e62..077bb8b9 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -95,7 +95,11 @@ public FormBrowser(){ this.trayIcon.ClickClose += trayIcon_ClickClose; Config.TrayBehaviorChanged += Config_TrayBehaviorChanged; - UpdateTrayIcon(); + UpdateTray(); + + if (Config.MuteNotifications){ + UpdateFormIcon(); + } this.updates = new UpdateHandler(browser, Program.InstallerPath); this.updates.CheckFinished += updates_CheckFinished; @@ -127,7 +131,11 @@ private void RestoreWindow(){ isLoaded = true; } - private void UpdateTrayIcon(){ + private void UpdateFormIcon(){ // TODO fix to show icon in taskbar too + Icon = Config.MuteNotifications ? Properties.Resources.icon_muted : Properties.Resources.icon; + } + + private void UpdateTray(){ trayIcon.Visible = Config.TrayBehavior.ShouldDisplayIcon(); } @@ -202,18 +210,19 @@ private void FormBrowser_FormClosed(object sender, FormClosedEventArgs e){ } private void Config_MuteToggled(object sender, EventArgs e){ + UpdateFormIcon(); AnalyticsFile.NotificationMutes.Trigger(); } private void Config_TrayBehaviorChanged(object sender, EventArgs e){ - UpdateTrayIcon(); + UpdateTray(); } private void trayIcon_ClickRestore(object sender, EventArgs e){ Show(); RestoreWindow(); Activate(); - UpdateTrayIcon(); + UpdateTray(); } private void trayIcon_ClickClose(object sender, EventArgs e){ diff --git a/Core/Other/TrayIcon.cs b/Core/Other/TrayIcon.cs index 3f461770..7d716746 100644 --- a/Core/Other/TrayIcon.cs +++ b/Core/Other/TrayIcon.cs @@ -1,6 +1,8 @@ using System; using System.ComponentModel; using System.Windows.Forms; +using TweetDuck.Configuration; +using Res = TweetDuck.Properties.Resources; namespace TweetDuck.Core.Other{ sealed partial class TrayIcon : Component{ @@ -8,6 +10,8 @@ public enum Behavior{ // keep order Disabled, DisplayOnly, MinimizeToTray, CloseToTray, Combined } + private static UserConfig Config => Program.UserConfig; + public event EventHandler ClickRestore; public event EventHandler ClickClose; @@ -17,12 +21,9 @@ public bool Visible{ } set{ - if (value){ - notifyIcon.Icon = Properties.Resources.icon_tray; - } - notifyIcon.Visible = value; hasNotifications = false; + UpdateIcon(); } } @@ -32,9 +33,9 @@ public bool HasNotifications{ } set{ - if (hasNotifications != value && Visible){ - notifyIcon.Icon = value ? Properties.Resources.icon_tray_new : Properties.Resources.icon_tray; + if (hasNotifications != value){ hasNotifications = value; + UpdateIcon(); } } } @@ -53,14 +54,26 @@ public TrayIcon(){ this.notifyIcon.ContextMenu = contextMenu; this.notifyIcon.Text = Program.BrandName; + + Config.MuteToggled += Config_MuteToggled; } public TrayIcon(IContainer container) : this(){ container.Add(this); } + private void UpdateIcon(){ + if (Visible){ + notifyIcon.Icon = hasNotifications ? Res.icon_tray_new : Config.MuteNotifications ? Res.icon_tray_muted : Res.icon_tray; + } + } + // event handlers + private void Config_MuteToggled(object sender, EventArgs e){ + UpdateIcon(); + } + private void trayIcon_MouseClick(object sender, MouseEventArgs e){ if (e.Button == MouseButtons.Left){ menuItemRestore_Click(sender, e); @@ -68,7 +81,7 @@ private void trayIcon_MouseClick(object sender, MouseEventArgs e){ } private void contextMenu_Popup(object sender, EventArgs e){ - contextMenu.MenuItems[1].Checked = Program.UserConfig.MuteNotifications; + contextMenu.MenuItems[1].Checked = Config.MuteNotifications; } private void menuItemRestore_Click(object sender, EventArgs e){ @@ -76,8 +89,8 @@ private void menuItemRestore_Click(object sender, EventArgs e){ } private void menuItemMuteNotifications_Click(object sender, EventArgs e){ - Program.UserConfig.MuteNotifications = !contextMenu.MenuItems[1].Checked; - Program.UserConfig.Save(); + Config.MuteNotifications = !contextMenu.MenuItems[1].Checked; + Config.Save(); } private void menuItemClose_Click(object sender, EventArgs e){ diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 20c91403..1fe43609 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -80,6 +80,16 @@ internal static System.Drawing.Icon icon { } } + /// <summary> + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// </summary> + internal static System.Drawing.Icon icon_muted { + get { + object obj = ResourceManager.GetObject("icon_muted", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// <summary> /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// </summary> @@ -90,6 +100,16 @@ internal static System.Drawing.Icon icon_tray { } } + /// <summary> + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// </summary> + internal static System.Drawing.Icon icon_tray_muted { + get { + object obj = ResourceManager.GetObject("icon_tray_muted", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// <summary> /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// </summary> diff --git a/Properties/Resources.resx b/Properties/Resources.resx index a8d8f0ef..4964019c 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -124,9 +124,15 @@ <data name="icon" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>..\Resources\icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> + <data name="icon_muted" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\icon-muted.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + </data> <data name="icon_tray" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>..\Resources\icon-tray.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> + <data name="icon_tray_muted" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\icon-tray-muted.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + </data> <data name="icon_tray_new" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>..\Resources\icon-tray-new.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> diff --git a/Resources/icon-muted.ico b/Resources/icon-muted.ico new file mode 100644 index 00000000..013ce46b Binary files /dev/null and b/Resources/icon-muted.ico differ diff --git a/Resources/icon-tray-muted.ico b/Resources/icon-tray-muted.ico new file mode 100644 index 00000000..d80aa2ba Binary files /dev/null and b/Resources/icon-tray-muted.ico differ diff --git a/TweetDuck.csproj b/TweetDuck.csproj index 35b50327..288c1e9f 100644 --- a/TweetDuck.csproj +++ b/TweetDuck.csproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="packages\CefSharp.WinForms.66.0.0-CI2629\build\CefSharp.WinForms.props" Condition="Exists('packages\CefSharp.WinForms.66.0.0-CI2629\build\CefSharp.WinForms.props')" /> <Import Project="packages\CefSharp.Common.66.0.0-CI2629\build\CefSharp.Common.props" Condition="Exists('packages\CefSharp.Common.66.0.0-CI2629\build\CefSharp.Common.props')" /> @@ -334,6 +334,8 @@ </ItemGroup> <ItemGroup> <Content Include="Resources\avatar.png" /> + <None Include="Resources\icon-tray-muted.ico" /> + <None Include="Resources\icon-muted.ico" /> <None Include="packages.config" /> <None Include="Resources\icon-small.ico" /> <None Include="Resources\icon-tray-new.ico" />