feat: remote printer (#11231)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -69,8 +69,6 @@ function getExt(name) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var jobIdCounter = 1;
|
||||
|
||||
class JobTable: Reactor.Component {
|
||||
this var jobs = [];
|
||||
this var job_map = {};
|
||||
@@ -126,8 +124,7 @@ class JobTable: Reactor.Component {
|
||||
}
|
||||
if (!to) return;
|
||||
to += handler.get_path_sep(!is_remote) + getFileName(is_remote, path);
|
||||
var id = jobIdCounter;
|
||||
jobIdCounter += 1;
|
||||
var id = handler.get_next_job_id();
|
||||
this.jobs.push({ type: "transfer",
|
||||
id: id, path: path, to: to,
|
||||
include_hidden: show_hidden,
|
||||
@@ -135,7 +132,7 @@ class JobTable: Reactor.Component {
|
||||
is_last: false
|
||||
});
|
||||
this.job_map[id] = this.jobs[this.jobs.length - 1];
|
||||
handler.send_files(id, path, to, 0, show_hidden, is_remote);
|
||||
handler.send_files(id, 0, path, to, 0, show_hidden, is_remote);
|
||||
var self = this;
|
||||
self.timer(30ms, function() { self.update(); });
|
||||
}
|
||||
@@ -147,8 +144,8 @@ class JobTable: Reactor.Component {
|
||||
is_remote: is_remote, is_last: true, file_num: file_num };
|
||||
this.jobs.push(job);
|
||||
this.job_map[id] = this.jobs[this.jobs.length - 1];
|
||||
jobIdCounter = id + 1;
|
||||
handler.add_job(id, path, to, file_num, show_hidden, is_remote);
|
||||
handler.update_next_job_id(id + 1);
|
||||
handler.add_job(id, 0, path, to, file_num, show_hidden, is_remote);
|
||||
stdout.println(JSON.stringify(job));
|
||||
}
|
||||
|
||||
@@ -162,16 +159,14 @@ class JobTable: Reactor.Component {
|
||||
}
|
||||
|
||||
function addDelDir(path, is_remote) {
|
||||
var id = jobIdCounter;
|
||||
jobIdCounter += 1;
|
||||
var id = handler.get_next_job_id();
|
||||
this.jobs.push({ type: "del-dir", id: id, path: path, is_remote: is_remote });
|
||||
this.job_map[id] = this.jobs[this.jobs.length - 1];
|
||||
this.update();
|
||||
}
|
||||
|
||||
function addDelFile(path, is_remote) {
|
||||
var id = jobIdCounter;
|
||||
jobIdCounter += 1;
|
||||
var id = handler.get_next_job_id();
|
||||
this.jobs.push({ type: "del-file", id: id, path: path, is_remote: is_remote });
|
||||
this.job_map[id] = this.jobs[this.jobs.length - 1];
|
||||
this.update();
|
||||
@@ -552,9 +547,9 @@ class FolderView : Reactor.Component {
|
||||
return;
|
||||
}
|
||||
var path = me.joinPath(name);
|
||||
handler.create_dir(jobIdCounter, path, me.is_remote);
|
||||
create_dir_jobs[jobIdCounter] = { is_remote: me.is_remote, path: path };
|
||||
jobIdCounter += 1;
|
||||
var id = handler.get_next_job_id();
|
||||
handler.create_dir(id, path, me.is_remote);
|
||||
create_dir_jobs[id] = { is_remote: me.is_remote, path: path };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -317,6 +317,9 @@ class MsgboxComponent: Reactor.Component {
|
||||
if (this.type == "multiple-sessions-nocancel") {
|
||||
values.sid = (this.$$(select))[0].value;
|
||||
}
|
||||
if (this.type == "remote-printer-selector") {
|
||||
values.name = (this.$$(select))[0].value;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
41
src/ui/printer.tis
Normal file
41
src/ui/printer.tis
Normal file
@@ -0,0 +1,41 @@
|
||||
include "sciter:reactor.tis";
|
||||
|
||||
handler.printerRequest = function(id, path) {
|
||||
show_printer_selector(id, path);
|
||||
};
|
||||
|
||||
function show_printer_selector(id, path)
|
||||
{
|
||||
var names = handler.get_printer_names();
|
||||
msgbox("remote-printer-selector", "Incoming Print Job", <PrinterComponent names={names} />, "", function(res=null) {
|
||||
if (res && res.name) {
|
||||
handler.on_printer_selected(id, path, res.name);
|
||||
}
|
||||
}, 180);
|
||||
}
|
||||
|
||||
class PrinterComponent extends Reactor.Component {
|
||||
this var names = [];
|
||||
this var jobTip = translate("print-incoming-job-confirm-tip");
|
||||
|
||||
function this(params) {
|
||||
if (params && params.names) {
|
||||
this.names = params.names;
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
return <div>
|
||||
<div>{translate("print-incoming-job-confirm-tip")}</div>
|
||||
<div style="margin-top: 1em;" />
|
||||
<div>
|
||||
<select style="width: 450; margin: 1em 0; font-size: 1.15em;">
|
||||
{this.names.map(function(name) {
|
||||
return <option value={name}>{name}</option>;
|
||||
})}
|
||||
</select>
|
||||
</div>
|
||||
<div style="margin-top: 1em;" />
|
||||
</div>;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
include "port_forward.tis";
|
||||
include "grid.tis";
|
||||
include "header.tis";
|
||||
include "printer.tis";
|
||||
</script>
|
||||
</head>
|
||||
<header>
|
||||
|
||||
@@ -379,6 +379,10 @@ impl InvokeUiSession for SciterHandler {
|
||||
fn update_record_status(&self, start: bool) {
|
||||
self.call("updateRecordStatus", &make_args!(start));
|
||||
}
|
||||
|
||||
fn printer_request(&self, id: i32, path: String) {
|
||||
self.call("printerRequest", &make_args!(id, path));
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SciterSession(Session<SciterHandler>);
|
||||
@@ -491,6 +495,8 @@ impl sciter::EventHandler for SciterSession {
|
||||
fn get_chatbox();
|
||||
fn get_icon();
|
||||
fn get_home_dir();
|
||||
fn get_next_job_id();
|
||||
fn update_next_job_id(i32);
|
||||
fn read_dir(String, bool);
|
||||
fn remove_dir(i32, String, bool);
|
||||
fn create_dir(i32, String, bool);
|
||||
@@ -502,8 +508,8 @@ impl sciter::EventHandler for SciterSession {
|
||||
fn confirm_delete_files(i32, i32);
|
||||
fn set_no_confirm(i32);
|
||||
fn cancel_job(i32);
|
||||
fn send_files(i32, String, String, i32, bool, bool);
|
||||
fn add_job(i32, String, String, i32, bool, bool);
|
||||
fn send_files(i32, i32, String, String, i32, bool, bool);
|
||||
fn add_job(i32, i32, String, String, i32, bool, bool);
|
||||
fn resume_job(i32, bool);
|
||||
fn get_platform(bool);
|
||||
fn get_path_sep(bool);
|
||||
@@ -541,6 +547,8 @@ impl sciter::EventHandler for SciterSession {
|
||||
fn set_selected_windows_session_id(String);
|
||||
fn is_recording();
|
||||
fn has_file_clipboard();
|
||||
fn get_printer_names();
|
||||
fn on_printer_selected(i32, String, String);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -842,6 +850,22 @@ impl SciterSession {
|
||||
fn version_cmp(&self, v1: String, v2: String) -> i32 {
|
||||
(hbb_common::get_version_number(&v1) - hbb_common::get_version_number(&v2)) as i32
|
||||
}
|
||||
|
||||
fn get_printer_names(&self) -> Value {
|
||||
#[cfg(target_os = "windows")]
|
||||
let printer_names = crate::platform::windows::get_printer_names().unwrap_or_default();
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let printer_names: Vec<String> = vec![];
|
||||
let mut v = Value::array(0);
|
||||
for name in printer_names {
|
||||
v.push(name);
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
fn on_printer_selected(&self, id: i32, path: String, printer_name: String) {
|
||||
self.printer_response(id, path, printer_name);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_fd(id: i32, entries: &Vec<FileEntry>, only_count: bool) -> Value {
|
||||
|
||||
Reference in New Issue
Block a user