fix: to string
This commit is contained in:
parent
b3f523f65e
commit
77bb821ecf
@ -157,11 +157,9 @@ pub struct PeerInfoSerde {
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct TransferSerde {
|
||||
#[serde(default)]
|
||||
pub write_jobs: Vec<TransferJobMeta>,
|
||||
pub write_jobs: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub read_jobs: Vec<TransferJobMeta>,
|
||||
#[serde(default)]
|
||||
pub remove_jobs: Vec<RemoveJobMeta>,
|
||||
pub read_jobs: Vec<String>,
|
||||
}
|
||||
|
||||
fn patch(path: PathBuf) -> PathBuf {
|
||||
|
@ -229,6 +229,8 @@ pub struct TransferJobMeta {
|
||||
pub show_hidden: bool,
|
||||
#[serde(default)]
|
||||
pub file_num: i32,
|
||||
#[serde(default)]
|
||||
pub is_remote: bool
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
@ -583,13 +585,15 @@ impl TransferJob {
|
||||
true
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn gen_meta(&self) -> TransferJobMeta {
|
||||
TransferJobMeta {
|
||||
id: self.id,
|
||||
remote: self.remote.to_string(),
|
||||
to: self.path.to_string_lossy().to_string(),
|
||||
file_num: self.file_num,
|
||||
show_hidden: self.show_hidden
|
||||
show_hidden: self.show_hidden,
|
||||
is_remote: self.is_remote
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,12 +39,13 @@ fn main() {
|
||||
println!("{}", crate::VERSION);
|
||||
return;
|
||||
}
|
||||
#[cfg(not(feature = "inline"))]
|
||||
// TODO: 提交去除inline
|
||||
#[cfg(feature = "inline")]
|
||||
{
|
||||
use hbb_common::env_logger::*;
|
||||
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
|
||||
}
|
||||
#[cfg(feature = "inline")]
|
||||
#[cfg(not(feature = "inline"))]
|
||||
{
|
||||
let mut path = hbb_common::config::Config::log_path();
|
||||
if args.len() > 0 && args[0].starts_with("--") {
|
||||
|
@ -371,7 +371,6 @@ impl ConnectionManager {
|
||||
}
|
||||
|
||||
async fn send(msg: Message, conn: &mut Connection) {
|
||||
println!("send msg: {:?}", msg);
|
||||
match msg.write_to_bytes() {
|
||||
Ok(bytes) => allow_err!(conn.send(&Data::RawMessage(bytes)).await),
|
||||
err => allow_err!(err),
|
||||
|
@ -20,7 +20,7 @@ use clipboard::{
|
||||
get_rx_clip_client, server_clip_file,
|
||||
};
|
||||
use enigo::{self, Enigo, KeyboardControllable};
|
||||
use hbb_common::config::TransferSerde;
|
||||
use hbb_common::{config::TransferSerde, fs::TransferJobMeta};
|
||||
use hbb_common::fs::{
|
||||
can_enable_overwrite_detection, get_string, is_file_exists, new_send_confirm,
|
||||
DigestCheckResult, RemoveJobMeta,
|
||||
@ -1319,7 +1319,6 @@ async fn io_loop(handler: Handler) {
|
||||
clipboard_file_context: None,
|
||||
};
|
||||
remote.io_loop(&key, &token).await;
|
||||
remote.sync_jobs_status_to_local().await;
|
||||
}
|
||||
|
||||
struct RemoveJob {
|
||||
@ -1551,23 +1550,29 @@ impl Remote {
|
||||
}
|
||||
// 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_str in pc.transfer.read_jobs.iter() {
|
||||
let job: Result<TransferJobMeta, serde_json::Error> = serde_json::from_str(&job_str);
|
||||
if let Ok(job) = job {
|
||||
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);
|
||||
for job_str in pc.transfer.write_jobs.iter() {
|
||||
let job: Result<TransferJobMeta, serde_json::Error> = serde_json::from_str(&job_str);
|
||||
if let Ok(job) = job {
|
||||
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!());
|
||||
}
|
||||
@ -1595,7 +1600,7 @@ 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, path.clone(),to,include_hidden,is_remote, 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(),to.clone(),include_hidden,is_remote, include_hidden, od) {
|
||||
@ -1837,13 +1842,12 @@ impl Remote {
|
||||
let mut config: PeerConfig = self.handler.load_config();
|
||||
let mut transfer_metas = TransferSerde::default();
|
||||
for job in self.read_jobs.iter() {
|
||||
transfer_metas.read_jobs.push(job.gen_meta());
|
||||
let json_str = serde_json::to_string(&job.gen_meta()).unwrap();
|
||||
transfer_metas.read_jobs.push(json_str);
|
||||
}
|
||||
for job in self.write_jobs.iter() {
|
||||
transfer_metas.write_jobs.push(job.gen_meta());
|
||||
}
|
||||
for job in self.remove_jobs.values() {
|
||||
transfer_metas.remove_jobs.push(job.gen_meta());
|
||||
let json_str = serde_json::to_string(&job.gen_meta()).unwrap();
|
||||
transfer_metas.write_jobs.push(json_str);
|
||||
}
|
||||
config.transfer = transfer_metas;
|
||||
println!("{:?}", config.transfer);
|
||||
|
Loading…
Reference in New Issue
Block a user