update sessions public function

This commit is contained in:
csf 2022-05-31 17:36:36 +08:00
parent 18ad23435b
commit 5274a43a34
5 changed files with 602 additions and 300 deletions

View File

@ -59,7 +59,7 @@ class _RemotePageState extends State<RemotePage> with WindowListener {
Wakelock.enable(); Wakelock.enable();
} }
_physicalFocusNode.requestFocus(); _physicalFocusNode.requestFocus();
FFI.ffiModel.updateEventListener(widget.id); // FFI.ffiModel.updateEventListener(widget.id);
FFI.listenToMouse(true); FFI.listenToMouse(true);
WindowManager.instance.addListener(this); WindowManager.instance.addListener(this);
} }
@ -599,10 +599,18 @@ class _RemotePageState extends State<RemotePage> with WindowListener {
Widget getBodyForDesktopWithListener(bool keyboard) { Widget getBodyForDesktopWithListener(bool keyboard) {
var paints = <Widget>[ImagePaint()]; var paints = <Widget>[ImagePaint()];
final cursor = await;
if (keyboard || if (keyboard ||
FFI.getByName('toggle_option', 'show-remote-cursor') == 'true') { FFI.getByName('toggle_option', 'show-remote-cursor') == 'true') {
paints.add(CursorPaint()); paints.add(CursorPaint());
} }
return FutureBuilder(
future: FFI.rustdeskImpl
.getSessionToggleOption(id: widget.id, arg: 'show-remote-cursor'),
builder: (ctx, snapshot) {
if(snapshot)
},
);
return Container( return Container(
color: MyTheme.canvasColor, child: Stack(children: paints)); color: MyTheme.canvasColor, child: Stack(children: paints));
} }
@ -974,9 +982,11 @@ RadioListTile<String> getRadio(String name, String toValue, String curValue,
void showOptions(String id) async { void showOptions(String id) async {
// String quality = FFI.getByName('image_quality'); // String quality = FFI.getByName('image_quality');
String quality = await FFI.rustdeskImpl.getImageQuality(id: id) ?? 'balanced'; String quality =
await FFI.rustdeskImpl.getSessionImageQuality(id: id) ?? 'balanced';
if (quality == '') quality = 'balanced'; if (quality == '') quality = 'balanced';
String viewStyle = FFI.getByName('peer_option', 'view-style'); String viewStyle =
await FFI.rustdeskImpl.getSessionOption(id: id, arg: 'view-style') ?? '';
var displays = <Widget>[]; var displays = <Widget>[];
final pi = FFI.ffiModel.pi; final pi = FFI.ffiModel.pi;
final image = FFI.ffiModel.getConnectionImage(); final image = FFI.ffiModel.getConnectionImage();

View File

@ -122,6 +122,53 @@ class FfiModel with ChangeNotifier {
_permissions.clear(); _permissions.clear();
} }
void Function(Map<String, dynamic>) startEventListener(String peerId) {
return (evt) {
var name = evt['name'];
if (name == 'msgbox') {
handleMsgBox(evt, peerId);
} else if (name == 'peer_info') {
handlePeerInfo(evt);
} else if (name == 'connection_ready') {
FFI.ffiModel.setConnectionType(
evt['secure'] == 'true', evt['direct'] == 'true');
} else if (name == 'switch_display') {
handleSwitchDisplay(evt);
} else if (name == 'cursor_data') {
FFI.cursorModel.updateCursorData(evt);
} else if (name == 'cursor_id') {
FFI.cursorModel.updateCursorId(evt);
} else if (name == 'cursor_position') {
FFI.cursorModel.updateCursorPosition(evt);
} else if (name == 'clipboard') {
Clipboard.setData(ClipboardData(text: evt['content']));
} else if (name == 'permission') {
FFI.ffiModel.updatePermission(evt);
} else if (name == 'chat_client_mode') {
FFI.chatModel.receive(ChatModel.clientModeID, evt['text'] ?? "");
} else if (name == 'chat_server_mode') {
FFI.chatModel
.receive(int.parse(evt['id'] as String), evt['text'] ?? "");
} else if (name == 'file_dir') {
FFI.fileModel.receiveFileDir(evt);
} else if (name == 'job_progress') {
FFI.fileModel.tryUpdateJobProgress(evt);
} else if (name == 'job_done') {
FFI.fileModel.jobDone(evt);
} else if (name == 'job_error') {
FFI.fileModel.jobError(evt);
} else if (name == 'override_file_confirm') {
FFI.fileModel.overrideFileConfirm(evt);
} else if (name == 'try_start_without_auth') {
FFI.serverModel.loginRequest(evt);
} else if (name == 'on_client_authorized') {
FFI.serverModel.onClientAuthorized(evt);
} else if (name == 'on_client_remove') {
FFI.serverModel.onClientRemove(evt);
}
};
}
/// Bind the event listener to receive events from the Rust core. /// Bind the event listener to receive events from the Rust core.
void updateEventListener(String peerId) { void updateEventListener(String peerId) {
final void Function(Map<String, dynamic>) cb = (evt) { final void Function(Map<String, dynamic>) cb = (evt) {
@ -782,9 +829,19 @@ class FFI {
} else { } else {
FFI.chatModel.resetClientMode(); FFI.chatModel.resetClientMode();
// setByName('connect', id); // setByName('connect', id);
final stream = final event_stream = FFI.rustdeskImpl
FFI.rustdeskImpl.connect(id: id, isFileTransfer: isFileTransfer); .sessionConnect(id: id, isFileTransfer: isFileTransfer);
// listen stream ... final cb = FFI.ffiModel.startEventListener(id);
() async {
await for (final message in event_stream) {
try {
Map<String, dynamic> event = json.decode(message);
cb(event);
} catch (e) {
print('json.decode fail(): $e');
}
}
}();
// every instance will bind a stream // every instance will bind a stream
} }
FFI.id = id; FFI.id = id;

View File

@ -1,16 +1,13 @@
use super::{Data, Interface}; use super::{Data, Interface};
use hbb_common::{ use hbb_common::{fs, message_proto::*};
fs,
message_proto::*,
};
pub trait FileManager: Interface { pub trait FileManager: Interface {
fn get_home_dir(&self) -> String{ fn get_home_dir(&self) -> String {
fs::get_home_as_string() fs::get_home_as_string()
} }
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
fn read_dir(&self,path: String, include_hidden: bool) -> sciter::Value { fn read_dir(&self, path: String, include_hidden: bool) -> sciter::Value {
match fs::read_dir(&fs::get_path(&path), include_hidden) { match fs::read_dir(&fs::get_path(&path), include_hidden) {
Err(_) => sciter::Value::null(), Err(_) => sciter::Value::null(),
Ok(fd) => { Ok(fd) => {
@ -23,11 +20,11 @@ pub trait FileManager: Interface {
} }
#[cfg(any(target_os = "android", target_os = "ios"))] #[cfg(any(target_os = "android", target_os = "ios"))]
fn read_dir(&self,path: &str, include_hidden: bool) -> String { fn read_dir(&self, path: &str, include_hidden: bool) -> String {
use crate::flutter::make_fd_to_json; use crate::flutter::make_fd_to_json;
match fs::read_dir(&fs::get_path(path), include_hidden){ match fs::read_dir(&fs::get_path(path), include_hidden) {
Ok(fd) => make_fd_to_json(fd), Ok(fd) => make_fd_to_json(fd),
Err(_)=>"".into() Err(_) => "".into(),
} }
} }
@ -76,7 +73,7 @@ pub trait FileManager: Interface {
} }
fn send_files( fn send_files(
&mut self, &self,
id: i32, id: i32,
path: String, path: String,
to: String, to: String,
@ -84,7 +81,14 @@ pub trait FileManager: Interface {
include_hidden: bool, include_hidden: bool,
is_remote: bool, is_remote: bool,
) { ) {
self.send(Data::SendFiles((id, path, to, file_num, include_hidden, is_remote))); self.send(Data::SendFiles((
id,
path,
to,
file_num,
include_hidden,
is_remote,
)));
} }
fn add_job( fn add_job(
@ -96,10 +100,17 @@ pub trait FileManager: Interface {
include_hidden: bool, include_hidden: bool,
is_remote: bool, is_remote: bool,
) { ) {
self.send(Data::AddJob((id, path, to, file_num, include_hidden, is_remote))); self.send(Data::AddJob((
id,
path,
to,
file_num,
include_hidden,
is_remote,
)));
} }
fn resume_job(&mut self, id: i32, is_remote: bool){ fn resume_job(&mut self, id: i32, is_remote: bool) {
self.send(Data::ResumeJob((id,is_remote))); self.send(Data::ResumeJob((id, is_remote)));
} }
} }

View File

@ -27,14 +27,14 @@ use std::{
lazy_static::lazy_static! { lazy_static::lazy_static! {
// static ref SESSION: Arc<RwLock<Option<Session>>> = Default::default(); // static ref SESSION: Arc<RwLock<Option<Session>>> = Default::default();
static ref SESSIONS: RwLock<HashMap<String,Session>> = Default::default(); pub static ref SESSIONS: RwLock<HashMap<String,Session>> = Default::default();
pub static ref EVENT_STREAM: RwLock<Option<StreamSink<String>>> = Default::default(); // rust to dart event channel pub static ref EVENT_STREAM: RwLock<Option<StreamSink<String>>> = Default::default(); // rust to dart event channel
pub static ref RGBA_STREAM: RwLock<Option<StreamSink<ZeroCopyBuffer<Vec<u8>>>>> = Default::default(); // rust to dart rgba (big u8 list) channel pub static ref RGBA_STREAM: RwLock<Option<StreamSink<ZeroCopyBuffer<Vec<u8>>>>> = Default::default(); // rust to dart rgba (big u8 list) channel
} }
pub fn get_session(id: &str) -> Option<&Session> { // pub fn get_session<'a>(id: &str) -> Option<&'a Session> {
SESSIONS.read().unwrap().get(id) // SESSIONS.read().unwrap().get(id)
} // }
#[derive(Clone)] #[derive(Clone)]
pub struct Session { pub struct Session {
@ -102,7 +102,7 @@ impl Session {
/// * `value` - The value of the option to set. /// * `value` - The value of the option to set.
pub fn set_option(&self, name: String, value: String) { pub fn set_option(&self, name: String, value: String) {
let mut value = value; let mut value = value;
let lc = self.lc.write().unwrap(); let mut lc = self.lc.write().unwrap();
if name == "remote_dir" { if name == "remote_dir" {
value = lc.get_all_remote_dir(value); value = lc.get_all_remote_dir(value);
} }
@ -367,7 +367,7 @@ impl Session {
/// ///
/// # Arguments /// # Arguments
/// ///
/// * `value` - The text to input. /// * `value` - The text to input. TODO &str -> String
pub fn input_string(&self, value: &str) { pub fn input_string(&self, value: &str) {
let mut key_event = KeyEvent::new(); let mut key_event = KeyEvent::new();
key_event.set_seq(value.to_owned()); key_event.set_seq(value.to_owned());

View File

@ -1,9 +1,9 @@
use crate::client::file_trait::FileManager; use crate::client::file_trait::FileManager;
use crate::flutter::connection_manager::{self, get_clients_length, get_clients_state}; use crate::flutter::connection_manager::{self, get_clients_length, get_clients_state};
use crate::flutter::{self, get_session, make_fd_to_json, Session}; use crate::flutter::{self, make_fd_to_json, Session, SESSIONS};
use crate::start_server; use crate::start_server;
use crate::ui_interface; use crate::ui_interface;
use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer}; use flutter_rust_bridge::{StreamSink, SyncReturn, ZeroCopyBuffer};
use hbb_common::ResultType; use hbb_common::ResultType;
use hbb_common::{ use hbb_common::{
config::{self, Config, LocalConfig, PeerConfig, ONLINE}, config::{self, Config, LocalConfig, PeerConfig, ONLINE},
@ -69,13 +69,236 @@ pub fn start_rgba_stream(s: StreamSink<ZeroCopyBuffer<Vec<u8>>>) -> ResultType<(
Ok(()) Ok(())
} }
pub fn connect(id: String, is_file_transfer: bool, events2ui: StreamSink<String>) { pub fn session_connect(
events2ui: StreamSink<String>,
id: String,
is_file_transfer: bool,
) -> ResultType<()> {
Session::start(&id, is_file_transfer, events2ui); Session::start(&id, is_file_transfer, events2ui);
Ok(())
} }
pub fn get_image_quality(id: String) -> Option<String> { pub fn get_session_remember(id: String) -> Option<bool> {
let session = get_session(&id)?; if let Some(session) = SESSIONS.read().unwrap().get(&id) {
Some(session.get_image_quality()) Some(session.get_remember())
} else {
None
}
}
pub fn get_session_toggle_option(id: String, arg: String) -> Option<bool> {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
Some(session.get_toggle_option(&arg))
} else {
None
}
}
pub fn get_session_image_quality(id: String) -> SyncReturn<Option<String>> {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
SyncReturn(Some(session.get_image_quality()))
} else {
SyncReturn(None)
}
}
pub fn get_session_option(id: String, arg: String) -> Option<String> {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
Some(session.get_option(&arg))
} else {
None
}
}
// void
pub fn session_login(id: String, password: String, remember: bool) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.login(&password, remember);
}
}
pub fn session_close(id: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.close();
}
}
pub fn session_refresh(id: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.refresh();
}
}
pub fn session_reconnect(id: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.reconnect();
}
}
pub fn session_toggle_option(id: String, value: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.toggle_option(&value);
}
}
pub fn session_set_image_quality(id: String, value: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.set_image_quality(&value);
}
}
pub fn session_lock_screen(id: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.lock_screen();
}
}
pub fn session_ctrl_alt_del(id: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.ctrl_alt_del();
}
}
pub fn session_switch_display(id: String, value: i32) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.switch_display(value);
}
}
pub fn session_input_key(
id: String,
name: String,
down: bool,
press: bool,
alt: bool,
ctrl: bool,
shift: bool,
command: bool,
) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.input_key(&name, down, press, alt, ctrl, shift, command);
}
}
pub fn session_input_string(id: String, value: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.input_string(&value);
}
}
// chat_client_mode
pub fn session_send_chat(id: String, text: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.send_chat(text);
}
}
// if let Some(_type) = m.get("type") {
// mask = match _type.as_str() {
// "down" => 1,
// "up" => 2,
// "wheel" => 3,
// _ => 0,
// };
// }
// if let Some(buttons) = m.get("buttons") {
// mask |= match buttons.as_str() {
// "left" => 1,
// "right" => 2,
// "wheel" => 4,
// _ => 0,
// } << 3;
// }
// TODO
pub fn session_send_mouse(
id: String,
mask: i32,
x: i32,
y: i32,
alt: bool,
ctrl: bool,
shift: bool,
command: bool,
) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.send_mouse(mask, x, y, alt, ctrl, shift, command);
}
}
pub fn session_peer_option(id: String, name: String, value: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.set_option(name, value);
}
}
pub fn session_input_os_password(id: String, value: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.input_os_password(value, true);
}
}
// File Action
pub fn session_read_remote_dir(id: String, path: String, include_hidden: bool) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.read_remote_dir(path, include_hidden);
}
}
pub fn session_send_files(
id: String,
act_id: i32,
path: String,
to: String,
file_num: i32,
include_hidden: bool,
is_remote: bool,
) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.send_files(act_id, path, to, file_num, include_hidden, is_remote);
}
}
pub fn session_set_confirm_override_file(
id: String,
act_id: i32,
file_num: i32,
need_override: bool,
remember: bool,
is_upload: bool,
) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.set_confirm_override_file(act_id, file_num, need_override, remember, is_upload);
}
}
pub fn session_remove_file(id: String, act_id: i32, path: String, file_num: i32, is_remote: bool) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.remove_file(act_id, path, file_num, is_remote);
}
}
pub fn session_read_dir_recursive(id: String, act_id: i32, path: String, is_remote: bool) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.remove_dir_all(act_id, path, is_remote);
}
}
pub fn session_remove_all_empty_dirs(id: String, act_id: i32, path: String, is_remote: bool) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.remove_dir(act_id, path, is_remote);
}
}
pub fn session_cancel_job(id: String, act_id: i32) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.cancel_job(act_id);
}
}
pub fn session_create_dir(id: String, act_id: i32, path: String, is_remote: bool) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.create_dir(act_id, path, is_remote);
}
} }
/// FFI for **get** commands which are idempotent. /// FFI for **get** commands which are idempotent.
@ -106,16 +329,16 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co
res = LocalConfig::get_remote_id(); res = LocalConfig::get_remote_id();
} }
} }
"remember" => { // "remember" => {
res = Session::get_remember().to_string(); // res = Session::get_remember().to_string();
} // }
"toggle_option" => { // "toggle_option" => {
if let Ok(arg) = arg.to_str() { // if let Ok(arg) = arg.to_str() {
if let Some(v) = Session::get_toggle_option(arg) { // if let Some(v) = Session::get_toggle_option(arg) {
res = v.to_string(); // res = v.to_string();
} // }
} // }
} // }
"test_if_valid_server" => { "test_if_valid_server" => {
if let Ok(arg) = arg.to_str() { if let Ok(arg) = arg.to_str() {
res = hbb_common::socket_client::test_if_valid_server(arg); res = hbb_common::socket_client::test_if_valid_server(arg);
@ -126,9 +349,9 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co
res = Config::get_option(arg); res = Config::get_option(arg);
} }
} }
"image_quality" => { // "image_quality" => {
res = Session::get_image_quality(); // res = Session::get_image_quality();
} // }
"software_update_url" => { "software_update_url" => {
res = crate::common::SOFTWARE_UPDATE_URL.lock().unwrap().clone() res = crate::common::SOFTWARE_UPDATE_URL.lock().unwrap().clone()
} }
@ -143,11 +366,11 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co
} }
} }
} }
"peer_option" => { // "peer_option" => {
if let Ok(arg) = arg.to_str() { // if let Ok(arg) = arg.to_str() {
res = Session::get_option(arg); // res = Session::get_option(arg);
} // }
} // }
"server_id" => { "server_id" => {
res = ui_interface::get_id(); res = ui_interface::get_id();
} }
@ -231,103 +454,103 @@ unsafe extern "C" fn set_by_name(name: *const c_char, value: *const c_char) {
"info2" => { "info2" => {
*crate::common::MOBILE_INFO2.lock().unwrap() = value.to_owned(); *crate::common::MOBILE_INFO2.lock().unwrap() = value.to_owned();
} }
"connect" => { // "connect" => {
Session::start(value, false); // Session::start(value, false);
} // }
"connect_file_transfer" => { // "connect_file_transfer" => {
Session::start(value, true); // Session::start(value, true);
} // }
"login" => { // "login" => {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
if let Some(password) = m.get("password") { // if let Some(password) = m.get("password") {
if let Some(remember) = m.get("remember") { // if let Some(remember) = m.get("remember") {
Session::login(password, remember == "true"); // Session::login(password, remember == "true");
} // }
} // }
} // }
} // }
"close" => { // "close" => {
Session::close(); // Session::close();
} // }
"refresh" => { // "refresh" => {
Session::refresh(); // Session::refresh();
} // }
"reconnect" => { // "reconnect" => {
Session::reconnect(); // Session::reconnect();
} // }
"toggle_option" => { // "toggle_option" => {
Session::toggle_option(value); // Session::toggle_option(value);
} // }
"image_quality" => { // "image_quality" => {
Session::set_image_quality(value); // Session::set_image_quality(value);
} // }
"lock_screen" => { // "lock_screen" => {
Session::lock_screen(); // Session::lock_screen();
} // }
"ctrl_alt_del" => { // "ctrl_alt_del" => {
Session::ctrl_alt_del(); // Session::ctrl_alt_del();
} // }
"switch_display" => { // "switch_display" => {
if let Ok(v) = value.parse::<i32>() { // if let Ok(v) = value.parse::<i32>() {
Session::switch_display(v); // Session::switch_display(v);
} // }
} // }
"remove" => { "remove" => {
PeerConfig::remove(value); PeerConfig::remove(value);
} }
"input_key" => { // "input_key" => {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
let alt = m.get("alt").is_some(); // let alt = m.get("alt").is_some();
let ctrl = m.get("ctrl").is_some(); // let ctrl = m.get("ctrl").is_some();
let shift = m.get("shift").is_some(); // let shift = m.get("shift").is_some();
let command = m.get("command").is_some(); // let command = m.get("command").is_some();
let down = m.get("down").is_some(); // let down = m.get("down").is_some();
let press = m.get("press").is_some(); // let press = m.get("press").is_some();
if let Some(name) = m.get("name") { // if let Some(name) = m.get("name") {
Session::input_key(name, down, press, alt, ctrl, shift, command); // Session::input_key(name, down, press, alt, ctrl, shift, command);
} // }
} // }
} // }
"input_string" => { // "input_string" => {
Session::input_string(value); // Session::input_string(value);
} // }
"chat_client_mode" => { // "chat_client_mode" => {
Session::send_chat(value.to_owned()); // Session::send_chat(value.to_owned());
} // }
"send_mouse" => { // "send_mouse" => {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
let alt = m.get("alt").is_some(); // let alt = m.get("alt").is_some();
let ctrl = m.get("ctrl").is_some(); // let ctrl = m.get("ctrl").is_some();
let shift = m.get("shift").is_some(); // let shift = m.get("shift").is_some();
let command = m.get("command").is_some(); // let command = m.get("command").is_some();
let x = m // let x = m
.get("x") // .get("x")
.map(|x| x.parse::<i32>().unwrap_or(0)) // .map(|x| x.parse::<i32>().unwrap_or(0))
.unwrap_or(0); // .unwrap_or(0);
let y = m // let y = m
.get("y") // .get("y")
.map(|x| x.parse::<i32>().unwrap_or(0)) // .map(|x| x.parse::<i32>().unwrap_or(0))
.unwrap_or(0); // .unwrap_or(0);
let mut mask = 0; // let mut mask = 0;
if let Some(_type) = m.get("type") { // if let Some(_type) = m.get("type") {
mask = match _type.as_str() { // mask = match _type.as_str() {
"down" => 1, // "down" => 1,
"up" => 2, // "up" => 2,
"wheel" => 3, // "wheel" => 3,
_ => 0, // _ => 0,
}; // };
} // }
if let Some(buttons) = m.get("buttons") { // if let Some(buttons) = m.get("buttons") {
mask |= match buttons.as_str() { // mask |= match buttons.as_str() {
"left" => 1, // "left" => 1,
"right" => 2, // "right" => 2,
"wheel" => 4, // "wheel" => 4,
_ => 0, // _ => 0,
} << 3; // } << 3;
} // }
Session::send_mouse(mask, x, y, alt, ctrl, shift, command); // Session::send_mouse(mask, x, y, alt, ctrl, shift, command);
} // }
} // }
"option" => { "option" => {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
if let Some(name) = m.get("name") { if let Some(name) = m.get("name") {
@ -347,162 +570,163 @@ unsafe extern "C" fn set_by_name(name: *const c_char, value: *const c_char) {
} }
} }
} }
"peer_option" => { // "peer_option" => {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
if let Some(name) = m.get("name") { // if let Some(name) = m.get("name") {
if let Some(value) = m.get("value") { // if let Some(value) = m.get("value") {
Session::set_option(name.to_owned(), value.to_owned()); // Session::set_option(name.to_owned(), value.to_owned());
} // }
} // }
} // }
} // }
"input_os_password" => { // "input_os_password" => {
Session::input_os_password(value.to_owned(), true); // Session::input_os_password(value.to_owned(), true);
} // }
// File Action // // File Action
"read_remote_dir" => { // "read_remote_dir" => {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
if let (Some(path), Some(show_hidden), Some(session)) = ( // if let (Some(path), Some(show_hidden), Some(session)) = (
m.get("path"), // m.get("path"),
m.get("show_hidden"), // m.get("show_hidden"),
Session::get().read().unwrap().as_ref(), // Session::get().read().unwrap().as_ref(),
) { // ) {
session.read_remote_dir(path.to_owned(), show_hidden.eq("true")); // session.read_remote_dir(path.to_owned(), show_hidden.eq("true"));
} // }
} // }
} // }
"send_files" => { // "send_files" => {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
if let ( // if let (
Some(id), // Some(id),
Some(path), // Some(path),
Some(to), // Some(to),
Some(file_num), // Some(file_num),
Some(show_hidden), // Some(show_hidden),
Some(is_remote), // Some(is_remote),
) = ( // ) = (
m.get("id"), // m.get("id"),
m.get("path"), // m.get("path"),
m.get("to"), // m.get("to"),
m.get("file_num"), // m.get("file_num"),
m.get("show_hidden"), // m.get("show_hidden"),
m.get("is_remote"), // m.get("is_remote"),
) { // ) {
Session::send_files( // Session::send_files(
id.parse().unwrap_or(0), // id.parse().unwrap_or(0),
path.to_owned(), // path.to_owned(),
to.to_owned(), // to.to_owned(),
file_num.parse().unwrap_or(0), // file_num.parse().unwrap_or(0),
show_hidden.eq("true"), // show_hidden.eq("true"),
is_remote.eq("true"), // is_remote.eq("true"),
); // );
} // }
} // }
} // }
"set_confirm_override_file" => { // "set_confirm_override_file" => {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
if let ( // if let (
Some(id), // Some(id),
Some(file_num), // Some(file_num),
Some(need_override), // Some(need_override),
Some(remember), // Some(remember),
Some(is_upload), // Some(is_upload),
) = ( // ) = (
m.get("id"), // m.get("id"),
m.get("file_num"), // m.get("file_num"),
m.get("need_override"), // m.get("need_override"),
m.get("remember"), // m.get("remember"),
m.get("is_upload"), // m.get("is_upload"),
) { // ) {
Session::set_confirm_override_file( // Session::set_confirm_override_file(
id.parse().unwrap_or(0), // id.parse().unwrap_or(0),
file_num.parse().unwrap_or(0), // file_num.parse().unwrap_or(0),
need_override.eq("true"), // need_override.eq("true"),
remember.eq("true"), // remember.eq("true"),
is_upload.eq("true"), // is_upload.eq("true"),
); // );
} // }
} // }
} // }
"remove_file" => { // ** TODO ** continue
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // "remove_file" => {
if let ( // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
Some(id), // if let (
Some(path), // Some(id),
Some(file_num), // Some(path),
Some(is_remote), // Some(file_num),
Some(session), // Some(is_remote),
) = ( // Some(session),
m.get("id"), // ) = (
m.get("path"), // m.get("id"),
m.get("file_num"), // m.get("path"),
m.get("is_remote"), // m.get("file_num"),
Session::get().write().unwrap().as_mut(), // m.get("is_remote"),
) { // Session::get().write().unwrap().as_mut(),
session.remove_file( // ) {
id.parse().unwrap_or(0), // session.remove_file(
path.to_owned(), // id.parse().unwrap_or(0),
file_num.parse().unwrap_or(0), // path.to_owned(),
is_remote.eq("true"), // file_num.parse().unwrap_or(0),
); // is_remote.eq("true"),
} // );
} // }
} // }
"read_dir_recursive" => { // }
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // "read_dir_recursive" => {
if let (Some(id), Some(path), Some(is_remote), Some(session)) = ( // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
m.get("id"), // if let (Some(id), Some(path), Some(is_remote), Some(session)) = (
m.get("path"), // m.get("id"),
m.get("is_remote"), // m.get("path"),
Session::get().write().unwrap().as_mut(), // m.get("is_remote"),
) { // Session::get().write().unwrap().as_mut(),
session.remove_dir_all( // ) {
id.parse().unwrap_or(0), // session.remove_dir_all(
path.to_owned(), // id.parse().unwrap_or(0),
is_remote.eq("true"), // path.to_owned(),
); // is_remote.eq("true"),
} // );
} // }
} // }
"remove_all_empty_dirs" => { // }
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // "remove_all_empty_dirs" => {
if let (Some(id), Some(path), Some(is_remote), Some(session)) = ( // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
m.get("id"), // if let (Some(id), Some(path), Some(is_remote), Some(session)) = (
m.get("path"), // m.get("id"),
m.get("is_remote"), // m.get("path"),
Session::get().write().unwrap().as_mut(), // m.get("is_remote"),
) { // Session::get().write().unwrap().as_mut(),
session.remove_dir( // ) {
id.parse().unwrap_or(0), // session.remove_dir(
path.to_owned(), // id.parse().unwrap_or(0),
is_remote.eq("true"), // path.to_owned(),
); // is_remote.eq("true"),
} // );
} // }
} // }
"cancel_job" => { // }
if let (Ok(id), Some(session)) = // "cancel_job" => {
(value.parse(), Session::get().write().unwrap().as_mut()) // if let (Ok(id), Some(session)) =
{ // (value.parse(), Session::get().write().unwrap().as_mut())
session.cancel_job(id); // {
} // session.cancel_job(id);
} // }
"create_dir" => { // }
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) { // "create_dir" => {
if let (Some(id), Some(path), Some(is_remote), Some(session)) = ( // if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
m.get("id"), // if let (Some(id), Some(path), Some(is_remote), Some(session)) = (
m.get("path"), // m.get("id"),
m.get("is_remote"), // m.get("path"),
Session::get().write().unwrap().as_mut(), // m.get("is_remote"),
) { // Session::get().write().unwrap().as_mut(),
session.create_dir( // ) {
id.parse().unwrap_or(0), // session.create_dir(
path.to_owned(), // id.parse().unwrap_or(0),
is_remote.eq("true"), // path.to_owned(),
); // is_remote.eq("true"),
} // );
} // }
} // }
// }
// Server Side // Server Side
"update_password" => { "update_password" => {
if value.is_empty() { if value.is_empty() {