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)]
|
#[derive(Default)]
|
||||||
pub struct TransferJob {
|
pub struct TransferJob {
|
||||||
id: i32,
|
id: i32,
|
||||||
|
remote: String,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
|
show_hidden: bool,
|
||||||
|
is_remote: bool,
|
||||||
files: Vec<FileEntry>,
|
files: Vec<FileEntry>,
|
||||||
file_num: i32,
|
file_num: i32,
|
||||||
file: Option<File>,
|
file: Option<File>,
|
||||||
@ -217,7 +220,9 @@ pub struct TransferJob {
|
|||||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||||
pub struct TransferJobMeta {
|
pub struct TransferJobMeta {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub path: PathBuf,
|
pub remote: String,
|
||||||
|
pub to: String,
|
||||||
|
pub show_hidden: bool,
|
||||||
pub file_num: i32,
|
pub file_num: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +258,10 @@ fn is_compressed_file(name: &str) -> bool {
|
|||||||
impl TransferJob {
|
impl TransferJob {
|
||||||
pub fn new_write(
|
pub fn new_write(
|
||||||
id: i32,
|
id: i32,
|
||||||
|
remote: String,
|
||||||
path: String,
|
path: String,
|
||||||
|
show_hidden: bool,
|
||||||
|
is_remote: bool,
|
||||||
files: Vec<FileEntry>,
|
files: Vec<FileEntry>,
|
||||||
enable_override_detection: bool,
|
enable_override_detection: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -261,7 +269,10 @@ impl TransferJob {
|
|||||||
let total_size = files.iter().map(|x| x.size as u64).sum();
|
let total_size = files.iter().map(|x| x.size as u64).sum();
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
|
remote,
|
||||||
path: get_path(&path),
|
path: get_path(&path),
|
||||||
|
show_hidden,
|
||||||
|
is_remote,
|
||||||
files,
|
files,
|
||||||
total_size,
|
total_size,
|
||||||
enable_overwrite_detection: enable_override_detection,
|
enable_overwrite_detection: enable_override_detection,
|
||||||
@ -271,7 +282,10 @@ impl TransferJob {
|
|||||||
|
|
||||||
pub fn new_read(
|
pub fn new_read(
|
||||||
id: i32,
|
id: i32,
|
||||||
|
remote: String,
|
||||||
path: String,
|
path: String,
|
||||||
|
show_hidden: bool,
|
||||||
|
is_remote: bool,
|
||||||
include_hidden: bool,
|
include_hidden: bool,
|
||||||
enable_override_detection: bool,
|
enable_override_detection: bool,
|
||||||
) -> ResultType<Self> {
|
) -> ResultType<Self> {
|
||||||
@ -280,7 +294,10 @@ impl TransferJob {
|
|||||||
let total_size = files.iter().map(|x| x.size as u64).sum();
|
let total_size = files.iter().map(|x| x.size as u64).sum();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id,
|
id,
|
||||||
|
remote,
|
||||||
path: get_path(&path),
|
path: get_path(&path),
|
||||||
|
show_hidden,
|
||||||
|
is_remote,
|
||||||
files,
|
files,
|
||||||
total_size,
|
total_size,
|
||||||
enable_overwrite_detection: enable_override_detection,
|
enable_overwrite_detection: enable_override_detection,
|
||||||
@ -561,8 +578,10 @@ impl TransferJob {
|
|||||||
pub fn gen_meta(&self) -> TransferJobMeta {
|
pub fn gen_meta(&self) -> TransferJobMeta {
|
||||||
TransferJobMeta {
|
TransferJobMeta {
|
||||||
id: self.id,
|
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,
|
file_num: self.file_num,
|
||||||
|
show_hidden: self.show_hidden
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -974,7 +974,7 @@ impl Connection {
|
|||||||
let id = s.id;
|
let id = s.id;
|
||||||
let od =
|
let od =
|
||||||
can_enable_overwrite_detection(get_version_number(VERSION));
|
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) => {
|
Err(err) => {
|
||||||
self.send(fs::new_error(id, err, 0)).await;
|
self.send(fs::new_error(id, err, 0)).await;
|
||||||
}
|
}
|
||||||
|
@ -161,9 +161,13 @@ impl ConnectionManager {
|
|||||||
mut files,
|
mut files,
|
||||||
} => {
|
} => {
|
||||||
let od = can_enable_overwrite_detection(get_version_number(VERSION));
|
let od = can_enable_overwrite_detection(get_version_number(VERSION));
|
||||||
|
// cm has no show_hidden context
|
||||||
write_jobs.push(fs::TransferJob::new_write(
|
write_jobs.push(fs::TransferJob::new_write(
|
||||||
id,
|
id,
|
||||||
|
"".to_string(),
|
||||||
path,
|
path,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
files
|
files
|
||||||
.drain(..)
|
.drain(..)
|
||||||
.map(|f| FileEntry {
|
.map(|f| FileEntry {
|
||||||
|
@ -100,6 +100,12 @@ class JobTable: Reactor.Component {
|
|||||||
refreshDir(is_remote);
|
refreshDir(is_remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearAllJobs() {
|
||||||
|
this.jobs = [];
|
||||||
|
this.job_map = {};
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
function send(path, is_remote) {
|
function send(path, is_remote) {
|
||||||
var to;
|
var to;
|
||||||
var show_hidden;
|
var show_hidden;
|
||||||
@ -124,6 +130,14 @@ class JobTable: Reactor.Component {
|
|||||||
self.timer(30ms, function() { self.update(); });
|
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) {
|
function addDelDir(path, is_remote) {
|
||||||
var id = jobIdCounter;
|
var id = jobIdCounter;
|
||||||
jobIdCounter += 1;
|
jobIdCounter += 1;
|
||||||
@ -649,6 +663,18 @@ handler.jobError = function(id, err, file_num = -1) {
|
|||||||
file_transfer.job_table.updateJobStatus(id, file_num, err);
|
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) {
|
function refreshDir(is_remote) {
|
||||||
if (is_remote) file_transfer.remote_folder_view.refreshDir();
|
if (is_remote) file_transfer.remote_folder_view.refreshDir();
|
||||||
else file_transfer.local_folder_view.refreshDir();
|
else file_transfer.local_folder_view.refreshDir();
|
||||||
|
@ -1388,6 +1388,10 @@ impl Remote {
|
|||||||
self.handler
|
self.handler
|
||||||
.call("setConnectionType", &make_args!(peer.is_secured(), direct));
|
.call("setConnectionType", &make_args!(peer.is_secured(), direct));
|
||||||
|
|
||||||
|
if conn_type == ConnType::FILE_TRANSFER {
|
||||||
|
self.load_last_jobs().await;
|
||||||
|
}
|
||||||
|
|
||||||
// just build for now
|
// just build for now
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
let (_tx_holder, mut rx_clip_client) = mpsc::unbounded_channel::<i32>();
|
let (_tx_holder, mut rx_clip_client) = mpsc::unbounded_channel::<i32>();
|
||||||
@ -1537,6 +1541,36 @@ impl Remote {
|
|||||||
Some(tx)
|
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 {
|
async fn handle_msg_from_ui(&mut self, data: Data, peer: &mut Stream) -> bool {
|
||||||
// log::info!("new msg from ui, {}",data);
|
// log::info!("new msg from ui, {}",data);
|
||||||
match data {
|
match data {
|
||||||
@ -1560,10 +1594,10 @@ impl Remote {
|
|||||||
if is_remote {
|
if is_remote {
|
||||||
log::debug!("New job {}, write to {} from remote {}", id, to, path);
|
log::debug!("New job {}, write to {} from remote {}", id, to, path);
|
||||||
self.write_jobs
|
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);
|
allow_err!(peer.send(&fs::new_send(id, path, include_hidden)).await);
|
||||||
} else {
|
} 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) => {
|
Err(err) => {
|
||||||
self.handle_job_status(id, -1, Some(err.to_string()));
|
self.handle_job_status(id, -1, Some(err.to_string()));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user