Sitelet https://github.com/drcryo/Windows-Auto-Night-Mode/commit/34c7b287c3aa0d234a5265194dce5bf3c7ba910b
Skip to content

Commit 34c7b28

Browse files
committed
refactoring & finishing version 2.1
1 parent 2155602 commit 34c7b28

5 files changed

Lines changed: 98 additions & 33 deletions

File tree

‎AutoThemeChanger/App.xaml.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ protected override async void OnStartup(StartupEventArgs e)
3737
{
3838
RegEditHandler regEditHandler = new RegEditHandler();
3939
regEditHandler.SwitchThemeBasedOnTime();
40+
}else if (value == "/removeAutostart")
41+
{
42+
RegEditHandler regEditHandler = new RegEditHandler();
43+
regEditHandler.RemoveAutoStart();
4044
}
4145
}
4246
Shutdown();

‎AutoThemeChanger/MainWindow.xaml.cs‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private void AboutWindow_Closed(object sender, EventArgs e)
260260
}
261261
}
262262

263-
//applicatin close behaviour
263+
//application close behaviour
264264
private void Window_Closed(object sender, EventArgs e)
265265
{
266266
Properties.Settings.Default.Save();
@@ -390,26 +390,43 @@ private void SystemComboBox_DropDownClosed(object sender, EventArgs e)
390390
if (SystemComboBox.SelectedIndex.Equals(0))
391391
{
392392
Properties.Settings.Default.SystemThemeChange = 0;
393-
if (ThemeSettingDark) RegEditHandler.SystemTheme(0);
394-
if (!ThemeSettingDark) RegEditHandler.SystemTheme(1);
395-
if (Properties.Settings.Default.AccentColor)
393+
if (Properties.Settings.Default.AccentColor && !ThemeSettingDark)
394+
{
395+
RegEditHandler.ColorPrevalence(0);
396+
Thread.Sleep(500);
397+
RegEditHandler.SystemTheme(1);
398+
}
399+
if(Properties.Settings.Default.AccentColor && ThemeSettingDark)
396400
{
397-
if (ThemeSettingDark) RegEditHandler.ColorPrevalence(1);
398-
if (!ThemeSettingDark) RegEditHandler.ColorPrevalence(0);
401+
RegEditHandler.SystemTheme(0);
402+
Thread.Sleep(500);
403+
RegEditHandler.ColorPrevalence(1);
399404
}
405+
AccentColorCheckBox.IsEnabled = true;
400406
}
401407
if (SystemComboBox.SelectedIndex.Equals(1))
402408
{
403409
Properties.Settings.Default.SystemThemeChange = 1;
410+
if (Properties.Settings.Default.AccentColor)
411+
{
412+
RegEditHandler.ColorPrevalence(0);
413+
Thread.Sleep(500);
414+
}
404415
RegEditHandler.SystemTheme(1);
405-
if (Properties.Settings.Default.AccentColor) RegEditHandler.ColorPrevalence(0);
416+
AccentColorCheckBox.IsEnabled = false;
417+
AccentColorCheckBox.IsChecked = false;
406418
GetCurTheme();
407419
}
408420
if (SystemComboBox.SelectedIndex.Equals(2))
409421
{
410422
Properties.Settings.Default.SystemThemeChange = 2;
411423
RegEditHandler.SystemTheme(0);
412-
if (Properties.Settings.Default.AccentColor) RegEditHandler.ColorPrevalence(1);
424+
if (Properties.Settings.Default.AccentColor)
425+
{
426+
Thread.Sleep(500);
427+
RegEditHandler.ColorPrevalence(1);
428+
}
429+
AccentColorCheckBox.IsEnabled = true;
413430
GetCurTheme();
414431
}
415432
}

