fix windows wakelock, add set_display (#6623)

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-12-05 08:32:44 -05:00
committed by GitHub
parent 00fe3a76c8
commit 50b81c2356
5 changed files with 75 additions and 21 deletions

View File

@@ -733,4 +733,11 @@ impl WakeLock {
.ok(),
)
}
pub fn set_display(&mut self, display: bool) -> ResultType<()> {
self.0
.as_mut()
.map(|h| h.set_display(display))
.ok_or(anyhow!("no AwakeHandle"))?
}
}

View File

@@ -98,7 +98,7 @@ impl WakeLock {
}
}
pub fn get_wake_lock(_display: bool) -> WakeLock {
pub fn get_wakelock(_display: bool) -> WakeLock {
hbb_common::log::info!("new wakelock, require display on: {_display}");
#[cfg(target_os = "android")]
return crate::platform::WakeLock::new("server");

View File

@@ -2109,7 +2109,7 @@ pub fn is_process_consent_running() -> ResultType<bool> {
.output()?;
Ok(output.status.success() && !output.stdout.is_empty())
}
pub struct WakeLock;
pub struct WakeLock(u32);
// Failed to compile keepawake-rs on i686
impl WakeLock {
pub fn new(display: bool, idle: bool, sleep: bool) -> Self {
@@ -2124,7 +2124,20 @@ impl WakeLock {
flag |= ES_AWAYMODE_REQUIRED;
}
unsafe { SetThreadExecutionState(flag) };
WakeLock {}
WakeLock(flag)
}
pub fn set_display(&mut self, display: bool) -> ResultType<()> {
let flag = if display {
self.0 | ES_DISPLAY_REQUIRED
} else {
self.0 & !ES_DISPLAY_REQUIRED
};
if flag != self.0 {
unsafe { SetThreadExecutionState(flag) };
self.0 = flag;
}
Ok(())
}
}