mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-17 18:21:02 +03:00
keep-awake-during-incoming-sessions (#14082)
* keep-awake-during-incoming-sessions * Update flutter/lib/desktop/pages/desktop_setting_page.dart Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update flutter/lib/common.dart Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update flutter/lib/mobile/pages/settings_page.dart Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update common.dart * wakelock Signed-off-by: 21pages <sunboeasy@gmail.com> * fix build Signed-off-by: 21pages <sunboeasy@gmail.com> * Update server_model.dart --------- Signed-off-by: 21pages <sunboeasy@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
@@ -74,6 +74,7 @@ lazy_static::lazy_static! {
|
||||
pub static ref CONTROL_PERMISSIONS_ARRAY: Arc::<Mutex<Vec<(i32, ControlPermissions)>>> = Default::default();
|
||||
static ref SWITCH_SIDES_UUID: Arc::<Mutex<HashMap<String, (Instant, uuid::Uuid)>>> = Default::default();
|
||||
static ref WAKELOCK_SENDER: Arc::<Mutex<std::sync::mpsc::Sender<(usize, usize)>>> = Arc::new(Mutex::new(start_wakelock_thread()));
|
||||
static ref WAKELOCK_KEEP_AWAKE_OPTION: Arc::<Mutex<Option<bool>>> = Default::default();
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
@@ -906,6 +907,7 @@ impl Connection {
|
||||
_ = second_timer.tick() => {
|
||||
#[cfg(windows)]
|
||||
conn.portable_check();
|
||||
raii::AuthedConnID::check_wake_lock_on_setting_changed();
|
||||
if let Some((instant, minute)) = conn.auto_disconnect_timer.as_ref() {
|
||||
if instant.elapsed().as_secs() > minute * 60 {
|
||||
conn.send_close_reason_no_retry("Connection failed due to inactivity").await;
|
||||
@@ -5008,6 +5010,7 @@ impl FileRemoveLogControl {
|
||||
}
|
||||
|
||||
fn start_wakelock_thread() -> std::sync::mpsc::Sender<(usize, usize)> {
|
||||
// Check if we should keep awake during incoming sessions
|
||||
use crate::platform::{get_wakelock, WakeLock};
|
||||
let (tx, rx) = std::sync::mpsc::channel::<(usize, usize)>();
|
||||
std::thread::spawn(move || {
|
||||
@@ -5016,9 +5019,15 @@ fn start_wakelock_thread() -> std::sync::mpsc::Sender<(usize, usize)> {
|
||||
loop {
|
||||
match rx.recv() {
|
||||
Ok((conn_count, remote_count)) => {
|
||||
if conn_count == 0 {
|
||||
wakelock = None;
|
||||
log::info!("drop wakelock");
|
||||
let keep_awake = config::Config::get_bool_option(
|
||||
keys::OPTION_KEEP_AWAKE_DURING_INCOMING_SESSIONS,
|
||||
);
|
||||
*WAKELOCK_KEEP_AWAKE_OPTION.lock().unwrap() = Some(keep_awake);
|
||||
if conn_count == 0 || !keep_awake {
|
||||
if wakelock.is_some() {
|
||||
wakelock = None;
|
||||
log::info!("drop wakelock");
|
||||
}
|
||||
} else {
|
||||
let mut display = remote_count > 0;
|
||||
if let Some(_w) = wakelock.as_mut() {
|
||||
@@ -5329,6 +5338,16 @@ mod raii {
|
||||
.send((conn_count, remote_count)));
|
||||
}
|
||||
|
||||
pub fn check_wake_lock_on_setting_changed() {
|
||||
let current = config::Config::get_bool_option(
|
||||
keys::OPTION_KEEP_AWAKE_DURING_INCOMING_SESSIONS,
|
||||
);
|
||||
let cached = *WAKELOCK_KEEP_AWAKE_OPTION.lock().unwrap();
|
||||
if cached != Some(current) {
|
||||
Self::check_wake_lock();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn non_port_forward_conn_count() -> usize {
|
||||
AUTHED_CONNS
|
||||
|
||||
Reference in New Issue
Block a user