private static Icon LoadIcon(IconKind kind) { uint dpi = WindowsTaskbar.Dpi; switch (kind) { case IconKind.EarTrumpet: return(IconHelper.LoadIconForTaskbar((string)App.Current.Resources["EarTrumpetIconDark"], dpi)); case IconKind.EarTrumpet_LightTheme: return(IconHelper.LoadIconForTaskbar((string)App.Current.Resources["EarTrumpetIconLight"], dpi)); case IconKind.Muted: return(IconHelper.LoadIconForTaskbar(SndVolSSO.GetPath(SndVolSSO.IconId.Muted), dpi)); case IconKind.NoDevice: return(IconHelper.LoadIconForTaskbar(SndVolSSO.GetPath(SndVolSSO.IconId.NoDevice), dpi)); case IconKind.SpeakerZeroBars: return(IconHelper.LoadIconForTaskbar(SndVolSSO.GetPath(SndVolSSO.IconId.SpeakerZeroBars), dpi)); case IconKind.SpeakerOneBar: return(IconHelper.LoadIconForTaskbar(SndVolSSO.GetPath(SndVolSSO.IconId.SpeakerOneBar), dpi)); case IconKind.SpeakerTwoBars: return(IconHelper.LoadIconForTaskbar(SndVolSSO.GetPath(SndVolSSO.IconId.SpeakerTwoBars), dpi)); case IconKind.SpeakerThreeBars: return(IconHelper.LoadIconForTaskbar(SndVolSSO.GetPath(SndVolSSO.IconId.SpeakerThreeBars), dpi)); default: throw new NotImplementedException(); } }
private void UpdateTrayTooltipAndIcon() { var iconType = (PlaybackDevicesViewModel.Default == null) ? SndVolSSO.IconId.NoDevice : PlaybackDevicesViewModel.Default.GetSndVolIcon(); _trayIcon.IconSource.Tag = iconType; _trayIcon.IconSource.Source = SndVolSSO.GetPath(iconType); _trayIcon.SetTooltip(PlaybackDevicesViewModel.GetTrayToolTip()); }
private void CreateTrayExperience() { if (!SndVolSSO.SystemIconsAreAvailable()) { _settings.UseLegacyIcon = true; } TaskbarIconSource iconSource = null; iconSource = new TaskbarIconSource(icon => { if (_settings.UseLegacyIcon) { icon?.Dispose(); icon = IconHelper.LoadIconForTaskbar(SystemSettings.IsSystemLightTheme ? $"{AssetBaseUri}Application.ico" : $"{AssetBaseUri}Tray.ico"); } double iconFillPercent = ((SndVolSSO.IconId)iconSource.Tag) == SndVolSSO.IconId.NoDevice && !_settings.UseLegacyIcon ? 0.4 : 1; if (SystemParameters.HighContrast) { icon = IconHelper.ColorIcon(icon, iconFillPercent, _trayIcon.IsMouseOver ? SystemColors.HighlightTextColor : SystemColors.WindowTextColor); } else if (SystemSettings.IsSystemLightTheme && !_settings.UseLegacyIcon) { icon = IconHelper.ColorIcon(icon, iconFillPercent, System.Windows.Media.Colors.Black); } return(icon); }, () => $"hc={SystemParameters.HighContrast} {(SystemParameters.HighContrast ? $"mouse={_trayIcon.IsMouseOver}" : "")} dpi={WindowsTaskbar.Dpi} theme={SystemSettings.IsSystemLightTheme} legacy={_settings.UseLegacyIcon}"); _settings.UseLegacyIconChanged += (_, __) => iconSource.CheckForUpdate(); _trayIcon = new ShellNotifyIcon(iconSource, () => _settings.TrayIconIdentity, _settings.ResetTrayIconIdentity); _trayIcon.PrimaryInvoke += (_, type) => FlyoutViewModel.OpenFlyout(type); _trayIcon.SecondaryInvoke += (_, __) => _trayIcon.ShowContextMenu(GetTrayContextMenuItems()); _trayIcon.TertiaryInvoke += (_, __) => PlaybackDevicesViewModel.Default?.ToggleMute.Execute(null); _trayIcon.Scrolled += (_, wheelDelta) => PlaybackDevicesViewModel.Default?.IncrementVolume(Math.Sign(wheelDelta) * 2); Exit += (_, __) => _trayIcon.IsVisible = false; UpdateTrayTooltipAndIcon(); }