hematite/ui/
sleep_inhibitor.rs1#[cfg(target_os = "windows")]
11mod imp {
12 const ES_CONTINUOUS: u32 = 0x80000000;
13 const ES_SYSTEM_REQUIRED: u32 = 0x00000001;
14
15 #[link(name = "kernel32")]
16 extern "system" {
17 fn SetThreadExecutionState(esFlags: u32) -> u32;
18 }
19
20 pub struct SleepInhibitor;
21
22 impl SleepInhibitor {
23 pub fn acquire() -> Self {
24 unsafe {
25 SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
26 }
27 Self
28 }
29 }
30
31 impl Drop for SleepInhibitor {
32 fn drop(&mut self) {
33 unsafe {
34 SetThreadExecutionState(ES_CONTINUOUS);
35 }
36 }
37 }
38}
39
40#[cfg(not(target_os = "windows"))]
41mod imp {
42 pub struct SleepInhibitor;
43 impl SleepInhibitor {
44 pub fn acquire() -> Self {
45 Self
46 }
47 }
48}
49
50pub use imp::SleepInhibitor;