public WindowsTheme WatchTheme() { var currentUser = WindowsIdentity.GetCurrent(); string query = string.Format( CultureInfo.InvariantCulture, @"SELECT * FROM RegistryValueChangeEvent WHERE Hive = 'HKEY_USERS' AND KeyPath = '{0}\\{1}' AND ValueName = '{2}'", currentUser.User.Value, RegistryKeyPath.Replace(@"\", @"\\"), RegistryValueName); try { var watcher = new ManagementEventWatcher(query); watcher.EventArrived += (sender, args) => { CurrentWindowsTheme = GetWindowsTheme(); OnWindowsThemeChanged(CurrentWindowsTheme); // React to new theme }; // Start listening for events watcher.Start(); } catch (Exception) { throw; } CurrentWindowsTheme = GetWindowsTheme(); OnWindowsThemeChanged(CurrentWindowsTheme); return(CurrentWindowsTheme); }
public void WatchTheme() { WindowsIdentity currentUser = WindowsIdentity.GetCurrent(); string query = string.Format( CultureInfo.InvariantCulture, @"SELECT * FROM RegistryValueChangeEvent WHERE Hive = 'HKEY_USERS' AND KeyPath = '{0}\\{1}' AND ValueName = '{2}'", currentUser.User.Value, RegistryKeyPath.Replace(@"\", @"\\"), RegistryValueName); try { ManagementEventWatcher watcher = new(query); watcher.EventArrived += (sender, args) => { WindowsTheme newWindowsTheme = GetWindowsTheme(); OnThemeChanged(new WindowsThemeEventArgs(newWindowsTheme)); }; // Start listening for events watcher.Start(); } catch (Exception) { // This can fail on Windows 7 } }
public Task Execute(IJobExecutionContext context) { _currentTheme = GetWindowsTheme(); SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(ChangeToDarkMode); return(Task.CompletedTask); }
private static ResourceDictionary GetAccentResource(Accent accent) { return(accent.Specified != null ? new ResourceDictionary { Source = CreateAccentResourceUri(accent.Specified.Value), } : GetAccentResource(accent.Color ?? WindowsTheme.GetAccentColor())); }
public static IconSettings GetSettings(WindowsTheme theme) { var size = SystemInformation.SmallIconSize; Log.Write($"{nameof(SystemInformation.SmallIconSize)}: {size.Width}x{size.Height}"); return(GetSettings(size, theme)); }
private void OnColorValuesChanged() { currentWindowsTheme = ThemeHelper.GetWindowsTheme(); if (windowsTheme != currentWindowsTheme) { Log.Write("OnWindowsThemeChanged -> {0}", currentWindowsTheme); SignalDataChanged(); } }
private void InitializeTheme() { windowsTheme = ThemeHelper.GetWindowsTheme(); currentWindowsTheme = windowsTheme; uiSettings = new UISettings(); // Based on observation this fires immediately when Windows theme changes. But none of colors in GetColorValue() // or UIElementColor() are actually updated, so handling the theme change must be done manually. uiSettings.ColorValuesChanged += (s, e) => OnColorValuesChanged(); }
public void Attach(IChromeOwner window) { Action <Color> applyAccent = color => this.Background = new SolidColorBrush(Color.FromRgb(color.R, color.G, color.B)); var disposable = WindowsTheme.RegisterAccentColorListener(applyAccent); this.Closed += (sender, e) => disposable.Dispose(); applyAccent(WindowsTheme.GetAccentColor()); this.Attach(window, true); }
private void CheckTheme() { this.theme = themeMonitor.GetTheme(); switch (theme) { case WindowsTheme.Dark: interfaceController.darkTheme(); break; case WindowsTheme.Light: interfaceController.lightTheme(); break; } }
/// <summary> /// Helper method for converting theme information. /// </summary> private static MessageCommunicatorTheme WindowsThemeToMessageCommunicator(WindowsTheme winTheme) { switch (winTheme) { case WindowsTheme.Dark: return(MessageCommunicatorTheme.Dark); case WindowsTheme.Light: return(MessageCommunicatorTheme.Light); default: throw new ArgumentOutOfRangeException(nameof(winTheme), winTheme, null); } }
public void WatchTheme() { var currentUser = WindowsIdentity.GetCurrent(); string query = string.Format( CultureInfo.InvariantCulture, @"SELECT * FROM RegistryValueChangeEvent WHERE Hive = 'HKEY_USERS' AND KeyPath = '{0}\\{1}' AND ValueName = '{2}'", currentUser.User.Value, RegistryKeyPath.Replace(@"\", @"\\"), RegistryValueName); try { var watcher = new ManagementEventWatcher(query); watcher.EventArrived += (sender, args) => { WindowsTheme newWindowsTheme = GetWindowsTheme(); if (newWindowsTheme != CurrentTheme) { var acnt = (SolidColorBrush)SystemParameters.WindowGlassBrush; acnt.Freeze(); OnThemeChanged?.Invoke(this, new ThemeChangeEventArgs { CurrentTheme = newWindowsTheme, AccentColor = acnt.Color }); // React to new theme CurrentTheme = newWindowsTheme; } }; // Start listening for events watcher.Start(); DispatcherTimer accentWatcher = new DispatcherTimer { Interval = TimeSpan.FromSeconds(5), }; accentWatcher.Tick += AccentWatcher_Tick; accentWatcher.Start(); } catch (Exception) { // This can fail on Windows 7 } WindowsTheme initialTheme = GetWindowsTheme(); }
private void ChangeToDarkMode(object sender, UserPreferenceChangedEventArgs e) { WindowsTheme selectedTheme = GetWindowsTheme(); if (_currentTheme != selectedTheme) { _currentTheme = selectedTheme; if (_currentTheme == WindowsTheme.Dark) { Console.WriteLine("Dark theme selected"); Console.ReadLine(); } } }
public void SetTheme(WindowsTheme theme) { if (theme == WindowsTheme.Light) { this.DarkTheme.IsChecked = false; this.LightTheme.IsChecked = true; } else if (theme == WindowsTheme.Dark) { this.DarkTheme.IsChecked = true; this.LightTheme.IsChecked = false; } currentTheme = theme; Console.WriteLine("Using theme: " + theme); Application.Current.Resources.MergedDictionaries[0].Source = new Uri($"/Themes/{theme}.xaml", UriKind.Relative); }
private void UpdateListener(Accent accent) { if (accent == Accent.Windows) { if (this.windowsColorListener == null) { // アクセントが Windows 依存で、リスナーが未登録だったら購読する this.windowsColorListener = WindowsTheme.RegisterAccentColorListener(x => this.ChangeAccentCore(x)); } } else if (this.windowsColorListener != null) { // アクセントが Windows 依存でないのにリスナーが登録されてたら解除する this.windowsColorListener.Dispose(); this.windowsColorListener = null; } }
private bool Update() { var currentBatteryData = testBatteryData != null?testBatteryData.GetNextTestData() : new BatteryData(battery); // These conditions all forces icon (re)drawing, even if there's no change in CurrentCharge or the change is too small // to cause the number of levels to update. var drawIcon = windowsTheme != currentWindowsTheme || batteryData == null || batteryData.IsCharging != currentBatteryData.IsCharging || batteryData.IsAboveMaximumCharge != currentBatteryData.IsAboveMaximumCharge || batteryData.IsBelowMinimumCharge != currentBatteryData.IsBelowMinimumCharge || batteryData.IsCriticalCharge != currentBatteryData.IsCriticalCharge; if (drawIcon || batteryData.CurrentCharge != currentBatteryData.CurrentCharge || batteryData.CurrentTime != currentBatteryData.CurrentTime || batteryData.IsPluggedInNotCharging != currentBatteryData.IsPluggedInNotCharging) { if (currentBatteryData.IsNotAvailable) { CreateBatteryUpdateText(Resources.BatteryNotFound); CreateBatteryWarningText(Resources.BatteryNotFound); CreateBatteryIcon(currentBatteryData, currentWindowsTheme, drawIcon); } else { Log.Write("Battery: {0}", currentBatteryData); var currentUpdateText = TextFormatter.FormatBatteryUpdateText(currentBatteryData); CreateBatteryUpdateText(currentUpdateText); WarningText = null; CreateBatteryIcon(currentBatteryData, currentWindowsTheme, drawIcon); } batteryData = currentBatteryData; windowsTheme = currentWindowsTheme; return(true); } return(false); }
public static void ChangeTaskbarPinIcon(WindowsTheme theme) { string taskbarShortcutPath = GetTaskbarShortcutPath(); if (System.IO.File.Exists(taskbarShortcutPath)) { System.IO.File.Delete(taskbarShortcutPath); } WshShell shell = new WshShell(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(taskbarShortcutPath); shortcut.TargetPath = Process.GetCurrentProcess().MainModule.FileName; shortcut.IconLocation = GetIconPath(theme); shortcut.Save(); foreach (Process process in Process.GetProcessesByName("explorer")) { process.Kill(); } }
public static IconSettings GetSettings(Size size, WindowsTheme theme) { var check = size.Width; if (size.Width != size.Height) { check = Math.Min(size.Width, size.Height); } // Assume that reducing is better than enlarging if (check < 20) { return(new IconSettings(Settings.BatteryIcon100, theme)); } if (check < 24) { return(new IconSettings(Settings.BatteryIcon150, theme)); } // Return the largest setting we have return(new IconSettings(Settings.BatteryIcon150, theme)); }
private void OnWindowsThemeChanged(WindowsTheme newTheme) { WindowsThemeChanged?.Invoke(newTheme); }
public static string GetIconPath(WindowsTheme theme) { string processPath = Process.GetCurrentProcess().MainModule.FileName; return(Directory.GetParent(processPath).FullName + "\\Icons\\" + theme.ToString() + ".ico"); }
public IconSettings(BatteryIcon batteryIcon, WindowsTheme theme) { this.batteryIcon = batteryIcon; ForegroundColor = theme == WindowsTheme.Light ? Settings.ForegroundColorLightTheme : Settings.ForegroundColorDarkTheme; }
protected virtual void OnWindowsThemeChanged(WindowsTheme theme) { EventHandler <FunctionEventArgs <WindowsTheme> > handler = WindowsThemeChanged; handler?.Invoke(this, new FunctionEventArgs <WindowsTheme>(theme)); }