add file log page to cm

* Only send and receive logs are shown
* For older version, client send to server doesn't have size information, because server side doesn't know the total_size
* Not switch tabs automatically when new files are transferred
* If cm side page is open, not pop up automatically when new files are transferred
* Show unread message count
* The cm tab remains open when closed if a file transfer has previously occurred

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-09-06 16:56:39 +08:00
parent e88e17a4b0
commit 2afce3f1f4
14 changed files with 519 additions and 39 deletions

View File

@@ -99,6 +99,8 @@ pub trait InvokeUiCM: Send + Clone + 'static + Sized {
fn show_elevation(&self, show: bool);
fn update_voice_call_state(&self, client: &Client);
fn file_transfer_log(&self, log: String);
}
impl<T: InvokeUiCM> Deref for ConnectionManager<T> {
@@ -357,6 +359,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
);
}
}
let (tx_log, mut rx_log) = mpsc::unbounded_channel::<String>();
self.running = false;
loop {
@@ -403,11 +406,16 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
if let ipc::FS::WriteBlock { id, file_num, data: _, compressed } = fs {
if let Ok(bytes) = self.stream.next_raw().await {
fs = ipc::FS::WriteBlock{id, file_num, data:bytes.into(), compressed};
handle_fs(fs, &mut write_jobs, &self.tx).await;
handle_fs(fs, &mut write_jobs, &self.tx, Some(&tx_log)).await;
}
} else {
handle_fs(fs, &mut write_jobs, &self.tx).await;
handle_fs(fs, &mut write_jobs, &self.tx, Some(&tx_log)).await;
}
let log = fs::serialize_transfer_jobs(&write_jobs);
self.cm.ui_handler.file_transfer_log(log);
}
Data::FileTransferLog(log) => {
self.cm.ui_handler.file_transfer_log(log);
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Data::ClipboardFile(_clip) => {
@@ -509,6 +517,9 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
//
}
},
Some(job_log) = rx_log.recv() => {
self.cm.ui_handler.file_transfer_log(job_log);
}
}
}
}
@@ -632,7 +643,7 @@ pub async fn start_listen<T: InvokeUiCM>(
cm.new_message(current_id, text);
}
Some(Data::FS(fs)) => {
handle_fs(fs, &mut write_jobs, &tx).await;
handle_fs(fs, &mut write_jobs, &tx, None).await;
}
Some(Data::Close) => {
break;
@@ -647,7 +658,14 @@ pub async fn start_listen<T: InvokeUiCM>(
}
#[cfg(not(any(target_os = "ios")))]
async fn handle_fs(fs: ipc::FS, write_jobs: &mut Vec<fs::TransferJob>, tx: &UnboundedSender<Data>) {
async fn handle_fs(
fs: ipc::FS,
write_jobs: &mut Vec<fs::TransferJob>,
tx: &UnboundedSender<Data>,
tx_log: Option<&UnboundedSender<String>>,
) {
use hbb_common::fs::serialize_transfer_job;
match fs {
ipc::FS::ReadDir {
dir,
@@ -674,10 +692,12 @@ async fn handle_fs(fs: ipc::FS, write_jobs: &mut Vec<fs::TransferJob>, tx: &Unbo
file_num,
mut files,
overwrite_detection,
total_size,
conn_id,
} => {
// cm has no show_hidden context
// dummy remote, show_hidden, is_remote
write_jobs.push(fs::TransferJob::new_write(
let mut job = fs::TransferJob::new_write(
id,
"".to_string(),
path,
@@ -693,11 +713,17 @@ async fn handle_fs(fs: ipc::FS, write_jobs: &mut Vec<fs::TransferJob>, tx: &Unbo
})
.collect(),
overwrite_detection,
));
);
job.total_size = total_size;
job.conn_id = conn_id;
write_jobs.push(job);
}
ipc::FS::CancelWrite { id } => {
if let Some(job) = fs::get_job(id, write_jobs) {
job.remove_download_file();
tx_log.map(|tx: &UnboundedSender<String>| {
tx.send(serialize_transfer_job(job, false, true, ""))
});
fs::remove_job(id, write_jobs);
}
}
@@ -705,11 +731,13 @@ async fn handle_fs(fs: ipc::FS, write_jobs: &mut Vec<fs::TransferJob>, tx: &Unbo
if let Some(job) = fs::get_job(id, write_jobs) {
job.modify_time();
send_raw(fs::new_done(id, file_num), tx);
tx_log.map(|tx| tx.send(serialize_transfer_job(job, true, false, "")));
fs::remove_job(id, write_jobs);
}
}
ipc::FS::WriteError { id, file_num, err } => {
if let Some(job) = fs::get_job(id, write_jobs) {
tx_log.map(|tx| tx.send(serialize_transfer_job(job, false, false, &err)));
send_raw(fs::new_error(job.id(), err, file_num), tx);
fs::remove_job(job.id(), write_jobs);
}