‎AutoThemeChanger/RegEditHandler.cs‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ public void SwitchThemeBasedOnTime()
2121
{
2222
ThemeToLight();
2323
MainWindow.ThemeSettingDark = false;
24-
Console.WriteLine("Theme to Light");
24+
//Console.WriteLine("Theme to Light");
2525
}
2626
if (minute >= darkStart[1])
2727
{
2828
ThemeToDark();
2929
MainWindow.ThemeSettingDark = true;
30-
Console.WriteLine("Theme to Dark");
30+
//Console.WriteLine("Theme to Dark");
3131
}
3232
}
3333
else
3434
{
3535
ThemeToDark();
3636
MainWindow.ThemeSettingDark = true;
37-
Console.WriteLine("Theme to Dark");
37+
//Console.WriteLine("Theme to Dark");
3838
}
3939
}
4040
else if (hour >= lightStart[0] || hour < darkStart[0])
@@ -45,20 +45,20 @@ public void SwitchThemeBasedOnTime()
4545
{
4646
ThemeToDark();
4747
MainWindow.ThemeSettingDark = true;
48-
Console.WriteLine("Theme to Dark");
48+
//Console.WriteLine("Theme to Dark");
4949
}
5050
if(minute >= lightStart[1])
5151
{
5252
ThemeToLight();
5353
MainWindow.ThemeSettingDark = false;
54-
Console.WriteLine("Theme to Light");
54+
//Console.WriteLine("Theme to Light");
5555
}
5656
}
5757
else
5858
{
5959
ThemeToLight();
6060
MainWindow.ThemeSettingDark = false;
61-
Console.WriteLine("Theme to Light");
61+
//Console.WriteLine("Theme to Light");
6262
}
6363
}
6464
}
@@ -68,15 +68,23 @@ public void ThemeToDark()
6868
if (Properties.Settings.Default.AppThemeChange.Equals(0)) AppTheme(0);
6969
if (Properties.Settings.Default.SystemThemeChange.Equals(0)) SystemTheme(0);
7070
if (Properties.Settings.Default.EdgeThemeChange.Equals(0)) EdgeTheme(1);
71-
if (Properties.Settings.Default.AccentColor && Properties.Settings.Default.SystemThemeChange.Equals(0)) ColorPrevalence(1);
71+
if (Properties.Settings.Default.AccentColor && Properties.Settings.Default.SystemThemeChange.Equals(0))
72+
{
73+
System.Threading.Thread.Sleep(1000);
74+
ColorPrevalence(1);
75+
}
7276
}
7377

7478
public void ThemeToLight()
7579
{
80+
if (Properties.Settings.Default.AccentColor && Properties.Settings.Default.SystemThemeChange.Equals(0))
81+
{
82+
ColorPrevalence(0);
83+
System.Threading.Thread.Sleep(1000);
84+
}
7685
if (Properties.Settings.Default.AppThemeChange.Equals(0)) AppTheme(1);
7786
if (Properties.Settings.Default.SystemThemeChange.Equals(0)) SystemTheme(1);
7887
if (Properties.Settings.Default.EdgeThemeChange.Equals(0)) EdgeTheme(0);
79-
if (Properties.Settings.Default.AccentColor && Properties.Settings.Default.SystemThemeChange.Equals(0)) ColorPrevalence(0);
8088
}
8189

8290
public void AppTheme(int theme)
@@ -139,14 +147,7 @@ public void AddAutoStart()
139147
public void RemoveAutoStart()
140148
{
141149
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
142-
try
143-
{
144-
registryKey.DeleteValue("AutoDarkMode");
145-
}
146-
catch
147-
{
148-
149-
}
150+
registryKey.DeleteValue("AutoDarkMode", false);
150151
}
151152
}
152-
}
153+
}

‎AutoThemeChanger/taskShedHandler.cs‎

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,46 @@ public void RemoveTask()
9797
using (TaskService taskService = new TaskService())
9898
{
9999
TaskFolder taskFolder = taskService.GetFolder(folder);
100-
taskFolder.DeleteTask(light, false);
101-
taskFolder.DeleteTask(dark, false);
102-
taskFolder.DeleteTask(hibernation, false);
103-
taskFolder.DeleteTask(updater, false);
104-
taskService.RootFolder.DeleteFolder(folder, false);
100+
try
101+
{
102+
taskFolder.DeleteTask(light, false);
103+
}
104+
catch
105+
{
106+
107+
}
108+
try
109+
{
110+
taskFolder.DeleteTask(dark, false);
111+
}
112+
catch
113+
{
114+
115+
}
116+
try
117+
{
118+
taskFolder.DeleteTask(hibernation, false);
119+
}
120+
catch
121+
{
122+
123+
}
124+
try
125+
{
126+
taskFolder.DeleteTask(updater, false);
127+
}
128+
catch
129+
{
130+
131+
}
132+
try
133+
{
134+
taskService.RootFolder.DeleteFolder(folder, false);
135+
}
136+
catch
137+
{
138+
139+
}
105140
}
106141
}
107142

@@ -110,7 +145,14 @@ public void RemoveLocationTask()
110145
using (TaskService taskService = new TaskService())
111146
{
112147
TaskFolder taskFolder = taskService.GetFolder(folder);
113-
taskFolder.DeleteTask(updater, false);
148+
try
149+
{
150+
taskFolder.DeleteTask(updater, false);
151+
}
152+
catch
153+
{
154+
155+
}
114156
}
115157
}
116158

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Windows 10 Auto-Night-Mode
2-
Automatically switches between the dark and light theme of Windows 10
1+
# Windows 10 Auto Dark Mode
2+
Automatically switches between the dark and light theme of Windows 10 at sheduled times
33
![Screenshot](https://github.com/Armin2208/Windows-Auto-Night-Mode/blob/master/screenshot.png)
44

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

2021
## Download

0 commit comments

Comments
 (0)