Skip to content

Commit 32cc787

Browse files
committed
Fix a deadlock when setting timers <30s before even hours
1 parent d2c8f31 commit 32cc787

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This application allows you to automatically switch between light and dark mode
44

55
## Installation
66

7-
* Download it here: https://github.com/lhecker/windows-dark-mode-switcher/releases/tag/v0.1.2
7+
* Download it here: https://github.com/lhecker/windows-dark-mode-switcher/releases/tag/v0.1.3
88
* Unzip the archive
99
* Put `dark-mode-switcher.exe` into this directory:
1010
```

src/resource.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ BEGIN
147147
BEGIN
148148
VALUE "CompanyName", "Leonard Hecker <leonard@hecker.io>"
149149
VALUE "FileDescription", "https://github.com/lhecker/windows-dark-mode-switcher/"
150-
VALUE "FileVersion", "0.1.2.0"
150+
VALUE "FileVersion", "0.1.3.0"
151151
VALUE "LegalCopyright", "MIT License"
152152
VALUE "ProductName", "Dark Mode Switcher"
153-
VALUE "ProductVersion", "0.1.2.0"
153+
VALUE "ProductVersion", "0.1.3.0"
154154
END
155155
END
156156
BLOCK "VarFileInfo"

src/suncourse.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,15 @@ bool suncourse_is_daytime(float lat, float lon, FILETIME_QUAD* next_update)
6464

6565
// If it's daytime, the next change is the sunset and vice versa.
6666
double next_h = is_daytime ? ss.sunset : ss.sunrise;
67+
// Add 24 hours, because next_h may be negative.
6768
// Add 30 seconds as wiggle room for the timer.
68-
next_h += 30.0 / 3600.0;
69-
// Ensure it's [0, 24).
70-
next_h = fmod(next_h + 24.0, 24.0);
71-
72-
double hours;
73-
double minutes = modf(next_h, &hours) * 60;
69+
long next_min = lround(next_h * 60.0 + 24.0 * 60.0 + 0.5);
70+
// Ensure it's [0, 24) hours.
71+
next_min = next_min % 1440;
7472

7573
SYSTEMTIME next_st = now_st;
76-
next_st.wHour = (WORD)lround(hours);
77-
next_st.wMinute = (WORD)lround(minutes);
74+
next_st.wHour = (WORD)(next_min / 60);
75+
next_st.wMinute = (WORD)(next_min % 60);
7876
next_st.wSecond = 0;
7977
next_st.wMilliseconds = 0;
8078

0 commit comments

Comments
 (0)