Skip to content

Commit fd4c4b6

Browse files
committed
fix: normalize night light state marker
1 parent eb3f1ac commit fd4c4b6

4 files changed

Lines changed: 49 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wnlctl"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2024"
55
license = "MIT"
66
description = "Windows Night Light control CLI"

RELEASING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
Maintainer notes for publishing a new `wnlctl` release.
44

5+
## Codex Shortcut
6+
7+
For the usual patch release flow, tell Codex:
8+
9+
```text
10+
wnlctl 패치 릴리스 진행해줘. 버전 bump, 검증, 커밋, 태그, 푸시,
11+
scoop-bucket workflow 실행, 로컬 scoop 업데이트까지 해줘.
12+
```
13+
514
## Manual Release
615

716
1. Update the package version in `Cargo.toml`.

vendor/win-nightlight-lib/src/nightlight_state.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl NightlightState {
3434
reader.read_marshaled_header()?;
3535

3636
let mut is_enabled = false;
37-
let mut initialized: i32 = 0;
37+
let mut initialized: i32 = 1;
3838
let mut last_transition_filetime: u64 = 0;
3939

4040
loop {
@@ -105,26 +105,30 @@ impl NightlightState {
105105
+ u64::from(now.timestamp_subsec_nanos() / 100);
106106
}
107107

108-
/// Enables the nightlight and updates the timestamp.
109-
/// Returns true if a change was made (i.e. the nightlight was previously disabled).
110-
pub fn enable(&mut self) -> bool {
111-
if self.is_enabled {
108+
fn set_enabled(&mut self, is_enabled: bool) -> bool {
109+
let state_changed = self.is_enabled != is_enabled;
110+
let marker_changed = self.initialized != 1;
111+
112+
if !state_changed && !marker_changed {
112113
return false;
113114
}
114-
self.is_enabled = true;
115+
116+
self.is_enabled = is_enabled;
117+
self.initialized = 1;
115118
self.update_transition_timestamps();
116119
true
117120
}
118121

122+
/// Enables the nightlight and updates the timestamp.
123+
/// Returns true if a change was made.
124+
pub fn enable(&mut self) -> bool {
125+
self.set_enabled(true)
126+
}
127+
119128
/// Disables the nightlight and updates the timestamp.
120-
/// Returns true if a change was made (i.e. the nightlight was previously enabled).
129+
/// Returns true if a change was made.
121130
pub fn disable(&mut self) -> bool {
122-
if !self.is_enabled {
123-
return false;
124-
}
125-
self.is_enabled = false;
126-
self.update_transition_timestamps();
127-
true
131+
self.set_enabled(false)
128132
}
129133
}
130134

@@ -194,4 +198,25 @@ mod tests {
194198
let state_deserialized = NightlightState::deserialize_from_bytes(&bytes).unwrap();
195199
assert_eq!(state_deserialized, state_enabled);
196200
}
201+
202+
#[test]
203+
fn state_changes_normalize_initialized_marker() {
204+
let mut state = NightlightState {
205+
timestamp: 0,
206+
is_enabled: false,
207+
initialized: 0,
208+
last_transition_filetime: 0,
209+
};
210+
211+
assert!(state.enable());
212+
assert_eq!(state.initialized, 1);
213+
214+
state.initialized = 0;
215+
assert!(state.disable());
216+
assert_eq!(state.initialized, 1);
217+
218+
state.initialized = 0;
219+
assert!(state.disable());
220+
assert_eq!(state.initialized, 1);
221+
}
197222
}

0 commit comments

Comments
 (0)