add: job logic
This commit is contained in:
parent
2caa2db463
commit
11e0d2cbf1
@ -201,7 +201,10 @@ pub fn can_enable_overwrite_detection(version: i64) -> bool {
|
||||
#[derive(Default)]
|
||||
pub struct TransferJob {
|
||||
id: i32,
|
||||
remote: String,
|
||||
path: PathBuf,
|
||||
show_hidden: bool,
|
||||
is_remote: bool,
|
||||
files: Vec<FileEntry>,
|
||||
file_num: i32,
|
||||
file: Option<File>,
|
||||
@ -217,7 +220,9 @@ pub struct TransferJob {
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct TransferJobMeta {
|
||||
pub id: i32,
|
||||
pub path: PathBuf,
|
||||
pub remote: String,
|
||||
pub to: String,
|
||||
pub show_hidden: bool,
|
||||
pub file_num: i32,
|
||||
}
|
||||
|
||||
@ -253,7 +258,10 @@ fn is_compressed_file(name: &str) -> bool {
|
||||
impl TransferJob {
|
||||
pub fn new_write(
|
||||
id: i32,
|
||||
remote: String,
|
||||
path: String,
|
||||
show_hidden: bool,
|
||||
is_remote: bool,
|
||||
files: Vec<FileEntry>,
|
||||
enable_override_detection: bool,
|
||||
) -> Self {
|
||||
@ -261,7 +269,10 @@ impl TransferJob {
|
||||
let total_size = files.iter().map(|x| x.size as u64).sum();
|
||||
Self {
|
||||
id,
|
||||
remote,
|
||||
path: get_path(&path),
|
||||
show_hidden,
|
||||
is_remote,
|
||||
files,
|
||||
total_size,
|
||||
enable_overwrite_detection: enable_override_detection,
|
||||
@ -271,7 +282,10 @@ impl TransferJob {
|
||||
|
||||
pub fn new_read(
|
||||
id: i32,
|
||||
remote: String,
|
||||
path: String,
|
||||
show_hidden: bool,
|
||||
is_remote: bool,
|
||||
include_hidden: bool,
|
||||
enable_override_detection: bool,
|
||||
) -> ResultType<Self> {
|
||||
@ -280,7 +294,10 @@ impl TransferJob {
|
||||
let total_size = files.iter().map(|x| x.size as u64).sum();
|
||||
Ok(Self {
|
||||
id,
|
||||
remote,
|
||||
path: get_path(&path),
|
||||
show_hidden,
|
||||
is_remote,
|
||||
files,
|
||||
total_size,
|
||||
enable_overwrite_detection: enable_override_detection,
|
||||
@ -561,8 +578,10 @@ impl TransferJob {
|
||||
pub fn gen_meta(&self) -> TransferJobMeta {
|
||||
TransferJobMeta {
|
||||
id: self.id,
|
||||
path: self.path.clone(),
|
||||
remote: self.remote.to_string(),
|
||||
to: self.path.to_string_lossy().to_string(),
|
||||
file_num: self.file_num,
|
||||
show_hidden: self.show_hidden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -974,7 +974,7 @@ impl Connection {
|
||||
let id = s.id;
|
||||
let od =
|
||||
can_enable_overwrite_detection(get_version_number(VERSION));
|
||||
match fs::TransferJob::new_read(id, s.path.clone(), s.include_hidden) {
|
||||
match fs::TransferJob::new_read(id, s.path.clone(), s.include_hidden, od) {
|
||||
Err(err) => {
|
||||
self.send(fs::new_error(id, err, 0)).await;
|
||||
}
|
||||
|
@ -161,9 +161,13 @@ impl ConnectionManager {
|
||||
mut files,
|
||||
} => {
|
||||
let od = can_enable_overwrite_detection(get_version_number(VERSION));
|
||||
// cm has no show_hidden context
|
||||
write_jobs.push(fs::TransferJob::new_write(
|
||||
id,
|
||||
"".to_string(),
|
||||
path,
|
||||
false,
|
||||
false,
|
||||
files
|
||||
.drain(..)
|
||||
.map(|f| FileEntry {
|
||||
@ -172,7 +176,7 @@ impl ConnectionManager {
|
||||
..Default::default()
|
||||
})
|
||||
.collect(),
|
||||
od,
|
||||
od,
|
||||
));
|
||||
}
|
||||
ipc::FS::CancelWrite { id } => {
|
||||
|
@ -100,6 +100,12 @@ class JobTable: Reactor.Component {
|
||||
refreshDir(is_remote);
|
||||
}
|
||||
|
||||
function clearAllJobs() {
|
||||
this.jobs = [];
|
||||
this.job_map = {};
|
||||
this.update();
|
||||
}
|
||||
|
||||
function send(path, is_remote) {
|
||||
var to;
|
||||
var show_hidden;
|
||||
@ -124,6 +130,14 @@ class JobTable: Reactor.Component {
|
||||
self.timer(30ms, function() { self.update(); });
|
||||
}
|
||||
|
||||
function addJob(id, path, to, show_hidden, is_remote) {
|
||||
this.jobs.push({ type: "transfer",
|
||||
id: id, path: path, to: to,
|
||||
include_hidden: show_hidden,
|
||||
is_remote: is_remote });
|
||||
this.job_map[id] = this.jobs[this.jobs.length - 1];
|
||||
}
|
||||
|
||||
function addDelDir(path, is_remote) {
|
||||
var id = jobIdCounter;
|
||||
jobIdCounter += 1;
|
||||
@ -649,6 +663,18 @@ handler.jobError = function(id, err, file_num = -1) {
|
||||
file_transfer.job_table.updateJobStatus(id, file_num, err);
|
||||
}
|
||||
|
||||
handler.clearAllJobs = function() {
|
||||
file_transfer.job_table.clearAllJobs();
|
||||
}
|
||||
|
||||
handler.addJob = function (id, path, to, file_num, show_hidden, is_remote) {
|
||||
file_transfer.job_table.addJob(id,path,to,file_num,show_hidden,is_remote);
|
||||
}
|
||||
|
||||
handler.updateTransferList = function () {
|
||||
file_transfer.job_table.update();
|
||||
}
|
||||
|
||||
function refreshDir(is_remote) {
|
||||
if (is_remote) file_transfer.remote_folder_view.refreshDir();
|
||||
else file_transfer.local_folder_view.refreshDir();
|
||||
|
@ -1387,6 +1387,10 @@ impl Remote {
|
||||
}
|
||||
self.handler
|
||||
.call("setConnectionType", &make_args!(peer.is_secured(), direct));
|
||||
|
||||
if conn_type == ConnType::FILE_TRANSFER {
|
||||
self.load_last_jobs().await;
|
||||
}
|
||||
|
||||
// just build for now
|
||||
#[cfg(not(windows))]
|
||||
@ -1537,6 +1541,36 @@ impl Remote {
|
||||
Some(tx)
|
||||
}
|
||||
|
||||
async fn load_last_jobs(&mut self) {
|
||||
self.handler.call("clearAllJobs",&make_args!());
|
||||
let pc = self.handler.load_config();
|
||||
if pc.transfer.write_jobs.is_empty() && pc.transfer.read_jobs.is_empty() {
|
||||
// no last jobs
|
||||
return;
|
||||
}
|
||||
// TODO: can add a confirm dialog
|
||||
let mut cnt = 0;
|
||||
for job in pc.transfer.read_jobs.iter() {
|
||||
self.handler.call("addJob",&make_args!(
|
||||
cnt,job.remote.clone(),job.to.clone(),job.file_num,job.show_hidden, false
|
||||
));
|
||||
self.handler.send_files(cnt, job.remote.clone(),
|
||||
job.to.clone(), job.show_hidden, false);
|
||||
cnt += 1;
|
||||
println!("restore read_job: {:?}",job);
|
||||
}
|
||||
for job in pc.transfer.write_jobs.iter() {
|
||||
self.handler.call("addJob",&make_args!(
|
||||
cnt,job.remote.clone(),job.to.clone(),job.file_num,job.show_hidden, true
|
||||
));
|
||||
self.handler.send_files(cnt, job.remote.clone(),
|
||||
job.to.clone(), job.show_hidden, true);
|
||||
cnt += 1;
|
||||
println!("restore write_job: {:?}",job);
|
||||
}
|
||||
self.handler.call("updateTransferList", &make_args!());
|
||||
}
|
||||
|
||||
async fn handle_msg_from_ui(&mut self, data: Data, peer: &mut Stream) -> bool {
|
||||
// log::info!("new msg from ui, {}",data);
|
||||
match data {
|
||||
@ -1560,10 +1594,10 @@ impl Remote {
|
||||
if is_remote {
|
||||
log::debug!("New job {}, write to {} from remote {}", id, to, path);
|
||||
self.write_jobs
|
||||
.push(fs::TransferJob::new_write(id, to, Vec::new(), od));
|
||||
.push(fs::TransferJob::new_write(id, path.clone(),to,include_hidden,is_remote, Vec::new(), od));
|
||||
allow_err!(peer.send(&fs::new_send(id, path, include_hidden)).await);
|
||||
} else {
|
||||
match fs::TransferJob::new_read(id, path.clone(), include_hidden, od) {
|
||||
match fs::TransferJob::new_read(id, path.clone(),to.clone(),include_hidden,is_remote, include_hidden, od) {
|
||||
Err(err) => {
|
||||
self.handle_job_status(id, -1, Some(err.to_string()));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user