/// <summary> /// Adds missing monitors to the configuration file /// If a monitor configuration is not found, /// it will automatically create a configuration with the respective monitor's current wallpaper /// </summary> public static void DetectMonitors() { var monitors = Task.Run(async() => await DisplayHandler.GetMonitorInfosAsync()).Result; IDesktopWallpaper handler = (IDesktopWallpaper) new DesktopWallpaperClass(); List <string> monitorIds = new(); bool needsUpdate = false; foreach (var monitor in monitors) { MonitorSettings settings = builder.Config.WallpaperSwitch.Component.Monitors.Find(m => m.Id == monitor.DeviceId); if (settings == null) { Logger.Info($"missing monitor found, adding new default config for: {monitor.DeviceId}"); builder.Config.WallpaperSwitch.Component.Monitors.Add(new MonitorSettings() { DarkThemeWallpaper = handler.GetWallpaper(monitor.DeviceId), LightThemeWallpaper = handler.GetWallpaper(monitor.DeviceId), Id = monitor.DeviceId }); needsUpdate = true; } } if (needsUpdate) { GlobalState state = GlobalState.Instance(); state.SkipConfigFileReload = true; builder.Save(); } }
//save theme selection private void SaveThemeSettings() { //disable wallpaper switch builder.Config.WallpaperSwitch.Enabled = false; //get selected light theme file from combobox string selectedLightTheme = (string)ComboBoxLightTheme.SelectedItem; try { ThemeFile selected = themeCollection.FirstOrDefault(t => t.ToString().Contains(selectedLightTheme)); if (selected != null) { builder.Config.WindowsThemeMode.LightThemePath = selected.Path; } } catch { theme1 = false; ComboBoxLightTheme.SelectedItem = null; } //get selected dark theme file from combobox string selectedDarkTheme = (string)ComboBoxDarkTheme.SelectedItem; try { ThemeFile selected = themeCollection.FirstOrDefault(t => t.ToString().Contains(selectedDarkTheme)); if (selected != null) { builder.Config.WindowsThemeMode.DarkThemePath = selected.Path; } } catch { theme2 = false; ComboBoxDarkTheme.SelectedItem = null; } //enable theme mode builder.Config.WindowsThemeMode.Enabled = true; //ui changes TextBlockUserFeedback.Visibility = Visibility.Visible; //apply theme try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex, "SaveThemeSettings"); } RequestThemeSwitch(); Trace.WriteLine("Windows Theme Mode settings were applied"); }
public static void CleanUpMonitors() { AdmConfigBuilder builder = AdmConfigBuilder.Instance(); IDesktopWallpaper handler = (IDesktopWallpaper) new DesktopWallpaperClass(); List <string> monitorIds = new(); for (uint i = 0; i < handler.GetMonitorDevicePathCount(); i++) { monitorIds.Add(handler.GetMonitorDevicePathAt(i)); } List <MonitorSettings> connectedSettings = new(); foreach (string monitorId in monitorIds) { if (monitorId.Length == 0) { continue; } MonitorSettings settings = builder.Config.WallpaperSwitch.Component.Monitors.Find(m => m.Id == monitorId); if (settings != null) { connectedSettings.Add(settings); } } int diff = builder.Config.WallpaperSwitch.Component.Monitors.Count - connectedSettings.Count; if (diff != 0) { Logger.Info($"removing {diff} disconnected monitors"); GlobalState state = GlobalState.Instance(); state.SkipConfigFileReload = true; builder.Config.WallpaperSwitch.Component.Monitors = connectedSettings; builder.Save(); } }
private void CheckBoxBatteryDarkMode_Click(object sender, RoutedEventArgs e) { if (CheckBoxBatteryDarkMode.IsChecked.Value) { builder.Config.Events.DarkThemeOnBattery = true; } else { builder.Config.Events.DarkThemeOnBattery = false; } try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex, "CheckBoxBatteryDarkMode_Click"); } }
private async void ApplyTheme() { //show warning for notebook on battery with enabled battery saver if (PowerManager.EnergySaverStatus == EnergySaverStatus.On) { userFeedback.Text = Properties.Resources.msgChangesSaved + "\n\n" + Properties.Resources.msgBatterySaver; applyButton.IsEnabled = true; } else { userFeedback.Text = Properties.Resources.msgChangesSaved;//changes were saved! } if (builder.Config.Location.Enabled) { ActivateLocationMode(); } else { try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex); } } try { string result = await messagingClient.SendMessageAndGetReplyAsync(Command.Switch); if (result == Response.Err) { throw new SwitchThemeException(); } } catch (Exception ex) { ErrorWhileApplyingTheme($"ZMQ message is {Response.Err}", ex.ToString()); } }
private void ToggleSwitchWallpaper_Toggled(object sender, RoutedEventArgs e) { if ((sender as ModernWpf.Controls.ToggleSwitch).IsOn) { builder.Config.WallpaperSwitch.Enabled = true; ChangeUiEnabledStatus(true); } else { builder.Config.WallpaperSwitch.Enabled = false; ChangeUiEnabledStatus(false); } try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex, "PageWallpaperPicker"); } }
//open wallpaper configuration private void BGWinButton_Click(object sender, RoutedEventArgs e) { DesktopBGui BGui = new DesktopBGui(); BGui.Owner = Window.GetWindow(this); BGui.ShowDialog(); if (BGui.saved == true) { ButtonDisableTheme_Click(this, e); } try { builder.Save(); } catch (Exception ex) { ShowErrorMessage("error saving config in BGWinButton_Click: ", ex); } ShowDeskBGStatus(); RequestThemeSwitch(); }
private void AppComboBox_DropDownClosed(object sender, EventArgs e) { if (AppComboBox.SelectedIndex.Equals(0)) { builder.Config.AppsTheme = Mode.Switch; } if (AppComboBox.SelectedIndex.Equals(1)) { builder.Config.AppsTheme = Mode.LightOnly; } if (AppComboBox.SelectedIndex.Equals(2)) { builder.Config.AppsTheme = Mode.DarkOnly; } try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex); } RequestThemeSwitch(); }
private async void CheckBoxColourFilter_Click(object sender, RoutedEventArgs e) { RegeditHandler regeditHandler = new RegeditHandler(); if (CheckBoxColourFilter.IsChecked.Value) { regeditHandler.ColourFilterSetup(); builder.Config.ColorFilterEnabled = true; } else { regeditHandler.ColourFilterKeySender(false); builder.Config.ColorFilterEnabled = false; } try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex); } await messagingClient.SendMessageAsync(Command.Switch); }
/// <summary> /// Adds missing monitors to the configuration file /// If a monitor configuration is not found, /// it will automatically create a configuration with the respective monitor's current wallpaper /// </summary> public static void DetectMonitors() { var monitors = Task.Run(async() => await GetMonitorInfosAsync()).Result; AdmConfigBuilder builder = AdmConfigBuilder.Instance(); IDesktopWallpaper handler = (IDesktopWallpaper) new DesktopWallpaperClass(); List <string> monitorIds = new(); for (uint i = 0; i < handler.GetMonitorDevicePathCount(); i++) { monitorIds.Add(handler.GetMonitorDevicePathAt(i)); } bool needsUpdate = false; foreach (string monitorId in monitorIds) { if (monitorId.Length == 0) { continue; } MonitorSettings settings = builder.Config.WallpaperSwitch.Component.Monitors.Find(m => m.Id == monitorId); if (settings == null) { Logger.Info($"missing monitor found, adding new default config for: {monitorId}"); builder.Config.WallpaperSwitch.Component.Monitors.Add(new MonitorSettings() { DarkThemeWallpaper = handler.GetWallpaper(monitorId), LightThemeWallpaper = handler.GetWallpaper(monitorId), Id = monitorId }); needsUpdate = true; } } if (needsUpdate) { GlobalState state = GlobalState.Instance(); state.SkipConfigFileReload = true; builder.Save(); } }
/// <summary> /// Offset /// for sunrise and sunset hours /// </summary> //apply offset private void OffsetButton_Click(object sender, RoutedEventArgs e) { int offsetDark; int offsetLight; //get values from TextBox try { offsetDark = Convert.ToInt32(NumberboxOffsetDark.Value); offsetLight = Convert.ToInt32(NumberBoxOffsetLight.Value); } catch { userFeedback.Text = Properties.Resources.errorNumberInput; return; } //send the values / offset to Svc try { builder.Config.Location.SunriseOffsetMin = offsetLight; builder.Config.Location.SunsetOffsetMin = offsetDark; } catch { userFeedback.Text = "Error while sending offset digits to Svc"; return; } OffsetButton.IsEnabled = false; UpdateSuntimes(); Dispatcher.BeginInvoke(new DispatcherDelegate(ApplyTheme)); try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex, "OffsetButton_Click"); } }
private void DeleButton_Click(object sender, RoutedEventArgs e) { builder.Config.WallpaperSwitch.Enabled = false; builder.Save(); Close(); }
private void UiHandler() { try { builder.Load(); } catch (Exception ex) { ShowErrorMessage(ex); } //if a windows theme file was picked if (builder.Config.WindowsThemeMode.Enabled) { AccentColorCheckBox.IsEnabled = false; AccentColorCheckBox.ToolTip = Properties.Resources.ToolTipDisabledDueTheme; SystemComboBox.IsEnabled = false; SystemComboBox.ToolTip = Properties.Resources.ToolTipDisabledDueTheme; AppComboBox.IsEnabled = false; AppComboBox.ToolTip = Properties.Resources.ToolTipDisabledDueTheme; NumberBoxColorDelay.IsEnabled = false; NumberBoxColorDelay.ToolTip = Properties.Resources.ToolTipDisabledDueTheme; } //if the OS version is older than 1903 if (int.Parse(RegistryHandler.GetOSversion()).CompareTo(1900) > 0) { is1903 = true; } if (!is1903) { SystemComboBox.IsEnabled = false; SystemComboBox.ToolTip = Properties.Resources.cmb1903; AccentColorCheckBox.IsEnabled = false; AccentColorCheckBox.ToolTip = Properties.Resources.cmb1903; builder.Config.SystemSwitch.Enabled = false; try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex); } } else //os version 1903+ { //inform user about settings if (!builder.Config.WindowsThemeMode.Enabled) { AccentColorCheckBox.ToolTip = Properties.Resources.cbAccentColor; } //numbox NumberBoxColorDelay.Value = Convert.ToInt32(builder.Config.SystemSwitch.Component.TaskbarSwitchDelay); //is accent color switch enabled? AccentColorCheckBox.IsChecked = builder.Config.SystemSwitch.Component.TaskbarColorOnDark; if (!AccentColorCheckBox.IsChecked.Value) { TextBlockColorDelay.Visibility = Visibility.Collapsed; NumberBoxColorDelay.Visibility = Visibility.Collapsed; } } //combobox if (builder.Config.AppsSwitch.Enabled) { AppComboBox.SelectedIndex = (int)builder.Config.AppsSwitch.Component.Mode; } else { AppComboBox.SelectedIndex = 3; } if (builder.Config.SystemSwitch.Enabled) { SystemComboBox.SelectedIndex = (int)builder.Config.SystemSwitch.Component.Mode; } else { SystemComboBox.SelectedIndex = 3; } if (builder.Config.OfficeSwitch.Enabled) { OfficeComboBox.SelectedIndex = (int)builder.Config.OfficeSwitch.Component.Mode; } else { OfficeComboBox.SelectedIndex = 3; } //checkbox if (builder.Config.OfficeSwitch.Component.LightTheme == 5) { CheckBoxOfficeWhiteTheme.IsChecked = true; } }
static void Main(string[] args) { try { //Set up Logger var config = new NLog.Config.LoggingConfiguration(); var configDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "AutoDarkMode"); // Targets where to log to: File and Console var logfile = new NLog.Targets.FileTarget("logfile") { FileName = Path.Combine(configDir, "service.log"), Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} | ${level} | " + "${callsite:includeNamespace=False:" + "cleanNamesOfAnonymousDelegates=true:" + "cleanNamesOfAsyncContinuations=true}: ${message} ${exception:separator=|}" }; var logconsole = new NLog.Targets.ColoredConsoleTarget("logconsole") { Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} | ${level} | " + "${callsite:includeNamespace=False:" + "cleanNamesOfAnonymousDelegates=true:" + "cleanNamesOfAsyncContinuations=true}: ${message} ${exception:separator=|}" }; List <string> argsList; if (args.Length > 0) { argsList = new List <string>(args); } else { argsList = new List <string>(); } // Rules for mapping loggers to targets config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole); if (argsList.Contains("/debug")) { config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); } else { config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile); } // Apply config LogManager.Configuration = config; try { Directory.CreateDirectory(configDir); } catch (Exception e) { Logger.Fatal(e, "could not create config directory"); } try { if (!mutex.WaitOne(TimeSpan.FromSeconds(2), false)) { Logger.Debug("app instance already open"); return; } } catch (Exception ex) { Logger.Error(ex, "failed getting mutex, " + ex.Message); return; } //Instantiate Runtime config GlobalState.Instance(); //Populate configuration AdmConfigBuilder Builder = AdmConfigBuilder.Instance(); try { Builder.Load(); Builder.LoadLocationData(); Logger.Debug("config builder instantiated and configuration loaded"); } catch (Exception e) { Logger.Fatal(e, "could not read config file. shutting down application!"); LogManager.Shutdown(); Environment.Exit(-1); } if (Builder.Config.Tunable.Debug && !argsList.Contains("/debug")) { config = new NLog.Config.LoggingConfiguration(); config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole); config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); LogManager.Configuration = config; } Logger.Debug("config file loaded"); //if a path is set to null, set it to the currently actvie theme for convenience reasons bool configUpdateNeeded = false; if (!Builder.Config.ClassicMode) { if (!File.Exists(Builder.Config.DarkThemePath) || Builder.Config.DarkThemePath == null) { Builder.Config.DarkThemePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\Windows\Themes", ThemeHandler.GetCurrentThemeName() + ".theme"); configUpdateNeeded = true; } if (!File.Exists(Builder.Config.DarkThemePath) || Builder.Config.LightThemePath == null) { Builder.Config.LightThemePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\Windows\Themes", ThemeHandler.GetCurrentThemeName() + ".theme"); configUpdateNeeded = true; } if (configUpdateNeeded) { Logger.Warn("one or more theme paths not set at program start, reinstantiation needed"); try { Builder.Save(); } catch (Exception ex) { Logger.Error(ex, "couldn't save configuration file"); } } } int timerMillis = 0; if (args.Length != 0) { int.TryParse(args[0], out timerMillis); } timerMillis = (timerMillis == 0) ? TimerFrequency.Short : timerMillis; Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Service = new Service(timerMillis); Application.Run(Service); } finally { //clean shutdown if (Service != null) { Service.Cleanup(); } mutex.Dispose(); } }
private void UiHandler() { try { builder.Load(); } catch (Exception ex) { ShowErrorMessage(ex); } //if a windows theme file was picked if (builder.Config.WindowsThemeMode.Enabled) { AccentColorCheckBox.IsEnabled = false; AccentColorCheckBox.ToolTip = AdmProperties.Resources.ToolTipDisabledDueTheme; TextBlockOfficeLabel.ToolTip = "Only use with Office 2013-2019 or if you experience issues with Office's 'use system' setting"; SystemComboBoxItemSwitch.ToolTip = AdmProperties.Resources.ToolTipDisabledDueTheme; SystemComboBoxItemLightOnly.ToolTip = AdmProperties.Resources.ToolTipDisabledDueTheme; SystemComboBoxItemLightOnly.IsEnabled = false; SystemComboBoxItemSwitch.IsEnabled = false; SystemComboBoxItemDarkOnly.IsEnabled = false; AppComboBox.IsEnabled = false; AppComboBox.ToolTip = AdmProperties.Resources.ToolTipDisabledDueTheme; NumberBoxColorDelay.IsEnabled = false; NumberBoxColorDelay.ToolTip = AdmProperties.Resources.ToolTipDisabledDueTheme; } if (builder.Config.SystemSwitch.Enabled) { switch (builder.Config.SystemSwitch.Component.Mode) { case Mode.Switch: if (builder.Config.WindowsThemeMode.Enabled) { SystemComboBox.SelectedItem = SystemComboBoxItemDisabled; } else { SystemComboBox.SelectedItem = SystemComboBoxItemSwitch; } break; case Mode.LightOnly: if (builder.Config.WindowsThemeMode.Enabled) { SystemComboBox.SelectedItem = SystemComboBoxItemDisabled; } else { SystemComboBox.SelectedItem = SystemComboBoxItemLightOnly; } break; case Mode.DarkOnly: if (builder.Config.WindowsThemeMode.Enabled) { SystemComboBox.SelectedItem = SystemComboBoxItemDisabled; } else { SystemComboBox.SelectedItem = SystemComboBoxItemDarkOnly; } break; case Mode.AccentOnly: SystemComboBox.SelectedItem = SystemComboBoxItemAccentOnly; break; } RadioButtonAdaptiveTaskbarAccentOnDark.IsChecked = builder.Config.SystemSwitch.Component.TaskbarColorWhenNonAdaptive == Theme.Dark; RadioButtonAdaptiveTaskbarAccentOnLight.IsChecked = builder.Config.SystemSwitch.Component.TaskbarColorWhenNonAdaptive == Theme.Light; } else { SystemComboBox.SelectedItem = SystemComboBoxItemDisabled; } //if the OS version is older than 1903 if (int.Parse(RegistryHandler.GetOSversion()).CompareTo(1900) > 0) { is1903 = true; } if (!is1903) { SystemComboBox.IsEnabled = false; SystemComboBox.ToolTip = AdmProperties.Resources.cmb1903; AccentColorCheckBox.IsEnabled = false; AccentColorCheckBox.ToolTip = AdmProperties.Resources.cmb1903; builder.Config.SystemSwitch.Enabled = false; try { builder.Save(); } catch (Exception ex) { ShowErrorMessage(ex); } } else //os version 1903+ { //inform user about settings if (!builder.Config.WindowsThemeMode.Enabled) { AccentColorCheckBox.ToolTip = AdmProperties.Resources.cbAccentColor; } //numbox NumberBoxColorDelay.Value = Convert.ToInt32(builder.Config.SystemSwitch.Component.TaskbarSwitchDelay); AccentColorCheckBox.IsChecked = builder.Config.SystemSwitch.Component.TaskbarColorOnAdaptive; SystemComboBox_SelectionChanged(null, null); } //combobox if (builder.Config.AppsSwitch.Enabled) { AppComboBox.SelectedIndex = (int)builder.Config.AppsSwitch.Component.Mode; } else { AppComboBox.SelectedIndex = 3; } if (builder.Config.OfficeSwitch.Enabled) { if (builder.Config.OfficeSwitch.Component.Mode == Mode.FollowSystemTheme) { OfficeComboBox.SelectedIndex = 3; CheckBoxOfficeWhiteTheme.IsEnabled = false; } else { OfficeComboBox.SelectedIndex = (int)builder.Config.OfficeSwitch.Component.Mode; } } else { OfficeComboBox.SelectedIndex = 4; } //checkbox if (builder.Config.OfficeSwitch.Component.LightTheme == 5) { CheckBoxOfficeWhiteTheme.IsChecked = true; } }