public AppItemViewModel(IAudioMixerViewModelCallback callback, EarTrumpetAudioSessionModelGroup sessions) { _sessions = sessions; // select a session at random as sndvol does. var session = _sessions.Sessions.First(); IconHeight = IconWidth = 32; SessionId = session.SessionId; ProcessId = session.ProcessId; ExeName = GetExeName(session.DisplayName); IsDesktop = session.IsDesktop; _volume = Convert.ToInt32(Math.Round((session.Volume * 100), MidpointRounding.AwayFromZero)); _isMuted = session.IsMuted; _callback = callback; if (session.IsDesktop) { try { if (Path.GetExtension(session.IconPath) == ".dll") { Icon = IconExtensions.ExtractIconFromDll(session.IconPath); } else { // override for SpeechRuntime.exe (Repo -> HEY CORTANA) if (session.IconPath.ToLowerInvariant().Contains("speechruntime.exe")) { var sysType = Environment.Is64BitOperatingSystem ? "SysNative" : "System32"; Icon = IconExtensions.ExtractIconFromDll(Path.Combine("%windir%", sysType, "Speech\\SpeechUX\\SpeechUXWiz.exe"), 0); } else { Icon = System.Drawing.Icon.ExtractAssociatedIcon(session.IconPath).ToImageSource(); } } } catch { // ignored } Background = new SolidColorBrush(Colors.Transparent); } else { if (File.Exists(session.IconPath)) //hack until we invoke the resource manager correctly. { Icon = new BitmapImage(new Uri(session.IconPath)); } Background = new SolidColorBrush(AccentColorService.FromABGR(session.BackgroundColor)); } }
public AppItemViewModel(IAudioMixerViewModelCallback callback, EarTrumpetAudioSessionModelGroup sessions, ProcessTitleProvider titleProvider) { _sessions = sessions; // select a session at random as sndvol does. var session = _sessions.Sessions.First(); IconHeight = IconWidth = 32; SessionId = session.SessionId; DisplayName = session.DisplayName.Equals("System Sounds") ? EarTrumpet.Properties.Resources.SystemSoundsDisplayName : session.DisplayName; IsDesktop = session.IsDesktop; _volume = Convert.ToInt32(Math.Round((session.Volume * 100), MidpointRounding.AwayFromZero)); _callback = callback; if (session.IsDesktop) { try { Icon = Path.GetExtension(session.IconPath) == ".dll" ? IconExtensions.ExtractIconFromDll(session.IconPath) : System.Drawing.Icon.ExtractAssociatedIcon(session.IconPath).ToImageSource(); } catch { // ignored } Background = new SolidColorBrush(Colors.Transparent); try { string gotTitle; if (titleProvider.TryGetTitleForProcess(session.ProcessId, out gotTitle)) { DisplayName = gotTitle; } } catch { } // we fallback to exe name if DisplayName is not set in the try above. } else { if (File.Exists(session.IconPath)) //hack until we invoke the resource manager correctly. { Icon = new BitmapImage(new Uri(session.IconPath)); } Background = new SolidColorBrush(AccentColorService.FromABGR(session.BackgroundColor)); } }
//public static void UpdateThemeResources(ResourceDictionary dictionary) //{ // dictionary[@"WindowBackground"] = new SolidColorBrush(GetWindowBackgroundColor()); // SetBrush(dictionary, "WindowForeground", @"ImmersiveApplicationTextDarkTheme"); // ReplaceBrush(dictionary, "CottonSwabSliderThumb", @"ImmersiveSystemAccent"); // ReplaceBrush(dictionary, "CottonSwabSliderTrackBackground", SystemParameters.HighContrast ? "ImmersiveSystemAccentLight1" : "ImmersiveControlDarkSliderTrackBackgroundRest"); // SetBrushWithOpacity(dictionary, "CottonSwabSliderTrackBackgroundHover", SystemParameters.HighContrast ? "ImmersiveSystemAccentLight1" : "ImmersiveDarkBaseMediumHigh", SystemParameters.HighContrast ? 1.0 : 0.25); // SetBrush(dictionary, "CottonSwabSliderTrackBackgroundPressed", @"ImmersiveControlDarkSliderTrackBackgroundRest"); // ReplaceBrush(dictionary, "CottonSwabSliderTrackFill", @"ImmersiveSystemAccentLight1"); // SetBrush(dictionary, "CottonSwabSliderThumbHover", @"ImmersiveControlDarkSliderThumbHover"); // SetBrush(dictionary, "CottonSwabSliderThumbPressed", @"ImmersiveControlDarkSliderThumbHover"); //} /// <summary> /// /// </summary> /// <returns></returns> public static Color GetWindowBackgroundColor() { string resource; if (SystemInformation.HighContrast) { resource = "ImmersiveApplicationBackground"; } else if (UserSystemPreferencesService.UseAccentColor) { resource = IsWindowTransparencyEnabled ? "ImmersiveSystemAccentDark2" : "ImmersiveSystemAccentDark1"; } else { resource = "ImmersiveDarkChromeMedium"; } Color color = AccentColorService.GetColorByTypeName(resource); //return color; //color.A = (byte)(IsWindowTransparencyEnabled ? 190 : 255); return(Color.FromArgb(IsWindowTransparencyEnabled ? 190 : 255, color.R, color.G, color.B)); }