Merge branch 'rustdesk:master' into master

This commit is contained in:
Arash Hatami
2021-11-14 18:52:51 +03:30
committed by GitHub
21 changed files with 443 additions and 109 deletions

View File

@@ -1,6 +1,6 @@
pub use arboard::Clipboard as ClipboardContext;
use hbb_common::{
allow_err,
allow_err, bail,
compress::{compress as compress_func, decompress},
config::{Config, COMPRESS_LEVEL, RENDEZVOUS_TIMEOUT},
log,
@@ -240,6 +240,10 @@ async fn test_nat_type_() -> ResultType<bool> {
let rendezvous_server = get_rendezvous_server(100).await;
let server1 = rendezvous_server;
let mut server2 = server1;
if server1.port() == 0 { // offline
// avoid overflow crash
bail!("Offline");
}
server2.set_port(server1.port() - 1);
let mut msg_out = RendezvousMessage::new();
let serial = Config::get_serial();

View File

@@ -285,6 +285,7 @@ impl RendezvousMediator {
let mut msg_out = Message::new();
let mut rr = RelayResponse {
socket_addr,
version: crate::VERSION.to_owned(),
..Default::default()
};
if initiate {
@@ -321,6 +322,7 @@ impl RendezvousMediator {
socket_addr: AddrMangle::encode(peer_addr),
local_addr: AddrMangle::encode(local_addr),
relay_server,
version: crate::VERSION.to_owned(),
..Default::default()
});
let bytes = msg_out.write_to_bytes()?;
@@ -359,6 +361,7 @@ impl RendezvousMediator {
id: Config::get_id(),
relay_server,
nat_type: nat_type.into(),
version: crate::VERSION.to_owned(),
..Default::default()
});
let bytes = msg_out.write_to_bytes()?;

View File

@@ -3,49 +3,102 @@ pub use crate::common::{
check_clipboard, ClipboardContext, CLIPBOARD_INTERVAL as INTERVAL, CLIPBOARD_NAME as NAME,
CONTENT,
};
struct State {
ctx: Option<ClipboardContext>,
}
impl Default for State {
fn default() -> Self {
let ctx = match ClipboardContext::new() {
Ok(ctx) => Some(ctx),
Err(err) => {
log::error!("Failed to start {}: {}", NAME, err);
None
}
};
Self { ctx }
}
}
impl super::service::Reset for State {
fn reset(&mut self) {
*CONTENT.lock().unwrap() = Default::default();
}
}
use clipboard_master::{CallbackResult, ClipboardHandler, Master};
use hbb_common::{anyhow, ResultType};
use std::{
io, sync,
sync::{
atomic::{AtomicBool, Ordering},
mpsc::SyncSender,
},
time::Duration,
};
pub fn new() -> GenericService {
let sp = GenericService::new(NAME, true);
sp.repeat::<State, _>(INTERVAL, run);
sp.run::<_>(listen::run);
sp
}
fn run(sp: GenericService, state: &mut State) -> ResultType<()> {
if let Some(ctx) = state.ctx.as_mut() {
if let Some(msg) = check_clipboard(ctx, None) {
sp.send(msg);
}
sp.snapshot(|sps| {
let txt = crate::CONTENT.lock().unwrap().clone();
if !txt.is_empty() {
let msg_out = crate::create_clipboard_msg(txt);
sps.send_shared(Arc::new(msg_out));
}
Ok(())
})?;
mod listen {
use super::*;
static RUNNING: AtomicBool = AtomicBool::new(true);
static WAIT: Duration = Duration::from_millis(1500);
struct ClipHandle {
tx: SyncSender<()>,
}
impl ClipboardHandler for ClipHandle {
fn on_clipboard_change(&mut self) -> CallbackResult {
if !RUNNING.load(Ordering::SeqCst) {
return CallbackResult::Stop;
}
let _ = self.tx.send(());
CallbackResult::Next
}
fn on_clipboard_error(&mut self, error: io::Error) -> CallbackResult {
if !RUNNING.load(Ordering::SeqCst) {
CallbackResult::Stop
} else {
CallbackResult::StopWithError(error)
}
}
}
#[tokio::main]
pub async fn run(sp: GenericService) -> ResultType<()> {
let mut ctx = match ClipboardContext::new() {
Ok(ctx) => ctx,
Err(err) => {
log::error!("Failed to start {}: {}", NAME, err);
return Err(anyhow::Error::from(err));
}
};
if !RUNNING.load(Ordering::SeqCst) {
RUNNING.store(true, Ordering::SeqCst);
}
let (tx, rx) = sync::mpsc::sync_channel(12);
let listener = tokio::spawn(async {
log::info!("Clipboard listener running!");
let _ = Master::new(ClipHandle { tx }).run();
});
while sp.ok() {
if let Ok(_) = rx.recv_timeout(WAIT) {
if let Some(msg) = check_clipboard(&mut ctx, None) {
sp.send(msg);
}
}
sp.snapshot(|sps| {
let txt = crate::CONTENT.lock().unwrap().clone();
if !txt.is_empty() {
let msg_out = crate::create_clipboard_msg(txt);
sps.send_shared(Arc::new(msg_out));
}
Ok(())
})?;
}
RUNNING.store(false, Ordering::SeqCst);
trigger(&mut ctx);
let _ = listener.await;
log::info!("Clipboard listener stopped!");
*CONTENT.lock().unwrap() = Default::default();
Ok(())
}
fn trigger(ctx: &mut ClipboardContext) {
let _ = match ctx.get_text() {
Ok(text) => ctx.set_text(text),
Err(_) => ctx.set_text(Default::default()),
};
}
Ok(())
}

View File

@@ -333,9 +333,21 @@ impl UI {
}
}
}
*self.2.lock().unwrap() = m.clone();
ipc::set_options(m).ok();
}
fn set_option(&self, key: String, value: String) {
let mut options = self.2.lock().unwrap();
if value.is_empty() {
options.remove(&key);
} else {
options.insert(key, value);
}
ipc::set_options(options.clone()).ok();
}
fn install_path(&mut self) -> String {
#[cfg(windows)]
return crate::platform::windows::get_install_info().1;
@@ -587,6 +599,7 @@ impl sciter::EventHandler for UI {
fn test_if_valid_server(String);
fn get_sound_inputs();
fn set_options(Value);
fn set_option(String, String);
fn get_software_update_url();
fn get_new_version();
fn get_version();

View File

@@ -257,6 +257,10 @@ handler.msgbox = function(type, title, text, callback=null, height=180, width=50
self.timer(150ms, function() { msgbox(type, title, text, callback, height, width, retry); });
}
handler.block_msgbox = function(type, title, text, callback=null, height=180, width=500, retry=0) {
msgbox(type, title, text, callback, height, width, retry);
}
var reconnectTimeout = 1;
handler.msgbox_retry = function(type, title, text, hasRetry, callback=null, height=180, width=500) {
handler.msgbox(type, title, text, callback, height, width, hasRetry ? reconnectTimeout : 0);

View File

@@ -30,6 +30,7 @@ table > thead {
}
table > tbody {
behavior: select-multiple;
overflow-y: scroll-indicator;
size: *;
background: white;
@@ -85,6 +86,15 @@ table.has_current tr:current /* current row */
background-color: color(accent);
}
table.has_current tbody tr:checked
{
background-color: color(accent);
}
table.has_current tbody tr:checked td {
color: highlighttext;
}
table td
{
padding: 4px;

View File

@@ -374,7 +374,7 @@ class FolderView : Reactor.Component {
path = this.joinPath(entry.name);
}
var tm = entry.time ? new Date(entry.time.toFloat() * 1000.).toLocaleString() : 0;
return <tr>
return <tr role="option">
<td type={entry.type} filename={path}></td>
<td>{entry.name}</td>
<td value={entry.time || 0}>{tm || ""}</td>
@@ -401,20 +401,31 @@ class FolderView : Reactor.Component {
}
event click $(.trash) () {
var row = this.getCurrentRow();
if (!row) return;
var path = row[0];
var type = row[1];
var new_history = [];
for (var i = 0; i < this.history.length; ++i) {
var h = this.history[i];
if ((h + this.sep()).indexOf(path + this.sep()) == -1) new_history.push(h);
var rows = this.getCurrentRows();
if (!rows || rows.length == 0) return;
var delete_dirs = new Array();
for (var i = 0; i < rows.length; ++i) {
var row = rows[i];
var path = row[0];
var type = row[1];
var new_history = [];
for (var j = 0; j < this.history.length; ++j) {
var h = this.history[j];
if ((h + this.sep()).indexOf(path + this.sep()) == -1) new_history.push(h);
}
this.history = new_history;
if (type == 1) {
delete_dirs.push(path);
} else {
confirmDelete(path, this.is_remote);
}
}
this.history = new_history;
if (type == 1) {
file_transfer.job_table.addDelDir(path, this.is_remote);
} else {
confirmDelete(path, this.is_remote);
for (var i = 0; i < delete_dirs.length; ++i) {
file_transfer.job_table.addDelDir(delete_dirs[i], this.is_remote);
}
}
@@ -463,10 +474,28 @@ class FolderView : Reactor.Component {
return [this.joinPath(name), type];
}
function getCurrentRows() {
var rows = this.table.getCurrentRows();
if (!rows || rows.length== 0) return;
var records = new Array();
for (var i = 0; i < rows.length; ++i) {
var name = rows[i][1].text;
if (!name || name == "..") continue;
var type = rows[i][0].attributes["type"];
records.push([this.joinPath(name), type]);
}
return records;
}
event click $(.send) () {
var cur = this.getCurrentRow();
if (!cur) return;
file_transfer.job_table.send(cur[0], this.is_remote);
var rows = this.getCurrentRows();
if (!rows || rows.length == 0) return;
for (var i = 0; i < rows.length; ++i) {
file_transfer.job_table.send(rows[i][0], this.is_remote);
}
}
event change $(.select-dir) (_, el) {
@@ -570,7 +599,7 @@ var deleting_single_file_jobs = {};
var create_dir_jobs = {}
function confirmDelete(path, is_remote) {
handler.msgbox("custom-skip", "Confirm Delete", "<div .form> \
handler.block_msgbox("custom-skip", "Confirm Delete", "<div .form> \
<div>Are you sure you want to delete this file?</div> \
<div.ellipsis style=\"font-weight: bold;\">" + path + "</div> \
</div>", function(res=null) {
@@ -590,7 +619,7 @@ handler.confirmDeleteFiles = function(id, i, name) {
if (i >= n) return;
var file_path = job.path;
if (name) file_path += handler.get_path_sep(job.is_remote) + name;
handler.msgbox("custom-skip", "Confirm Delete", "<div .form> \
handler.block_msgbox("custom-skip", "Confirm Delete", "<div .form> \
<div>Deleting #" + (i + 1) + " of " + n + " files.</div> \
<div>Are you sure you want to delete this file?</div> \
<div.ellipsis style=\"font-weight: bold;\" .text>" + name + "</div> \

View File

@@ -24,6 +24,11 @@ class Grid: Behavior {
{
return this.$(tbody>tr:current);
}
function getCurrentRows()
{
return this.$$(tbody>tr:checked);
}
function getCurrentColumn()
{

View File

@@ -40,9 +40,7 @@ class ConnectStatus: Reactor.Component {
}
event click $(.connect-status .link) () {
var options = handler.get_options();
options["stop-service"] = "";
handler.set_options(options);
handler.set_option("stop-service", "");
}
}
@@ -138,7 +136,6 @@ function createNewConnect(id, type) {
var myIdMenu;
var audioInputMenu;
var configOptions = {};
class AudioInputs: Reactor.Component {
function this() {
audioInputMenu = this;
@@ -167,7 +164,7 @@ class AudioInputs: Reactor.Component {
}
function get_value() {
return configOptions["audio-input"] || this.get_default();
return handler.get_option("audio-input") || this.get_default();
}
function toggleMenuState() {
@@ -182,8 +179,7 @@ class AudioInputs: Reactor.Component {
var v = me.id;
if (v == this.get_value()) return;
if (v == this.get_default()) v = "";
configOptions["audio-input"] = v;
handler.set_options(configOptions);
handler.set_option("audio-input", v);
this.toggleMenuState();
}
}
@@ -223,7 +219,6 @@ class MyIdMenu: Reactor.Component {
event click $(svg#menu) (_, me) {
audioInputMenu.update({ show: true });
configOptions = handler.get_options();
this.toggleMenuState();
var menu = $(menu#config-options);
me.popup(menu);
@@ -232,7 +227,7 @@ class MyIdMenu: Reactor.Component {
function toggleMenuState() {
for (var el in $$(menu#config-options>li)) {
if (el.id && el.id.indexOf("enable-") == 0) {
var enabled = configOptions[el.id] != "N";
var enabled = handler.get_option(el.id) != "N";
el.attributes.toggleClass("selected", enabled);
el.attributes.toggleClass("line-through", !enabled);
}
@@ -241,11 +236,10 @@ class MyIdMenu: Reactor.Component {
event click $(menu#config-options>li) (_, me) {
if (me.id && me.id.indexOf("enable-") == 0) {
configOptions[me.id] = configOptions[me.id] == "N" ? "" : "N";
handler.set_options(configOptions);
handler.set_option(me.id, handler.get_option(me.id) == "N" ? "" : "N");
}
if (me.id == "whitelist") {
var old_value = (configOptions["whitelist"] || "").split(",").join("\n");
var old_value = handler.get_option("whitelist").split(",").join("\n");
handler.msgbox("custom-whitelist", "IP Whitelisting", "<div .form> \
<textarea spellcheck=\"false\" name=\"text\" novalue=\"0.0.0.0\" style=\"overflow: scroll-indicator; height: 160px; font-size: 1.2em; padding: 0.5em;\">" + old_value + "</textarea>\
</div> \
@@ -253,7 +247,7 @@ class MyIdMenu: Reactor.Component {
if (!res) return;
var value = (res.text || "").trim();
if (value) {
var values = value.split(/[\s,;]+/g);
var values = value.split(/[\s,;\n]+/g);
for (var ip in values) {
if (!ip.match(/^\d+\.\d+\.\d+\.\d+$/)) {
return "Invalid ip: " + ip;
@@ -262,11 +256,11 @@ class MyIdMenu: Reactor.Component {
value = values.join("\n");
}
if (value == old_value) return;
configOptions["whitelist"] = value.replace("\n", ",");
stdout.println("whitelist updated");
handler.set_options(configOptions);
handler.set_option("whitelist", value.replace("\n", ","));
}, 300);
} else if (me.id == "custom-server") {
var configOptions = handler.get_options();
var old_relay = configOptions["relay-server"] || "";
var old_id = configOptions["custom-rendezvous-server"] || "";
handler.msgbox("custom-server", "ID/Relay Server", "<div .form> \
@@ -293,8 +287,7 @@ class MyIdMenu: Reactor.Component {
} else if (me.id == "forum") {
handler.open_url("https:://forum.rustdesk.com");
} else if (me.id == "stop-service") {
configOptions["stop-service"] = service_stopped ? "" : "Y";
handler.set_options(configOptions);
handler.set_option("stop-service", service_stopped ? "" : "Y");
} else if (me.id == "about") {
var name = handler.get_app_name();
handler.msgbox("custom-nocancel-nook-hasclose", "About " + name, "<div style='line-height: 2em'> \