feat: remote printer (#11231)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-03-27 15:34:27 +08:00
committed by GitHub
parent 1cb53c1f7a
commit f4bbf82363
101 changed files with 3707 additions and 211 deletions

View File

@@ -624,7 +624,15 @@ pub fn session_send_files(
_is_dir: bool,
) {
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
session.send_files(act_id, path, to, file_num, include_hidden, is_remote);
session.send_files(
act_id,
fs::JobType::Generic.into(),
path,
to,
file_num,
include_hidden,
is_remote,
);
}
}
@@ -749,7 +757,15 @@ pub fn session_add_job(
is_remote: bool,
) {
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
session.add_job(act_id, path, to, file_num, include_hidden, is_remote);
session.add_job(
act_id,
fs::JobType::Generic.into(),
path,
to,
file_num,
include_hidden,
is_remote,
);
}
}
@@ -1668,6 +1684,17 @@ pub fn session_toggle_virtual_display(session_id: SessionID, index: i32, on: boo
}
}
pub fn session_printer_response(
session_id: SessionID,
id: i32,
path: String,
printer_name: String,
) {
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
session.printer_response(id, path, printer_name);
}
}
pub fn main_set_home_dir(_home: String) {
#[cfg(any(target_os = "android", target_os = "ios"))]
{
@@ -2362,6 +2389,68 @@ pub fn main_audio_support_loopback() -> SyncReturn<bool> {
SyncReturn(is_surpport)
}
pub fn main_get_printer_names() -> SyncReturn<String> {
#[cfg(target_os = "windows")]
return SyncReturn(
serde_json::to_string(&crate::platform::windows::get_printer_names().unwrap_or_default())
.unwrap_or_default(),
);
#[cfg(not(target_os = "windows"))]
return SyncReturn("".to_owned());
}
pub fn main_get_common(key: String) -> String {
if key == "is-printer-installed" {
#[cfg(target_os = "windows")]
{
return match remote_printer::is_rd_printer_installed(&get_app_name()) {
Ok(r) => r.to_string(),
Err(e) => e.to_string(),
};
}
#[cfg(not(target_os = "windows"))]
return false.to_string();
} else if key == "is-support-printer-driver" {
#[cfg(target_os = "windows")]
return crate::platform::is_win_10_or_greater().to_string();
#[cfg(not(target_os = "windows"))]
return false.to_string();
} else if key == "transfer-job-id" {
return hbb_common::fs::get_next_job_id().to_string();
} else {
"".to_owned()
}
}
pub fn main_get_common_sync(key: String) -> SyncReturn<String> {
SyncReturn(main_get_common(key))
}
pub fn main_set_common(_key: String, _value: String) {
#[cfg(target_os = "windows")]
if _key == "install-printer" && crate::platform::is_win_10_or_greater() {
std::thread::spawn(move || {
let (success, msg) = match remote_printer::install_update_printer(&get_app_name()) {
Ok(_) => (true, "".to_owned()),
Err(e) => {
let err = e.to_string();
log::error!("Failed to install/update rd printer: {}", &err);
(false, err)
}
};
let data = HashMap::from([
("name", serde_json::json!("install-printer-res")),
("success", serde_json::json!(success)),
("msg", serde_json::json!(msg)),
]);
let _res = flutter::push_global_event(
flutter::APP_TYPE_MAIN,
serde_json::ser::to_string(&data).unwrap_or("".to_owned()),
);
});
}
}
#[cfg(target_os = "android")]
pub mod server_side {
use hbb_common::{config, log};