feat: pc restart

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-07-25 19:35:15 +08:00
parent 4d1d90a090
commit 461a87bce9
30 changed files with 198 additions and 11 deletions

View File

@@ -31,6 +31,8 @@ use std::sync::{
atomic::{AtomicI64, Ordering},
mpsc as std_mpsc,
};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use system_shutdown;
pub type Sender = mpsc::UnboundedSender<(Instant, Arc<Message>)>;
@@ -79,6 +81,7 @@ pub struct Connection {
clipboard: bool,
audio: bool,
file: bool,
restart: bool,
last_test_delay: i64,
lock_after_session_end: bool,
show_remote_cursor: bool, // by peer
@@ -166,6 +169,7 @@ impl Connection {
clipboard: Config::get_option("enable-clipboard").is_empty(),
audio: Config::get_option("enable-audio").is_empty(),
file: Config::get_option("enable-file-transfer").is_empty(),
restart: Config::get_option("enable-remote-restart").is_empty(),
last_test_delay: 0,
lock_after_session_end: false,
show_remote_cursor: false,
@@ -204,6 +208,9 @@ impl Connection {
if !conn.file {
conn.send_permission(Permission::File, false).await;
}
if !conn.restart {
conn.send_permission(Permission::Restart, false).await;
}
let mut test_delay_timer =
time::interval_at(Instant::now() + TEST_DELAY_TIMEOUT, TEST_DELAY_TIMEOUT);
let mut last_recv_time = Instant::now();
@@ -281,6 +288,9 @@ impl Connection {
conn.file = enabled;
conn.send_permission(Permission::File, enabled).await;
conn.send_to_cm(ipc::Data::ClipboardFileEnabled(conn.file_transfer_enabled()));
} else if &name == "restart" {
conn.restart = enabled;
conn.send_permission(Permission::Restart, enabled).await;
}
}
ipc::Data::RawMessage(bytes) => {
@@ -766,6 +776,7 @@ impl Connection {
audio: self.audio,
file: self.file,
file_transfer_enabled: self.file_transfer_enabled(),
restart: self.restart,
});
}
@@ -1208,6 +1219,17 @@ impl Connection {
SESSIONS.lock().unwrap().remove(&self.lr.my_id);
return false;
}
Some(misc::Union::RestartRemoteDevice(_)) =>
{
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.restart {
match system_shutdown::reboot() {
Ok(_) => log::info!("Restart by the peer"),
Err(e) => log::error!("Failed to restart:{}", e),
}
}
}
_ => {}
},
_ => {}