Skip to content

Commit

Permalink
refactoring & finishing version 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin2208 committed Mar 2, 2019
1 parent 2155602 commit 34c7b28
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 33 deletions.
4 changes: 4 additions & 0 deletions AutoThemeChanger/App.xaml.cs
Expand Up @@ -37,6 +37,10 @@ protected override async void OnStartup(StartupEventArgs e)
{
RegEditHandler regEditHandler = new RegEditHandler();
regEditHandler.SwitchThemeBasedOnTime();
}else if (value == "/removeAutostart")
{
RegEditHandler regEditHandler = new RegEditHandler();
regEditHandler.RemoveAutoStart();
}
}
Shutdown();
Expand Down
33 changes: 25 additions & 8 deletions AutoThemeChanger/MainWindow.xaml.cs
Expand Up @@ -260,7 +260,7 @@ private void AboutWindow_Closed(object sender, EventArgs e)
}
}

//applicatin close behaviour
//application close behaviour
private void Window_Closed(object sender, EventArgs e)
{
Properties.Settings.Default.Save();
Expand Down Expand Up @@ -390,26 +390,43 @@ private void SystemComboBox_DropDownClosed(object sender, EventArgs e)
if (SystemComboBox.SelectedIndex.Equals(0))
{
Properties.Settings.Default.SystemThemeChange = 0;
if (ThemeSettingDark) RegEditHandler.SystemTheme(0);
if (!ThemeSettingDark) RegEditHandler.SystemTheme(1);
if (Properties.Settings.Default.AccentColor)
if (Properties.Settings.Default.AccentColor && !ThemeSettingDark)
{
RegEditHandler.ColorPrevalence(0);
Thread.Sleep(500);
RegEditHandler.SystemTheme(1);
}
if(Properties.Settings.Default.AccentColor && ThemeSettingDark)
{
if (ThemeSettingDark) RegEditHandler.ColorPrevalence(1);
if (!ThemeSettingDark) RegEditHandler.ColorPrevalence(0);
RegEditHandler.SystemTheme(0);
Thread.Sleep(500);
RegEditHandler.ColorPrevalence(1);
}
AccentColorCheckBox.IsEnabled = true;
}
if (SystemComboBox.SelectedIndex.Equals(1))
{
Properties.Settings.Default.SystemThemeChange = 1;
if (Properties.Settings.Default.AccentColor)
{
RegEditHandler.ColorPrevalence(0);
Thread.Sleep(500);
}
RegEditHandler.SystemTheme(1);
if (Properties.Settings.Default.AccentColor) RegEditHandler.ColorPrevalence(0);
AccentColorCheckBox.IsEnabled = false;
AccentColorCheckBox.IsChecked = false;
GetCurTheme();
}
if (SystemComboBox.SelectedIndex.Equals(2))
{
Properties.Settings.Default.SystemThemeChange = 2;
RegEditHandler.SystemTheme(0);
if (Properties.Settings.Default.AccentColor) RegEditHandler.ColorPrevalence(1);
if (Properties.Settings.Default.AccentColor)
{
Thread.Sleep(500);
RegEditHandler.ColorPrevalence(1);
}
AccentColorCheckBox.IsEnabled = true;
GetCurTheme();
}
}
Expand Down
35 changes: 18 additions & 17 deletions AutoThemeChanger/RegEditHandler.cs
Expand Up @@ -21,20 +21,20 @@ public void SwitchThemeBasedOnTime()
{
ThemeToLight();
MainWindow.ThemeSettingDark = false;
Console.WriteLine("Theme to Light");
//Console.WriteLine("Theme to Light");
}
if (minute >= darkStart[1])
{
ThemeToDark();
MainWindow.ThemeSettingDark = true;
Console.WriteLine("Theme to Dark");
//Console.WriteLine("Theme to Dark");
}
}
else
{
ThemeToDark();
MainWindow.ThemeSettingDark = true;
Console.WriteLine("Theme to Dark");
//Console.WriteLine("Theme to Dark");
}
}
else if (hour >= lightStart[0] || hour < darkStart[0])
Expand All @@ -45,20 +45,20 @@ public void SwitchThemeBasedOnTime()
{
ThemeToDark();
MainWindow.ThemeSettingDark = true;
Console.WriteLine("Theme to Dark");
//Console.WriteLine("Theme to Dark");
}
if(minute >= lightStart[1])
{
ThemeToLight();
MainWindow.ThemeSettingDark = false;
Console.WriteLine("Theme to Light");
//Console.WriteLine("Theme to Light");
}
}
else
{
ThemeToLight();
MainWindow.ThemeSettingDark = false;
Console.WriteLine("Theme to Light");
//Console.WriteLine("Theme to Light");
}
}
}
Expand All @@ -68,15 +68,23 @@ public void ThemeToDark()
if (Properties.Settings.Default.AppThemeChange.Equals(0)) AppTheme(0);
if (Properties.Settings.Default.SystemThemeChange.Equals(0)) SystemTheme(0);
if (Properties.Settings.Default.EdgeThemeChange.Equals(0)) EdgeTheme(1);
if (Properties.Settings.Default.AccentColor && Properties.Settings.Default.SystemThemeChange.Equals(0)) ColorPrevalence(1);
if (Properties.Settings.Default.AccentColor && Properties.Settings.Default.SystemThemeChange.Equals(0))
{
System.Threading.Thread.Sleep(1000);
ColorPrevalence(1);
}
}

