fix: remote printer (#11270)

* fix: remote printer, log

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix: remote printer, avoid double sign

Signed-off-by: fufesou <linlong1266@gmail.com>

* Spawn a new thread to handle the print job.

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-03-28 10:36:42 +08:00
committed by GitHub
parent f4bbf82363
commit ee2478168c
2 changed files with 32 additions and 19 deletions

View File

@@ -1550,21 +1550,32 @@ impl<T: InvokeUiSession> Remote<T> {
fs::JobType::Generic => {
self.handle_job_status(d.id, d.file_num, err);
}
fs::JobType::Printer =>
{
#[cfg(target_os = "windows")]
if let Some(data) = printer_data {
let printer_name = self
.handler
.printer_names
.write()
.unwrap()
.remove(&d.id);
crate::platform::send_raw_data_to_printer(
printer_name,
data,
)
.ok();
fs::JobType::Printer => {
if let Some(err) = err {
log::error!("Received printer job failed, error {err}");
} else {
log::info!(
"Received printer job done, data len: {:?}",
printer_data.as_ref().map(|d| d.len()).unwrap_or(0)
);
#[cfg(target_os = "windows")]
if let Some(data) = printer_data {
let printer_name = self
.handler
.printer_names
.write()
.unwrap()
.remove(&d.id);
// Spawn a new thread to handle the print job.
// Or print job will block the ui thread.
std::thread::spawn(move || {
crate::platform::send_raw_data_to_printer(
printer_name,
data,
)
.ok();
});
}
}
}
}

View File

@@ -2427,13 +2427,15 @@ impl Connection {
fs::DataSource::FilePath(PathBuf::from(&path));
}
JobType::Printer => {
if let Some(pd) =
self.printer_data.iter().find(|(_, p, _)| *p == path)
if let Some((_, _, data)) = self
.printer_data
.iter()
.position(|(_, p, _)| *p == path)
.map(|index| self.printer_data.remove(index))
{
data_source = fs::DataSource::MemoryCursor(
std::io::Cursor::new(pd.2.clone()),
std::io::Cursor::new(data),
);
self.printer_data.retain(|f| f.1 != path);
} else {
// Ignore this message if the printer data is not found
return true;