mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-05 14:11:27 +03:00
fix windows wakelock, add set_display (#6623)
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -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"))?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user