public void ThemeToLight()
{
if (Properties.Settings.Default.AccentColor && Properties.Settings.Default.SystemThemeChange.Equals(0))
{
ColorPrevalence(0);
System.Threading.Thread.Sleep(1000);
}
if (Properties.Settings.Default.AppThemeChange.Equals(0)) AppTheme(1);
if (Properties.Settings.Default.SystemThemeChange.Equals(0)) SystemTheme(1);
if (Properties.Settings.Default.EdgeThemeChange.Equals(0)) EdgeTheme(0);
if (Properties.Settings.Default.AccentColor && Properties.Settings.Default.SystemThemeChange.Equals(0)) ColorPrevalence(0);
}

public void AppTheme(int theme)
Expand Down Expand Up @@ -139,14 +147,7 @@ public void AddAutoStart()
public void RemoveAutoStart()
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
try
{
registryKey.DeleteValue("AutoDarkMode");
}
catch
{

}
registryKey.DeleteValue("AutoDarkMode", false);
}
}
}
}
54 changes: 48 additions & 6 deletions AutoThemeChanger/taskShedHandler.cs
Expand Up @@ -97,11 +97,46 @@ public void RemoveTask()
using (TaskService taskService = new TaskService())
{
TaskFolder taskFolder = taskService.GetFolder(folder);
taskFolder.DeleteTask(light, false);
taskFolder.DeleteTask(dark, false);
taskFolder.DeleteTask(hibernation, false);
taskFolder.DeleteTask(updater, false);
taskService.RootFolder.DeleteFolder(folder, false);
try
{
taskFolder.DeleteTask(light, false);
}
catch
{

}
try
{
taskFolder.DeleteTask(dark, false);
}
catch
{

}
try
{
taskFolder.DeleteTask(hibernation, false);
}
catch
{

}
try
{
taskFolder.DeleteTask(updater, false);
}
catch
{

}
try
{
taskService.RootFolder.DeleteFolder(folder, false);
}
catch
{

}
}
}

Expand All @@ -110,7 +145,14 @@ public void RemoveLocationTask()
using (TaskService taskService = new TaskService())
{
TaskFolder taskFolder = taskService.GetFolder(folder);
taskFolder.DeleteTask(updater, false);
try
{
taskFolder.DeleteTask(updater, false);
}
catch
{

}
}
}

Expand Down
5 changes: 3 additions & 2 deletions README.md
@@ -1,5 +1,5 @@
# Windows 10 Auto-Night-Mode
Automatically switches between the dark and light theme of Windows 10
# Windows 10 Auto Dark Mode
Automatically switches between the dark and light theme of Windows 10 at sheduled times
![Screenshot](https://github.com/Armin2208/Windows-Auto-Night-Mode/blob/master/screenshot.png)

## Description
Expand All @@ -15,6 +15,7 @@ With enabling the automatic theme switcher in the app, it creates a task in the
- Theme switch based on the sunrise and sunset of your location.
- Easy theme switch with a Jump-List from the Startmenu or Taskbar.
- You can choose if only Apps should change their theme, or both apps and the system.
- Support for Accent Color on the Taskbar and system elements.
- Lightweight with 100% clean uninstall. No admin-rights needed.

## Download
Expand Down

0 comments on commit 34c7b28

Please sign in to comment.