switch sides

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-01-17 13:28:33 +08:00
parent 45c0e10102
commit 333092f983
49 changed files with 373 additions and 61 deletions

View File

@@ -48,6 +48,7 @@ pub struct Client {
pub file: bool,
pub restart: bool,
pub recording: bool,
pub from_switch: bool,
#[serde(skip)]
tx: UnboundedSender<Data>,
}
@@ -118,6 +119,7 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
file: bool,
restart: bool,
recording: bool,
from_switch: bool,
tx: mpsc::UnboundedSender<Data>,
) {
let client = Client {
@@ -134,6 +136,7 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
file,
restart,
recording,
from_switch,
tx,
};
CLIENTS
@@ -241,6 +244,14 @@ pub fn get_clients_length() -> usize {
clients.len()
}
#[inline]
#[cfg(feature = "flutter")]
pub fn switch_back(id: i32) {
if let Some(client) = CLIENTS.read().unwrap().get(&id) {
allow_err!(client.tx.send(Data::SwitchBack));
};
}
impl<T: InvokeUiCM> IpcTaskRunner<T> {
#[cfg(windows)]
async fn enable_cliprdr_file_context(&mut self, conn_id: i32, enabled: bool) {
@@ -308,9 +319,9 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
}
Ok(Some(data)) => {
match data {
Data::Login{id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, file_transfer_enabled: _file_transfer_enabled, restart, recording} => {
Data::Login{id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, file_transfer_enabled: _file_transfer_enabled, restart, recording, from_switch} => {
log::debug!("conn_id: {}", id);
self.cm.add_connection(id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, restart, recording, self.tx.clone());
self.cm.add_connection(id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, restart, recording, from_switch,self.tx.clone());
self.authorized = authorized;
self.conn_id = id;
#[cfg(windows)]
@@ -498,6 +509,7 @@ pub async fn start_listen<T: InvokeUiCM>(
file,
restart,
recording,
from_switch,
..
}) => {
current_id = id;
@@ -514,6 +526,7 @@ pub async fn start_listen<T: InvokeUiCM>(
file,
restart,
recording,
from_switch,
tx.clone(),
);
}