fix conflicts

This commit is contained in:
Asur4s
2023-01-12 00:35:39 +08:00
244 changed files with 8727 additions and 3173 deletions

View File

@@ -1,8 +1,8 @@
use crate::client::io_loop::Remote;
use crate::client::{
check_if_retry, handle_hash, handle_login_from_ui, handle_test_delay, input_os_password,
load_config, send_mouse, start_video_audio_threads, FileManager, Key, LoginConfigHandler,
QualityStatus, KEY_MAP,
check_if_retry, handle_hash, handle_login_error, handle_login_from_ui, handle_test_delay,
input_os_password, load_config, send_mouse, start_video_audio_threads, FileManager, Key,
LoginConfigHandler, QualityStatus, KEY_MAP,
};
use crate::common::{self, is_keyboard_mode_supported, GrabState};
use crate::keyboard;
@@ -32,6 +32,32 @@ pub struct Session<T: InvokeUiSession> {
}
impl<T: InvokeUiSession> Session<T> {
pub fn is_file_transfer(&self) -> bool {
self.lc
.read()
.unwrap()
.conn_type
.eq(&ConnType::FILE_TRANSFER)
}
pub fn is_port_forward(&self) -> bool {
self.lc
.read()
.unwrap()
.conn_type
.eq(&ConnType::PORT_FORWARD)
}
pub fn is_rdp(&self) -> bool {
self.lc.read().unwrap().conn_type.eq(&ConnType::RDP)
}
pub fn set_connection_info(&mut self, direct: bool, received: bool) {
let mut lc = self.lc.write().unwrap();
lc.direct = Some(direct);
lc.received = received;
}
pub fn get_view_style(&self) -> String {
self.lc.read().unwrap().view_style.clone()
}
@@ -177,7 +203,7 @@ impl<T: InvokeUiSession> Session<T> {
self.send(Data::Message(msg));
}
pub fn get_audit_server(&self) -> String {
pub fn get_audit_server(&self, typ: String) -> String {
if self.lc.read().unwrap().conn_id <= 0
|| LocalConfig::get_option("access_token").is_empty()
{
@@ -186,11 +212,12 @@ impl<T: InvokeUiSession> Session<T> {
crate::get_audit_server(
Config::get_option("api-server"),
Config::get_option("custom-rendezvous-server"),
typ,
)
}
pub fn send_note(&self, note: String) {
let url = self.get_audit_server();
let url = self.get_audit_server("conn".to_string());
let id = self.id.clone();
let conn_id = self.lc.read().unwrap().conn_id;
std::thread::spawn(move || {
@@ -376,6 +403,7 @@ impl<T: InvokeUiSession> Session<T> {
name: &str,
keycode: i32,
scancode: i32,
lock_modes: i32,
down_or_up: bool,
) {
if scancode < 0 || keycode < 0 {
@@ -385,7 +413,7 @@ impl<T: InvokeUiSession> Session<T> {
let scancode: u32 = scancode as u32;
#[cfg(not(target_os = "windows"))]
let key = rdev::key_from_scancode(scancode) as rdev::Key;
let key = rdev::key_from_code(keycode) as rdev::Key;
// Windows requires special handling
#[cfg(target_os = "windows")]
let key = rdev::get_win_key(keycode, scancode);
@@ -402,7 +430,7 @@ impl<T: InvokeUiSession> Session<T> {
scan_code: scancode as _,
event_type: event_type,
};
keyboard::client::process_event(&event);
keyboard::client::process_event(&event, Some(lock_modes));
}
// flutter only TODO new input
@@ -586,7 +614,7 @@ pub trait InvokeUiSession: Send + Sync + Clone + 'static + Sized + Default {
fn set_cursor_data(&self, cd: CursorData);
fn set_cursor_id(&self, id: String);
fn set_cursor_position(&self, cp: CursorPosition);
fn set_display(&self, x: i32, y: i32, w: i32, h: i32, cursor_embeded: bool);
fn set_display(&self, x: i32, y: i32, w: i32, h: i32, cursor_embedded: bool);
fn switch_display(&self, display: &SwitchDisplay);
fn set_peer_info(&self, peer_info: &PeerInfo); // flutter
fn on_connected(&self, conn_type: ConnType);
@@ -639,39 +667,26 @@ impl<T: InvokeUiSession> FileManager for Session<T> {}
#[async_trait]
impl<T: InvokeUiSession> Interface for Session<T> {
fn get_login_config_handler(&self) -> Arc<RwLock<LoginConfigHandler>> {
return self.lc.clone();
}
fn send(&self, data: Data) {
if let Some(sender) = self.sender.read().unwrap().as_ref() {
sender.send(data).ok();
}
}
fn is_file_transfer(&self) -> bool {
self.lc
.read()
.unwrap()
.conn_type
.eq(&ConnType::FILE_TRANSFER)
}
fn is_port_forward(&self) -> bool {
self.lc
.read()
.unwrap()
.conn_type
.eq(&ConnType::PORT_FORWARD)
}
fn is_rdp(&self) -> bool {
self.lc.read().unwrap().conn_type.eq(&ConnType::RDP)
}
fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str) {
let retry = check_if_retry(msgtype, title, text);
let direct = self.lc.read().unwrap().direct.unwrap_or_default();
let received = self.lc.read().unwrap().received;
let retry_for_relay = direct && !received;
let retry = check_if_retry(msgtype, title, text, retry_for_relay);
self.ui_handler.msgbox(msgtype, title, text, link, retry);
}
fn handle_login_error(&mut self, err: &str) -> bool {
self.lc.write().unwrap().handle_login_error(err, self)
handle_login_error(self.lc.clone(), err, self)
}
fn handle_peer_info(&mut self, mut pi: PeerInfo) {
@@ -705,7 +720,7 @@ impl<T: InvokeUiSession> Interface for Session<T> {
current.y,
current.width,
current.height,
current.cursor_embeded,
current.cursor_embedded,
);
}
self.update_privacy_mode();
@@ -753,34 +768,14 @@ impl<T: InvokeUiSession> Interface for Session<T> {
handle_test_delay(t, peer).await;
}
}
fn set_force_relay(&mut self, direct: bool, received: bool) {
let mut lc = self.lc.write().unwrap();
lc.force_relay = false;
if direct && !received {
let errno = errno::errno().0;
log::info!("errno is {}", errno);
// TODO: check mac and ios
if cfg!(windows) && errno == 10054 || !cfg!(windows) && errno == 104 {
lc.force_relay = true;
lc.set_option("force-always-relay".to_owned(), "Y".to_owned());
}
}
}
fn is_force_relay(&self) -> bool {
self.lc.read().unwrap().force_relay
}
}
impl<T: InvokeUiSession> Session<T> {
pub fn lock_screen(&self) {
log::info!("Sending key even");
crate::keyboard::client::lock_screen();
}
pub fn ctrl_alt_del(&self) {
log::info!("Sending key even");
crate::keyboard::client::lock_screen();
crate::keyboard::client::ctrl_alt_del();
}
}