public PageApps() { builder.Load(); InitializeComponent(); UiHandler(); //follow windows theme ThemeChange(this, null); SourceChord.FluentWPF.SystemTheme.ThemeChanged += ThemeChange; }
public PageWallpaperPicker() { try { builder.Load(); } catch (Exception ex) { ShowErrorMessage(ex, "builder.Load at PageWallpaperPicker"); } InitializeComponent(); }
private void OnChangedConfig(object source, FileSystemEventArgs e) { _ = state.ConfigIsUpdatingWaitHandle.Reset(); state.ConfigIsUpdating = true; if (state.SkipConfigFileReload) { state.SkipConfigFileReload = false; Logger.Debug("skipping config file reload, update source internal"); return; } try { AdmConfig oldConfig = builder.Config; builder.Load(); componentManager.UpdateSettings(); UpdateEventStates(); builder.OnConfigUpdated(oldConfig); // fire warden ro register/unregister enabled/disabled modules if (warden != null) { warden.Fire(); } Logger.Debug("updated configuration file"); } catch (Exception ex) { Logger.Debug(ex, "config file load failed:"); } state.ConfigIsUpdating = false; if (!state.ConfigIsUpdatingWaitHandle.Set()) { Logger.Fatal("could not trigger reset event"); } }
public PagePersonalization() { try { builder.Load(); } catch (Exception ex) { ShowErrorMessage("error loading config", ex); } InitializeComponent(); if (builder.Config.WindowsThemeMode.Enabled & !builder.Config.WallpaperSwitch.Enabled) { SetThemePickerEnabled(); } if (builder.Config.WallpaperSwitch.Enabled & !builder.Config.WindowsThemeMode.Enabled) { SetWallpaperPickerEnabled(); } if (!builder.Config.WallpaperSwitch.Enabled & !builder.Config.WindowsThemeMode.Enabled) { WallpaperDisabledMessage.Visibility = Visibility.Collapsed; ThemeDisabledMessage.Visibility = Visibility.Collapsed; } }
public PageSettings() { try { builder.Load(); } catch (Exception ex) { ShowErrorMessage(ex); } InitializeComponent(); UiHandler(); }
public PageWallpaper() { try { builder.Load(); } catch (Exception ex) { ShowErrorMessage("couldn't init config file", ex); } InitializeComponent(); UiHandler(); }
public PageThemePicker() { try { builder.Load(); } catch (Exception ex) { ShowErrorMessage(ex, "PageThemePicker - couldn't init config file"); } InitializeComponent(); UiHandler(); init = false; }
private static void EnsureAutostart() { try { AdmConfigBuilder builder = AdmConfigBuilder.Instance(); builder.Load(); if (builder.Config.AutoThemeSwitchingEnabled) { ICommandClient client = new ZeroMQClient(Address.DefaultPort); _ = client.SendMessageAndGetReply(Command.AddAutostart); } } catch (Exception ex) { Trace.WriteLine(ex); } }
public PageTime() { try { builder.Load(); builder.LoadLocationData(); } catch (Exception ex) { ShowErrorMessage(ex); } InitializeComponent(); if (builder.Config.AutoThemeSwitchingEnabled) { autoCheckBox.IsChecked = true; } if (builder.Config.Location.Enabled) { ActivateLocationMode(); RadioButtonLocationTimes.IsChecked = true; } else { applyButton.IsEnabled = false; if (Properties.Settings.Default.AlterTime) { darkStartBox.Text = builder.Config.Sunset.ToString("hh", CultureInfo.InvariantCulture); lightStartBox.Text = builder.Config.Sunrise.ToString("hh", CultureInfo.InvariantCulture); } else { darkStartBox.Text = builder.Config.Sunset.ToString("HH", CultureInfo.InvariantCulture); lightStartBox.Text = builder.Config.Sunrise.ToString("HH", CultureInfo.InvariantCulture); } DarkStartMinutesBox.Text = builder.Config.Sunset.ToString("mm", CultureInfo.InvariantCulture); LightStartMinutesBox.Text = builder.Config.Sunrise.ToString("mm", CultureInfo.InvariantCulture); } InitOffset(); if (Settings.Default.AlterTime) { AlterTime(true); } init = false; }
public PageTime() { //read config file try { builder.Load(); builder.LoadLocationData(); } catch (Exception ex) { ShowErrorMessage(ex); } //initialize ui components InitializeComponent(); //enable 12 hour clock: if (Properties.Settings.Default.AlterTime) { TimePickerDark.Culture = CultureInfo.CreateSpecificCulture("en"); TimePickerLight.Culture = CultureInfo.CreateSpecificCulture("en"); } //enable 24 hour clock: else { TimePickerDark.Culture = CultureInfo.CreateSpecificCulture("de"); TimePickerLight.Culture = CultureInfo.CreateSpecificCulture("de"); } //read datetime from config file TimePickerDark.SelectedDateTime = builder.Config.Sunset; TimePickerLight.SelectedDateTime = builder.Config.Sunrise; //read offset from config file NumberBoxOffsetLight.Value = Convert.ToDouble(builder.Config.Location.SunriseOffsetMin); NumberboxOffsetDark.Value = Convert.ToDouble(builder.Config.Location.SunsetOffsetMin); //read coordinates from config file NumberBoxLat.Text = builder.Config.Location.CustomLat.ToString(); NumberBoxLon.Text = builder.Config.Location.CustomLon.ToString(); //tick correct radio button and prepare UI //is auto theme switch enabled? //disabled if (!builder.Config.AutoThemeSwitchingEnabled) { DisableTimeBasedSwitch(); TogglePanelVisibility(true, false, false, false); RadioButtonDisabled.IsChecked = true; } //enabled else { //is custom timepicker input enabled? if (!builder.Config.Location.Enabled) { RadioButtonCustomTimes.IsChecked = true; TogglePanelVisibility(true, false, false, false); applyButton.IsEnabled = false; } //is location mode enabled? if (builder.Config.Location.Enabled) { //windows location service if (builder.Config.Location.UseGeolocatorService) { TogglePanelVisibility(false, true, true, false); ActivateLocationModeWrapper(); RadioButtonLocationTimes.IsChecked = true; } //custom geographic coordinates else { RadioButtonCoordinateTimes.IsChecked = true; TogglePanelVisibility(false, true, true, true); ActivateLocationModeWrapper(); } } } init = false; }
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; } }