mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
wake lock for all connection type
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -82,35 +82,28 @@ pub const PA_SAMPLE_RATE: u32 = 48000;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
#[derive(Default)]
|
||||
pub struct WakeLock {
|
||||
lock: Option<android_wakelock::WakeLock>,
|
||||
}
|
||||
pub struct WakeLock(Option<android_wakelock::WakeLock>);
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
impl WakeLock {
|
||||
pub fn new(tag: &str) -> Self {
|
||||
let tag = format!("{}:{tag}", crate::get_app_name());
|
||||
match android_wakelock::partial(tag) {
|
||||
Ok(lock) => Self { lock: Some(lock) },
|
||||
Ok(lock) => Self(Some(lock)),
|
||||
Err(e) => {
|
||||
hbb_common::log::error!("Failed to get wakelock: {e:?}");
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn acquire(&self) -> Option<android_wakelock::Guard> {
|
||||
match self.lock.as_ref() {
|
||||
Some(lock) => match lock.acquire() {
|
||||
Ok(guard) => Some(guard),
|
||||
Err(e) => {
|
||||
hbb_common::log::error!("Failed to acquire wakelock guard: {e:?}");
|
||||
None
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
pub fn get_wake_lock(_display: bool) -> WakeLock {
|
||||
hbb_common::log::info!("new wakelock, require display on: {_display}");
|
||||
#[cfg(target_os = "android")]
|
||||
return crate::platform::WakeLock::new("server");
|
||||
#[cfg(not(target_os = "android"))]
|
||||
return crate::platform::WakeLock::new(_display, true, true);
|
||||
}
|
||||
|
||||
pub(crate) struct InstallingService; // please use new
|
||||
|
||||
Reference in New Issue
Block a user