WIP file transfer

This commit is contained in:
csf
2022-09-05 10:27:33 +08:00
parent f385127f3b
commit 09b769d92f
7 changed files with 196 additions and 191 deletions

View File

@@ -695,7 +695,7 @@ handler.clearAllJobs = function() {
file_transfer.job_table.clearAllJobs();
}
handler.addJob = function (id, path, to, file_num, show_hidden, is_remote) {
handler.addJob = function (id, path, to, file_num, show_hidden, is_remote) { // load last job
// stdout.println("restore job: " + is_remote);
file_transfer.job_table.addJob(id,path,to,file_num,show_hidden,is_remote);
}

View File

@@ -23,7 +23,9 @@ use clipboard::{
get_rx_clip_client, server_clip_file,
};
use hbb_common::{allow_err, log, message_proto::*, rendezvous_proto::ConnType};
use hbb_common::{
allow_err, fs::TransferJobMeta, log, message_proto::*, rendezvous_proto::ConnType,
};
#[cfg(windows)]
use crate::clipboard_file::*;
@@ -43,7 +45,6 @@ static mut IS_ALT_GR: bool = false;
/// SciterHandler
/// * element
/// * thread TODO check if flutter need
/// * close_state for file path when close
#[derive(Clone, Default)]
pub struct SciterHandler {
@@ -155,16 +156,36 @@ impl InvokeUi for SciterHandler {
self.call("clearAllJobs", &make_args!());
}
fn add_job(
fn load_last_job(&self, cnt: i32, job_json: &str) {
let job: Result<TransferJobMeta, serde_json::Error> = serde_json::from_str(job_json);
if let Ok(job) = job {
let path;
let to;
if job.is_remote {
path = job.remote.clone();
to = job.to.clone();
} else {
path = job.to.clone();
to = job.remote.clone();
}
self.call(
"addJob",
&make_args!(cnt, path, to, job.file_num, job.show_hidden, job.is_remote),
);
}
}
fn update_folder_files(
&self,
id: i32,
entries: &Vec<FileEntry>,
path: String,
to: String,
file_num: i32,
show_hidden: bool,
is_remote: bool,
_is_local: bool,
only_count: bool,
) {
todo!()
let mut m = make_fd(id, entries, only_count);
m.set_item("path", path);
self.call("updateFolderFiles", &make_args!(m));
}
fn update_transfer_list(&self) {
@@ -686,15 +707,18 @@ impl SciterSession {
}
pub fn make_fd(id: i32, entries: &Vec<FileEntry>, only_count: bool) -> Value {
log::debug!("make_fd");
let mut m = Value::map();
m.set_item("id", id);
let mut a = Value::array(0);
let mut n: u64 = 0;
for entry in entries {
log::debug!("for");
n += entry.size;
if only_count {
continue;
}
log::debug!("for1");
let mut e = Value::map();
e.set_item("name", entry.name.to_owned());
let tmp = entry.entry_type.value();
@@ -703,11 +727,11 @@ pub fn make_fd(id: i32, entries: &Vec<FileEntry>, only_count: bool) -> Value {
e.set_item("size", entry.size as f64);
a.push(e);
}
if only_count {
m.set_item("num_entries", entries.len() as i32);
} else {
if !only_count {
m.set_item("entries", a);
}
m.set_item("num_entries", entries.len() as i32);
m.set_item("total_size", n as f64);
log::debug!("make_fd end");
m
}