Initial
Rust validation / Formatting (push) Failing after 27s
EonaCat/ci-workflows: SonarQube / sonar (push) Successful in 45s
Rust validation / Windows x64 build and tests (push) Canceled after 0s

This commit is contained in:
EonaCat committed 2026-12-04 21:08:34 +01:00
1 parent 2cff35f215
commit 0f7377a1b5
359 files changed
+253980 -74

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
pub fn asked() -> bool {
asked_for(std::env::var("EONACAT_XS_KEEP_AWAKE").ok().as_deref())
}
fn asked_for(value: Option<&str>) -> bool {
value != Some("0")
}
#[cfg(windows)]
#[must_use = "the request is let go as soon as the guard is dropped"]
pub struct Awake {
request: *mut std::ffi::c_void,
}
#[cfg(not(windows))]
#[must_use = "the request is let go as soon as the guard is dropped"]
pub struct Awake;
#[cfg(windows)]
pub fn hold() -> Option<Awake> {
use windows_sys::Win32::Foundation::CloseHandle;
use windows_sys::Win32::System::Power::{
PowerCreateRequest, PowerRequestDisplayRequired, PowerRequestSystemRequired,
PowerSetRequest,
};
use windows_sys::Win32::System::Threading::{
POWER_REQUEST_CONTEXT_SIMPLE_STRING, REASON_CONTEXT,
};
let mut reason: Vec<u16> = "eonacat-xs: the title is running\0".encode_utf16().collect();
let mut context = REASON_CONTEXT {
Flags: POWER_REQUEST_CONTEXT_SIMPLE_STRING,
..Default::default()
};
context.Reason.SimpleReasonString = reason.as_mut_ptr();
let request = unsafe { PowerCreateRequest(&context) };
if request.is_null() || request as isize == -1 {
tracing::info!("the screen's power request was not created");
return None;
}
for flag in [PowerRequestDisplayRequired, PowerRequestSystemRequired] {
if unsafe { PowerSetRequest(request, flag) } == 0 {
tracing::info!(flag, "the screen's power request was refused");
unsafe {
windows_sys::Win32::System::Power::PowerClearRequest(
request,
PowerRequestDisplayRequired,
);
CloseHandle(request);
}
return None;
}
}
Some(Awake { request })
}
#[cfg(not(windows))]
pub fn hold() -> Option<Awake> {
None
}
#[cfg(windows)]
impl Drop for Awake {
fn drop(&mut self) {
use windows_sys::Win32::Foundation::CloseHandle;
use windows_sys::Win32::System::Power::{
PowerClearRequest, PowerRequestDisplayRequired, PowerRequestSystemRequired,
};
unsafe {
for flag in [PowerRequestDisplayRequired, PowerRequestSystemRequired] {
PowerClearRequest(self.request, flag);
}
CloseHandle(self.request);
}
}
}