Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion control/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion control/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dynamiclight-control"
version = "1.0.3"
version = "1.0.4"
edition = "2021"
license = "MIT"
rust-version = "1.99"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dynamiclight",
"version": "1.0.3",
"version": "1.0.4",
"private": true,
"license": "MIT",
"author": "mskutin",
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dynamiclight"
version = "1.0.3"
version = "1.0.4"
description = "Local USB monitor backlight controller"
authors = ["mskutin"]
license = "MIT"
Expand Down
11 changes: 11 additions & 0 deletions src-tauri/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ impl Engine {
| SystemEvent::Locked(true)
| SystemEvent::DisplayOff(true)
| SystemEvent::Away(Away::OtherUser | Away::Remote)
| SystemEvent::Ending(true)
) {
self.extension = None;
self.external_cue = None;
Expand Down Expand Up @@ -597,6 +598,16 @@ impl Engine {
.close(self.life.pause_reason(&self.state.settings));
}
}
SystemEvent::Ending(ending) => {
if ending == self.life.ending {
return;
}
self.life.ending = ending;
if ending && self.state.settings.off_on_quit {
self.black();
self.controller.close("Computer shutting down");
}
}
SystemEvent::SourcesChanged => {
if self.state.capturing && self.state.settings.mode == "blend" {
self.lose_blend_source(true);
Expand Down
22 changes: 22 additions & 0 deletions src-tauri/src/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub enum SystemEvent {
/// Only Windows reports it.
#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
Away(Away),
/// Windows is about to end the session (shutdown, restart, sign-out); `false`
/// when something cancelled it. Only Windows reports it.
#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
Ending(bool),
SourcesChanged,
#[cfg(target_os = "linux")]
AudioChanged,
Expand Down Expand Up @@ -41,6 +45,7 @@ pub struct Lifecycle {
pub display_off: bool,
pub locked: bool,
pub away: Away,
pub ending: bool,
}
impl Lifecycle {
pub fn pause_reason(&self, s: &Settings) -> &'static str {
Expand All @@ -52,6 +57,8 @@ impl Lifecycle {
"Remote desktop session"
} else if self.away == Away::OtherUser {
"Another Windows user is active"
} else if self.ending && s.off_on_quit {
"Computer shutting down"
} else if self.locked && s.off_on_lock {
"Computer locked"
} else if self.display_off && s.off_on_display_sleep {
Expand Down Expand Up @@ -154,4 +161,19 @@ mod tests {
std::fs::write(&path, b"invalid").unwrap();
assert!(SavedIntent::load(&path).is_err());
}

#[test]
fn ending_session_pauses_only_when_the_strip_goes_off_on_quit() {
let mut life = Lifecycle {
requested: true,
..Default::default()
};
let mut s = Settings::default();
assert!(life.active(&s));
life.ending = true;
s.off_on_quit = true;
assert_eq!(life.pause_reason(&s), "Computer shutting down");
s.off_on_quit = false;
assert!(life.active(&s));
}
}
10 changes: 9 additions & 1 deletion src-tauri/src/lifecycle_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,18 @@ unsafe extern "system" fn window_proc(
WM_DISPLAYCHANGE => handle.system_event(SystemEvent::SourcesChanged, false),
// Windows shutdown/restart/sign-out: turn the strip off before the process is
// killed, otherwise USB power keeps the last frame lit.
WM_QUERYENDSESSION => return LRESULT(1),
// The strip goes dark already on the query: when the session really ends,
// tao's window calls exit(0) on its own WM_ENDSESSION at once, which would
// kill this process before the USB frame below is written.
WM_QUERYENDSESSION => {
handle.system_event(SystemEvent::Ending(true), true);
return LRESULT(1);
}
WM_ENDSESSION if wparam.0 != 0 => {
let _ = handle.request(crate::engine::Action::Shutdown);
}
// Something cancelled the shutdown: light up again.
WM_ENDSESSION => handle.system_event(SystemEvent::Ending(false), false),
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "DynamicLight",
"version": "1.0.3",
"version": "1.0.4",
"identifier": "com.dynamiclight.desktop",
"build": {
"frontendDist": "../src/ui"
Expand Down
Loading