diff --git a/RetroBar/Controls/NotifyIcon.xaml.cs b/RetroBar/Controls/NotifyIcon.xaml.cs index e7d6146b..844a05c9 100644 --- a/RetroBar/Controls/NotifyIcon.xaml.cs +++ b/RetroBar/Controls/NotifyIcon.xaml.cs @@ -6,6 +6,7 @@ using ManagedShell.Common.Helpers; using ManagedShell.Interop; using ManagedShell.WindowsTray; +using RetroBar.Extensions; using RetroBar.Utilities; namespace RetroBar.Controls @@ -33,21 +34,12 @@ public NotifyIcon() private void applyEffects() { - if ((!EnvironmentHelper.IsWindows10OrBetter && Settings.Instance.InvertIconsMode == Settings.InvertIconsOption.WhenNeededByTheme) || TrayIcon == null || Settings.Instance.InvertIconsMode == Settings.InvertIconsOption.Never) + if (TrayIcon == null || Settings.Instance.InvertIconsMode == Settings.InvertIconsOption.Never) { return; } - string iconGuid = TrayIcon.GUID.ToString(); - - if (!(iconGuid == NotificationArea.HARDWARE_GUID || - iconGuid == NotificationArea.UPDATE_GUID || - iconGuid == NotificationArea.MICROPHONE_GUID || - iconGuid == NotificationArea.LOCATION_GUID || - iconGuid == NotificationArea.MEETNOW_GUID || - iconGuid == NotificationArea.NETWORK_GUID || - iconGuid == NotificationArea.POWER_GUID || - iconGuid == NotificationArea.VOLUME_GUID)) + if (!TrayIcon.CanInvert()) { return; } diff --git a/RetroBar/Controls/NotifyIconList.xaml.cs b/RetroBar/Controls/NotifyIconList.xaml.cs index 6b8ee437..2b167485 100644 --- a/RetroBar/Controls/NotifyIconList.xaml.cs +++ b/RetroBar/Controls/NotifyIconList.xaml.cs @@ -51,12 +51,12 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e) NotifyIcons.ItemsSource = allNotifyIconsSource.View; } } - else if (e.PropertyName == nameof(Settings.InvertIconsMode)) + else if (e.PropertyName == nameof(Settings.InvertIconsMode) || e.PropertyName == nameof(Settings.InvertNotifyIcons)) { // Reload icons NotifyIcons.ItemsSource = null; - if (Settings.Instance.CollapseNotifyIcons) + if (Settings.Instance.CollapseNotifyIcons && NotifyIconToggleButton.IsChecked != true) { NotifyIcons.ItemsSource = pinnedNotifyIconsSource.View; } diff --git a/RetroBar/Converters/BoolToIntConverter.cs b/RetroBar/Converters/BoolToIntConverter.cs index b777b1da..e0906bcb 100644 --- a/RetroBar/Converters/BoolToIntConverter.cs +++ b/RetroBar/Converters/BoolToIntConverter.cs @@ -10,7 +10,12 @@ public object Convert(object value, Type targetType, object parameter, System.Gl { if (value is bool boolValue) { - return boolValue ? 1 : 0; + var multiplier = 1; + if (parameter is string strValue) + { + multiplier = System.Convert.ToInt32(strValue); + } + return boolValue ? 1 * multiplier : 0; } return Binding.DoNothing; diff --git a/RetroBar/Converters/NotifyIconCanInvertConverter.cs b/RetroBar/Converters/NotifyIconCanInvertConverter.cs new file mode 100644 index 00000000..78b27c70 --- /dev/null +++ b/RetroBar/Converters/NotifyIconCanInvertConverter.cs @@ -0,0 +1,26 @@ +using ManagedShell.WindowsTray; +using RetroBar.Extensions; +using System; +using System.Windows.Data; + +namespace RetroBar.Converters +{ + [ValueConversion(typeof(NotifyIcon), typeof(bool))] + public class NotifyIconCanInvertConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value is NotifyIcon icon) + { + return icon.CanInvert(); + } + + return Binding.DoNothing; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return Binding.DoNothing; + } + } +} diff --git a/RetroBar/Extensions/NotifyIconExtensions.cs b/RetroBar/Extensions/NotifyIconExtensions.cs new file mode 100644 index 00000000..99c71039 --- /dev/null +++ b/RetroBar/Extensions/NotifyIconExtensions.cs @@ -0,0 +1,41 @@ +using ManagedShell.WindowsTray; +using RetroBar.Utilities; +using System.Collections.Generic; + +namespace RetroBar.Extensions +{ + public static class NotifyIconExtensions + { + public static string GetInvertIdentifier(this NotifyIcon icon) + { + if (icon.GUID != default) return icon.GUID.ToString(); + else return icon.Path + ":" + icon.UID.ToString(); + } + + public static bool CanInvert(this NotifyIcon icon) { + return Settings.Instance.InvertNotifyIcons.Contains(icon.GetInvertIdentifier()); + } + + public static void SetCanInvert(this NotifyIcon icon, bool canInvert) + { + var identifier = icon.GetInvertIdentifier(); + var settings = new List(Settings.Instance.InvertNotifyIcons); + var changed = false; + + if (!canInvert) + { + changed = settings.Remove(identifier); + } + else if (!settings.Contains(identifier)) + { + settings.Add(identifier); + changed = true; + } + + if (changed) + { + Settings.Instance.InvertNotifyIcons = settings; + } + } + } +} diff --git a/RetroBar/Languages/English.xaml b/RetroBar/Languages/English.xaml index 23b43dba..8cabff8f 100644 --- a/RetroBar/Languages/English.xaml +++ b/RetroBar/Languages/English.xaml @@ -71,6 +71,7 @@ Always show Name Behavior + Invert Start start diff --git a/RetroBar/NotificationPropertiesWindow.xaml b/RetroBar/NotificationPropertiesWindow.xaml index 4df39564..0e928fdd 100644 --- a/RetroBar/NotificationPropertiesWindow.xaml +++ b/RetroBar/NotificationPropertiesWindow.xaml @@ -2,6 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converters="clr-namespace:RetroBar.Converters" + xmlns:Settings="clr-namespace:RetroBar.Utilities" Title="{DynamicResource customize_notifications}" Height="406" Width="364" @@ -12,7 +13,9 @@ + +