2022-07-18 18:20:00 +08:00
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
iter::FromIterator,
|
2022-08-01 14:33:08 +08:00
|
|
|
process::Child,
|
2022-07-18 18:20:00 +08:00
|
|
|
sync::{Arc, Mutex},
|
|
|
|
};
|
|
|
|
|
|
|
|
use sciter::Value;
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
use hbb_common::{
|
|
|
|
allow_err,
|
2022-09-02 16:20:48 +08:00
|
|
|
config::{self, Config, PeerConfig, RENDEZVOUS_PORT, RENDEZVOUS_TIMEOUT},
|
2022-05-12 17:35:25 +08:00
|
|
|
futures::future::join_all,
|
|
|
|
log,
|
|
|
|
protobuf::Message as _,
|
|
|
|
rendezvous_proto::*,
|
|
|
|
tcp::FramedStream,
|
2022-11-19 10:57:17 +08:00
|
|
|
tokio,
|
2021-03-29 15:59:14 +08:00
|
|
|
};
|
2022-08-01 14:33:08 +08:00
|
|
|
|
2022-09-21 21:20:19 +08:00
|
|
|
use crate::common::get_app_name;
|
2022-08-02 13:10:09 +08:00
|
|
|
use crate::ipc;
|
2022-09-27 13:30:49 +08:00
|
|
|
use crate::ui_interface::*;
|
2022-08-01 14:33:08 +08:00
|
|
|
|
|
|
|
mod cm;
|
|
|
|
#[cfg(feature = "inline")]
|
2022-09-08 18:21:17 +08:00
|
|
|
pub mod inline;
|
2022-08-01 14:33:08 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
mod macos;
|
|
|
|
pub mod remote;
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
pub mod win_privacy;
|
2022-05-12 17:35:25 +08:00
|
|
|
|
|
|
|
type Message = RendezvousMessage;
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-11-10 21:25:12 +08:00
|
|
|
pub type Children = Arc<Mutex<(bool, HashMap<(String, String), Child>)>>;
|
|
|
|
#[allow(dead_code)]
|
2022-05-12 17:35:25 +08:00
|
|
|
type Status = (i32, bool, i64, String);
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-02-06 18:19:06 +08:00
|
|
|
lazy_static::lazy_static! {
|
|
|
|
// stupid workaround for https://sciter.com/forums/topic/crash-on-latest-tis-mac-sdk-sometimes/
|
|
|
|
static ref STUPID_VALUES: Mutex<Vec<Arc<Vec<Value>>>> = Default::default();
|
2022-05-25 23:09:14 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 22:36:34 +08:00
|
|
|
struct UIHostHandler;
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
pub fn start(args: &mut [String]) {
|
2022-04-28 21:54:27 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
2022-11-18 18:36:25 +08:00
|
|
|
macos::show_dock();
|
2022-04-18 15:45:12 +08:00
|
|
|
#[cfg(all(target_os = "linux", feature = "inline"))]
|
2022-05-29 10:14:22 +08:00
|
|
|
{
|
2022-06-09 17:30:26 +08:00
|
|
|
#[cfg(feature = "appimage")]
|
2022-05-29 10:14:22 +08:00
|
|
|
let prefix = std::env::var("APPDIR").unwrap_or("".to_string());
|
2022-06-09 17:30:26 +08:00
|
|
|
#[cfg(not(feature = "appimage"))]
|
|
|
|
let prefix = "".to_string();
|
2022-09-10 06:44:35 +08:00
|
|
|
#[cfg(feature = "flatpak")]
|
|
|
|
let dir = "/app";
|
|
|
|
#[cfg(not(feature = "flatpak"))]
|
|
|
|
let dir = "/usr";
|
|
|
|
sciter::set_library(&(prefix + dir + "/lib/rustdesk/libsciter-gtk.so")).ok();
|
2022-05-29 10:14:22 +08:00
|
|
|
}
|
2021-07-25 02:06:20 +08:00
|
|
|
// https://github.com/c-smile/sciter-sdk/blob/master/include/sciter-x-types.h
|
|
|
|
// https://github.com/rustdesk/rustdesk/issues/132#issuecomment-886069737
|
|
|
|
#[cfg(windows)]
|
|
|
|
allow_err!(sciter::set_options(sciter::RuntimeOptions::GfxLayer(
|
|
|
|
sciter::GFX_LAYER::WARP
|
|
|
|
)));
|
2022-05-12 17:35:25 +08:00
|
|
|
#[cfg(all(windows, not(feature = "inline")))]
|
|
|
|
unsafe {
|
|
|
|
winapi::um::shellscalingapi::SetProcessDpiAwareness(2);
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
use sciter::SCRIPT_RUNTIME_FEATURES::*;
|
|
|
|
allow_err!(sciter::set_options(sciter::RuntimeOptions::ScriptFeatures(
|
|
|
|
ALLOW_FILE_IO as u8 | ALLOW_SOCKET_IO as u8 | ALLOW_EVAL as u8 | ALLOW_SYSINFO as u8
|
|
|
|
)));
|
|
|
|
let mut frame = sciter::WindowBuilder::main_window().create();
|
|
|
|
#[cfg(windows)]
|
|
|
|
allow_err!(sciter::set_options(sciter::RuntimeOptions::UxTheming(true)));
|
2022-04-29 16:21:18 +08:00
|
|
|
frame.set_title(&crate::get_app_name());
|
2021-03-29 15:59:14 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
2022-04-29 16:21:18 +08:00
|
|
|
macos::make_menubar(frame.get_host(), args.is_empty());
|
2021-03-29 15:59:14 +08:00
|
|
|
let page;
|
|
|
|
if args.len() > 1 && args[0] == "--play" {
|
|
|
|
args[0] = "--connect".to_owned();
|
|
|
|
let path: std::path::PathBuf = (&args[1]).into();
|
|
|
|
let id = path
|
|
|
|
.file_stem()
|
|
|
|
.map(|p| p.to_str().unwrap_or(""))
|
|
|
|
.unwrap_or("")
|
|
|
|
.to_owned();
|
|
|
|
args[1] = id;
|
|
|
|
}
|
2022-04-29 16:21:18 +08:00
|
|
|
if args.is_empty() {
|
2022-11-10 21:25:12 +08:00
|
|
|
let children: Children = Default::default();
|
|
|
|
std::thread::spawn(move || check_zombie(children));
|
2021-03-29 15:59:14 +08:00
|
|
|
crate::common::check_software_update();
|
2022-05-25 23:09:14 +08:00
|
|
|
frame.event_handler(UI {});
|
2021-12-10 22:36:34 +08:00
|
|
|
frame.sciter_handler(UIHostHandler {});
|
2021-03-29 15:59:14 +08:00
|
|
|
page = "index.html";
|
|
|
|
} else if args[0] == "--install" {
|
2022-05-25 23:09:14 +08:00
|
|
|
frame.event_handler(UI {});
|
2021-12-10 22:36:34 +08:00
|
|
|
frame.sciter_handler(UIHostHandler {});
|
2021-03-29 15:59:14 +08:00
|
|
|
page = "install.html";
|
|
|
|
} else if args[0] == "--cm" {
|
|
|
|
frame.register_behavior("connection-manager", move || {
|
2022-09-05 19:41:09 +08:00
|
|
|
Box::new(cm::SciterConnectionManager::new())
|
2021-03-29 15:59:14 +08:00
|
|
|
});
|
|
|
|
page = "cm.html";
|
|
|
|
} else if (args[0] == "--connect"
|
|
|
|
|| args[0] == "--file-transfer"
|
|
|
|
|| args[0] == "--port-forward"
|
|
|
|
|| args[0] == "--rdp")
|
|
|
|
&& args.len() > 1
|
|
|
|
{
|
2022-05-12 17:35:25 +08:00
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
let hw = frame.get_host().get_hwnd();
|
|
|
|
crate::platform::windows::enable_lowlevel_keyboard(hw as _);
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
let mut iter = args.iter();
|
|
|
|
let cmd = iter.next().unwrap().clone();
|
|
|
|
let id = iter.next().unwrap().clone();
|
2022-07-27 00:31:20 +08:00
|
|
|
let pass = iter.next().unwrap_or(&"".to_owned()).clone();
|
2021-03-29 15:59:14 +08:00
|
|
|
let args: Vec<String> = iter.map(|x| x.clone()).collect();
|
|
|
|
frame.set_title(&id);
|
|
|
|
frame.register_behavior("native-remote", move || {
|
2022-12-09 21:16:09 +08:00
|
|
|
let handler = remote::SciterSession::new(
|
2022-07-27 00:31:20 +08:00
|
|
|
cmd.clone(),
|
|
|
|
id.clone(),
|
|
|
|
pass.clone(),
|
|
|
|
args.clone(),
|
2022-12-09 21:16:09 +08:00
|
|
|
);
|
2022-12-10 12:55:19 +08:00
|
|
|
#[cfg(not(feature = "flutter"))]
|
|
|
|
crate::keyboard::set_cur_session(handler.inner());
|
|
|
|
|
2022-12-09 21:16:09 +08:00
|
|
|
Box::new(handler)
|
2021-03-29 15:59:14 +08:00
|
|
|
});
|
|
|
|
page = "remote.html";
|
|
|
|
} else {
|
|
|
|
log::error!("Wrong command: {:?}", args);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#[cfg(feature = "inline")]
|
|
|
|
{
|
|
|
|
let html = if page == "index.html" {
|
|
|
|
inline::get_index()
|
|
|
|
} else if page == "cm.html" {
|
|
|
|
inline::get_cm()
|
|
|
|
} else if page == "install.html" {
|
|
|
|
inline::get_install()
|
|
|
|
} else {
|
|
|
|
inline::get_remote()
|
|
|
|
};
|
|
|
|
frame.load_html(html.as_bytes(), Some(page));
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "inline"))]
|
|
|
|
frame.load_file(&format!(
|
|
|
|
"file://{}/src/ui/{}",
|
|
|
|
std::env::current_dir()
|
|
|
|
.map(|c| c.display().to_string())
|
|
|
|
.unwrap_or("".to_owned()),
|
|
|
|
page
|
|
|
|
));
|
2022-04-29 16:21:18 +08:00
|
|
|
frame.run_app();
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-05-25 23:09:14 +08:00
|
|
|
struct UI {}
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-05-25 23:09:14 +08:00
|
|
|
impl UI {
|
|
|
|
fn recent_sessions_updated(&self) -> bool {
|
|
|
|
recent_sessions_updated()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn get_id(&self) -> String {
|
2022-08-01 14:33:08 +08:00
|
|
|
ipc::get_id()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-07-24 16:41:12 +08:00
|
|
|
fn temporary_password(&mut self) -> String {
|
2022-08-01 14:33:08 +08:00
|
|
|
temporary_password()
|
2022-07-24 16:41:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update_temporary_password(&self) {
|
2022-08-01 14:33:08 +08:00
|
|
|
update_temporary_password()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-07-24 16:41:12 +08:00
|
|
|
fn permanent_password(&self) -> String {
|
2022-08-01 14:33:08 +08:00
|
|
|
permanent_password()
|
2022-06-20 10:41:46 +08:00
|
|
|
}
|
|
|
|
|
2022-07-24 16:41:12 +08:00
|
|
|
fn set_permanent_password(&self, password: String) {
|
2022-08-01 20:42:30 +08:00
|
|
|
set_permanent_password(password);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_remote_id(&mut self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_remote_id()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn set_remote_id(&mut self, id: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
set_remote_id(id);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn goto_install(&mut self) {
|
2022-05-25 23:09:14 +08:00
|
|
|
goto_install();
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn install_me(&mut self, _options: String, _path: String) {
|
2022-06-27 11:50:15 +08:00
|
|
|
install_me(_options, _path, false, false);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update_me(&self, _path: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
update_me(_path);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn run_without_install(&self) {
|
2022-05-25 23:09:14 +08:00
|
|
|
run_without_install();
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn show_run_without_install(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
show_run_without_install()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn has_rendezvous_service(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
has_rendezvous_service()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_license(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_license()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_option(&self, key: String) -> String {
|
2022-05-25 23:22:14 +08:00
|
|
|
get_option(key)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2021-12-29 17:53:36 +08:00
|
|
|
fn get_local_option(&self, key: String) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_local_option(key)
|
2022-04-26 11:19:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn set_local_option(&self, key: String, value: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
set_local_option(key, value);
|
2021-12-29 17:53:36 +08:00
|
|
|
}
|
|
|
|
|
2022-01-02 15:09:44 +08:00
|
|
|
fn peer_has_password(&self, id: String) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
peer_has_password(id)
|
2022-01-02 15:09:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn forget_password(&self, id: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
forget_password(id)
|
2022-01-02 15:09:44 +08:00
|
|
|
}
|
|
|
|
|
2021-06-14 18:27:09 +08:00
|
|
|
fn get_peer_option(&self, id: String, name: String) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_peer_option(id, name)
|
2021-06-14 18:27:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn set_peer_option(&self, id: String, name: String, value: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
set_peer_option(id, name, value)
|
2021-06-14 18:27:09 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn using_public_server(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
using_public_server()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_options(&self) -> Value {
|
2022-07-18 18:20:00 +08:00
|
|
|
let hashmap: HashMap<String, String> = serde_json::from_str(&get_options()).unwrap();
|
2021-03-29 15:59:14 +08:00
|
|
|
let mut m = Value::map();
|
2022-05-25 23:09:14 +08:00
|
|
|
for (k, v) in hashmap {
|
2021-03-29 15:59:14 +08:00
|
|
|
m.set_item(k, v);
|
|
|
|
}
|
|
|
|
m
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_if_valid_server(&self, host: String) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
test_if_valid_server(host)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_sound_inputs(&self) -> Value {
|
2022-05-25 23:09:14 +08:00
|
|
|
Value::from_iter(get_sound_inputs())
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn set_options(&self, v: Value) {
|
|
|
|
let mut m = HashMap::new();
|
|
|
|
for (k, v) in v.items() {
|
|
|
|
if let Some(k) = k.as_string() {
|
|
|
|
if let Some(v) = v.as_string() {
|
|
|
|
if !v.is_empty() {
|
|
|
|
m.insert(k, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-25 23:09:14 +08:00
|
|
|
set_options(m);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2021-10-08 00:16:10 +08:00
|
|
|
fn set_option(&self, key: String, value: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
set_option(key, value);
|
2021-10-08 00:16:10 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn install_path(&mut self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
install_path()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-01-05 18:34:30 +08:00
|
|
|
fn get_socks(&self) -> Value {
|
2022-05-25 23:09:14 +08:00
|
|
|
Value::from_iter(get_socks())
|
2022-01-05 18:34:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn set_socks(&self, proxy: String, username: String, password: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
set_socks(proxy, username, password)
|
2022-01-05 18:34:30 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn is_installed(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_installed()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-27 13:30:49 +08:00
|
|
|
fn is_root(&self) -> bool {
|
|
|
|
is_root()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_release(&self) -> bool {
|
|
|
|
is_release()
|
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn is_rdp_service_open(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_rdp_service_open()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_share_rdp(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_share_rdp()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn set_share_rdp(&self, _enable: bool) {
|
2022-05-25 23:09:14 +08:00
|
|
|
set_share_rdp(_enable);
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn is_installed_lower_version(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_installed_lower_version()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-04-28 21:32:44 +08:00
|
|
|
fn closing(&mut self, x: i32, y: i32, w: i32, h: i32) {
|
2022-05-25 23:09:14 +08:00
|
|
|
closing(x, y, w, h)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_size(&mut self) -> Value {
|
2022-05-25 23:09:14 +08:00
|
|
|
Value::from_iter(get_size())
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn get_mouse_time(&self) -> f64 {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_mouse_time()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check_mouse_time(&self) {
|
2022-05-25 23:09:14 +08:00
|
|
|
check_mouse_time()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_connect_status(&mut self) -> Value {
|
|
|
|
let mut v = Value::array(0);
|
2022-05-25 23:09:14 +08:00
|
|
|
let x = get_connect_status();
|
2021-03-29 15:59:14 +08:00
|
|
|
v.push(x.0);
|
|
|
|
v.push(x.1);
|
2022-05-12 17:35:25 +08:00
|
|
|
v.push(x.3);
|
2021-03-29 15:59:14 +08:00
|
|
|
v
|
|
|
|
}
|
|
|
|
|
2022-01-02 21:56:04 +08:00
|
|
|
#[inline]
|
|
|
|
fn get_peer_value(id: String, p: PeerConfig) -> Value {
|
|
|
|
let values = vec![
|
|
|
|
id,
|
|
|
|
p.info.username.clone(),
|
|
|
|
p.info.hostname.clone(),
|
|
|
|
p.info.platform.clone(),
|
|
|
|
p.options.get("alias").unwrap_or(&"".to_owned()).to_owned(),
|
|
|
|
];
|
|
|
|
Value::from_iter(values)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_peer(&self, id: String) -> Value {
|
2022-05-25 23:09:14 +08:00
|
|
|
let c = get_peer(id.clone());
|
2022-01-02 21:56:04 +08:00
|
|
|
Self::get_peer_value(id, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_fav(&self) -> Value {
|
2022-05-25 23:09:14 +08:00
|
|
|
Value::from_iter(get_fav())
|
2022-01-02 21:56:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn store_fav(&self, fav: Value) {
|
|
|
|
let mut tmp = vec![];
|
|
|
|
fav.values().for_each(|v| {
|
|
|
|
if let Some(v) = v.as_string() {
|
|
|
|
if !v.is_empty() {
|
|
|
|
tmp.push(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-05-25 23:09:14 +08:00
|
|
|
store_fav(tmp);
|
2022-01-02 21:56:04 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_recent_sessions(&mut self) -> Value {
|
2022-04-26 11:19:45 +08:00
|
|
|
// to-do: limit number of recent sessions, and remove old peer file
|
2022-05-25 23:09:14 +08:00
|
|
|
let peers: Vec<Value> = get_recent_sessions()
|
2022-01-02 21:56:04 +08:00
|
|
|
.drain(..)
|
|
|
|
.map(|p| Self::get_peer_value(p.0, p.2))
|
2021-03-29 15:59:14 +08:00
|
|
|
.collect();
|
|
|
|
Value::from_iter(peers)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_icon(&mut self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_icon()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn remove_peer(&mut self, id: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
remove_peer(id)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-07-13 18:06:19 +08:00
|
|
|
fn remove_discovered(&mut self, id: String) {
|
|
|
|
let mut peers = config::LanPeers::load().peers;
|
|
|
|
peers.retain(|x| x.id != id);
|
|
|
|
config::LanPeers::store(&peers);
|
|
|
|
}
|
|
|
|
|
2022-07-14 10:34:56 +08:00
|
|
|
fn send_wol(&mut self, id: String) {
|
2022-07-15 20:39:42 +08:00
|
|
|
crate::lan::send_wol(id)
|
2022-07-14 10:34:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn new_remote(&mut self, id: String, remote_type: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
new_remote(id, remote_type)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_process_trusted(&mut self, _prompt: bool) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_process_trusted(_prompt)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_can_screen_recording(&mut self, _prompt: bool) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_can_screen_recording(_prompt)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 19:23:41 +08:00
|
|
|
fn is_installed_daemon(&mut self, _prompt: bool) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_installed_daemon(_prompt)
|
2022-01-13 19:23:41 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_error(&mut self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_error()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_login_wayland(&mut self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_login_wayland()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn fix_login_wayland(&mut self) {
|
2022-05-25 23:09:14 +08:00
|
|
|
fix_login_wayland()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2021-10-02 03:18:04 +08:00
|
|
|
|
2021-09-09 15:07:09 +08:00
|
|
|
fn current_is_wayland(&mut self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
current_is_wayland()
|
2021-09-09 15:07:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn modify_default_login(&mut self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
modify_default_login()
|
2021-09-09 15:07:09 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
|
|
|
|
fn get_software_update_url(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_software_update_url()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_new_version(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_new_version()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_version(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_version()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_app_name(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_app_name()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_software_ext(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_software_ext()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_software_store_path(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_software_store_path()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2021-07-27 23:53:12 +08:00
|
|
|
fn create_shortcut(&self, _id: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
create_shortcut(_id)
|
2021-06-14 17:51:45 +08:00
|
|
|
}
|
|
|
|
|
2022-01-12 03:10:15 +08:00
|
|
|
fn discover(&self) {
|
2022-08-02 13:10:09 +08:00
|
|
|
std::thread::spawn(move || {
|
|
|
|
allow_err!(crate::lan::discover());
|
|
|
|
});
|
2022-01-12 03:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_lan_peers(&self) -> String {
|
2022-10-26 21:40:22 +08:00
|
|
|
// let peers = get_lan_peers()
|
|
|
|
// .into_iter()
|
|
|
|
// .map(|mut peer| {
|
|
|
|
// (
|
|
|
|
// peer.remove("id").unwrap_or_default(),
|
|
|
|
// peer.remove("username").unwrap_or_default(),
|
|
|
|
// peer.remove("hostname").unwrap_or_default(),
|
|
|
|
// peer.remove("platform").unwrap_or_default(),
|
|
|
|
// )
|
|
|
|
// })
|
|
|
|
// .collect::<Vec<(String, String, String, String)>>();
|
2022-09-21 21:20:19 +08:00
|
|
|
serde_json::to_string(&get_lan_peers()).unwrap_or_default()
|
2022-01-12 03:10:15 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn get_uuid(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_uuid()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn open_url(&self, url: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
open_url(url)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2021-05-02 21:19:48 +08:00
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
fn change_id(&self, id: String) {
|
2022-08-01 14:33:08 +08:00
|
|
|
let old_id = self.get_id();
|
|
|
|
change_id(id, old_id);
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn post_request(&self, url: String, body: String, header: String) {
|
2022-05-25 23:09:14 +08:00
|
|
|
post_request(url, body, header)
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_ok_change_id(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_ok_change_id()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_async_job_status(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_async_job_status()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 16:45:22 +08:00
|
|
|
fn t(&self, name: String) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
t(name)
|
2021-12-25 16:45:22 +08:00
|
|
|
}
|
|
|
|
|
2021-05-02 21:19:48 +08:00
|
|
|
fn is_xfce(&self) -> bool {
|
2022-05-25 23:09:14 +08:00
|
|
|
is_xfce()
|
2021-05-02 21:19:48 +08:00
|
|
|
}
|
2022-05-12 17:35:25 +08:00
|
|
|
|
|
|
|
fn get_api_server(&self) -> String {
|
2022-05-25 23:09:14 +08:00
|
|
|
get_api_server()
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
2022-06-30 16:19:36 +08:00
|
|
|
|
|
|
|
fn has_hwcodec(&self) -> bool {
|
2022-08-15 11:08:42 +08:00
|
|
|
has_hwcodec()
|
2022-06-30 16:19:36 +08:00
|
|
|
}
|
2022-07-06 18:57:14 +08:00
|
|
|
|
2022-06-30 01:19:38 +08:00
|
|
|
fn get_langs(&self) -> String {
|
2022-08-13 12:43:35 +08:00
|
|
|
get_langs()
|
2022-06-30 01:19:38 +08:00
|
|
|
}
|
2022-09-15 17:31:28 +08:00
|
|
|
|
|
|
|
fn default_video_save_directory(&self) -> String {
|
|
|
|
default_video_save_directory()
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl sciter::EventHandler for UI {
|
|
|
|
sciter::dispatch_script_call! {
|
2021-12-25 16:45:22 +08:00
|
|
|
fn t(String);
|
2022-05-12 17:35:25 +08:00
|
|
|
fn get_api_server();
|
2021-05-02 21:19:48 +08:00
|
|
|
fn is_xfce();
|
2022-05-12 17:35:25 +08:00
|
|
|
fn using_public_server();
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_id();
|
2022-07-24 16:41:12 +08:00
|
|
|
fn temporary_password();
|
|
|
|
fn update_temporary_password();
|
|
|
|
fn permanent_password();
|
|
|
|
fn set_permanent_password(String);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_remote_id();
|
|
|
|
fn set_remote_id(String);
|
2022-04-28 21:32:44 +08:00
|
|
|
fn closing(i32, i32, i32, i32);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_size();
|
|
|
|
fn new_remote(String, bool);
|
2022-07-14 10:34:56 +08:00
|
|
|
fn send_wol(String);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn remove_peer(String);
|
2022-07-13 18:06:19 +08:00
|
|
|
fn remove_discovered(String);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_connect_status();
|
2022-05-12 17:35:25 +08:00
|
|
|
fn get_mouse_time();
|
|
|
|
fn check_mouse_time();
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_recent_sessions();
|
2022-01-02 21:56:04 +08:00
|
|
|
fn get_peer(String);
|
|
|
|
fn get_fav();
|
|
|
|
fn store_fav(Value);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn recent_sessions_updated();
|
|
|
|
fn get_icon();
|
2022-05-12 17:35:25 +08:00
|
|
|
fn install_me(String, String);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn is_installed();
|
2022-09-27 13:30:49 +08:00
|
|
|
fn is_root();
|
|
|
|
fn is_release();
|
2022-01-05 18:34:30 +08:00
|
|
|
fn set_socks(String, String, String);
|
|
|
|
fn get_socks();
|
2022-05-12 17:35:25 +08:00
|
|
|
fn is_rdp_service_open();
|
|
|
|
fn is_share_rdp();
|
|
|
|
fn set_share_rdp(bool);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn is_installed_lower_version();
|
|
|
|
fn install_path();
|
|
|
|
fn goto_install();
|
|
|
|
fn is_process_trusted(bool);
|
|
|
|
fn is_can_screen_recording(bool);
|
2022-01-13 19:23:41 +08:00
|
|
|
fn is_installed_daemon(bool);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_error();
|
|
|
|
fn is_login_wayland();
|
|
|
|
fn fix_login_wayland();
|
2021-09-09 15:07:09 +08:00
|
|
|
fn current_is_wayland();
|
|
|
|
fn modify_default_login();
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_options();
|
|
|
|
fn get_option(String);
|
2021-12-29 17:53:36 +08:00
|
|
|
fn get_local_option(String);
|
2022-04-26 11:19:45 +08:00
|
|
|
fn set_local_option(String, String);
|
2021-06-14 18:27:09 +08:00
|
|
|
fn get_peer_option(String, String);
|
2022-01-02 15:09:44 +08:00
|
|
|
fn peer_has_password(String);
|
|
|
|
fn forget_password(String);
|
2021-06-14 18:27:09 +08:00
|
|
|
fn set_peer_option(String, String, String);
|
2022-05-12 17:35:25 +08:00
|
|
|
fn has_rendezvous_service();
|
|
|
|
fn get_license();
|
2021-03-29 15:59:14 +08:00
|
|
|
fn test_if_valid_server(String);
|
|
|
|
fn get_sound_inputs();
|
|
|
|
fn set_options(Value);
|
2021-10-08 00:16:10 +08:00
|
|
|
fn set_option(String, String);
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_software_update_url();
|
|
|
|
fn get_new_version();
|
|
|
|
fn get_version();
|
|
|
|
fn update_me(String);
|
2022-05-12 17:35:25 +08:00
|
|
|
fn show_run_without_install();
|
|
|
|
fn run_without_install();
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_app_name();
|
|
|
|
fn get_software_store_path();
|
|
|
|
fn get_software_ext();
|
|
|
|
fn open_url(String);
|
2022-05-12 17:35:25 +08:00
|
|
|
fn change_id(String);
|
|
|
|
fn get_async_job_status();
|
|
|
|
fn post_request(String, String, String);
|
|
|
|
fn is_ok_change_id();
|
2021-06-14 17:51:45 +08:00
|
|
|
fn create_shortcut(String);
|
2022-01-12 03:10:15 +08:00
|
|
|
fn discover();
|
|
|
|
fn get_lan_peers();
|
2022-05-12 17:35:25 +08:00
|
|
|
fn get_uuid();
|
2022-06-30 16:19:36 +08:00
|
|
|
fn has_hwcodec();
|
2022-06-30 01:19:38 +08:00
|
|
|
fn get_langs();
|
2022-09-15 17:31:28 +08:00
|
|
|
fn default_video_save_directory();
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-10 22:36:34 +08:00
|
|
|
impl sciter::host::HostHandler for UIHostHandler {
|
|
|
|
fn on_graphics_critical_failure(&mut self) {
|
|
|
|
log::error!("Critical rendering error: e.g. DirectX gfx driver error. Most probably bad gfx drivers.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-10 21:25:12 +08:00
|
|
|
pub fn check_zombie(children: Children) {
|
2021-03-29 15:59:14 +08:00
|
|
|
let mut deads = Vec::new();
|
|
|
|
loop {
|
2022-11-10 21:25:12 +08:00
|
|
|
let mut lock = children.lock().unwrap();
|
2021-03-29 15:59:14 +08:00
|
|
|
let mut n = 0;
|
|
|
|
for (id, c) in lock.1.iter_mut() {
|
|
|
|
if let Ok(Some(_)) = c.try_wait() {
|
|
|
|
deads.push(id.clone());
|
|
|
|
n += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ref id in deads.drain(..) {
|
|
|
|
lock.1.remove(id);
|
|
|
|
}
|
|
|
|
if n > 0 {
|
|
|
|
lock.0 = true;
|
|
|
|
}
|
|
|
|
drop(lock);
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
|
|
fn get_sound_inputs() -> Vec<String> {
|
|
|
|
let mut out = Vec::new();
|
|
|
|
use cpal::traits::{DeviceTrait, HostTrait};
|
|
|
|
let host = cpal::default_host();
|
|
|
|
if let Ok(devices) = host.devices() {
|
|
|
|
for device in devices {
|
|
|
|
if device.default_input_config().is_err() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if let Ok(name) = device.name() {
|
|
|
|
out.push(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn get_sound_inputs() -> Vec<String> {
|
|
|
|
crate::platform::linux::get_pa_sources()
|
|
|
|
.drain(..)
|
|
|
|
.map(|x| x.1)
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
const INVALID_FORMAT: &'static str = "Invalid format";
|
|
|
|
const UNKNOWN_ERROR: &'static str = "Unknown error";
|
|
|
|
|
|
|
|
#[tokio::main(flavor = "current_thread")]
|
|
|
|
async fn change_id(id: String, old_id: String) -> &'static str {
|
|
|
|
if !hbb_common::is_valid_custom_id(&id) {
|
|
|
|
return INVALID_FORMAT;
|
|
|
|
}
|
|
|
|
let uuid = machine_uid::get().unwrap_or("".to_owned());
|
|
|
|
if uuid.is_empty() {
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
let rendezvous_servers = crate::ipc::get_rendezvous_servers(1_000).await;
|
|
|
|
let mut futs = Vec::new();
|
|
|
|
let err: Arc<Mutex<&str>> = Default::default();
|
|
|
|
for rendezvous_server in rendezvous_servers {
|
|
|
|
let err = err.clone();
|
|
|
|
let id = id.to_owned();
|
|
|
|
let uuid = uuid.clone();
|
|
|
|
let old_id = old_id.clone();
|
|
|
|
futs.push(tokio::spawn(async move {
|
|
|
|
let tmp = check_id(rendezvous_server, old_id, id, uuid).await;
|
|
|
|
if !tmp.is_empty() {
|
|
|
|
*err.lock().unwrap() = tmp;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
join_all(futs).await;
|
|
|
|
let err = *err.lock().unwrap();
|
|
|
|
if err.is_empty() {
|
|
|
|
crate::ipc::set_config_async("id", id.to_owned()).await.ok();
|
|
|
|
}
|
|
|
|
err
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn check_id(
|
|
|
|
rendezvous_server: String,
|
|
|
|
old_id: String,
|
|
|
|
id: String,
|
|
|
|
uuid: String,
|
|
|
|
) -> &'static str {
|
|
|
|
let any_addr = Config::get_any_listen_addr();
|
|
|
|
if let Ok(mut socket) = FramedStream::new(
|
|
|
|
crate::check_port(rendezvous_server, RENDEZVOUS_PORT),
|
|
|
|
any_addr,
|
|
|
|
RENDEZVOUS_TIMEOUT,
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
{
|
|
|
|
let mut msg_out = Message::new();
|
|
|
|
msg_out.set_register_pk(RegisterPk {
|
|
|
|
old_id,
|
|
|
|
id,
|
|
|
|
uuid: uuid.into(),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
let mut ok = false;
|
|
|
|
if socket.send(&msg_out).await.is_ok() {
|
|
|
|
if let Some(Ok(bytes)) = socket.next_timeout(3_000).await {
|
|
|
|
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) {
|
|
|
|
match msg_in.union {
|
2022-07-14 17:20:01 +08:00
|
|
|
Some(rendezvous_message::Union::RegisterPkResponse(rpr)) => {
|
2022-05-12 17:35:25 +08:00
|
|
|
match rpr.result.enum_value_or_default() {
|
|
|
|
register_pk_response::Result::OK => {
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
register_pk_response::Result::ID_EXISTS => {
|
|
|
|
return "Not available";
|
|
|
|
}
|
|
|
|
register_pk_response::Result::TOO_FREQUENT => {
|
|
|
|
return "Too frequent";
|
|
|
|
}
|
|
|
|
register_pk_response::Result::NOT_SUPPORT => {
|
2022-05-13 18:10:32 +08:00
|
|
|
return "server_not_support";
|
2022-05-12 17:35:25 +08:00
|
|
|
}
|
|
|
|
register_pk_response::Result::INVALID_ID_FORMAT => {
|
|
|
|
return INVALID_FORMAT;
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return "Failed to connect to rendezvous server";
|
|
|
|
}
|
|
|
|
""
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-02-06 18:19:06 +08:00
|
|
|
|
|
|
|
// sacrifice some memory
|
|
|
|
pub fn value_crash_workaround(values: &[Value]) -> Arc<Vec<Value>> {
|
|
|
|
let persist = Arc::new(values.to_vec());
|
|
|
|
STUPID_VALUES.lock().unwrap().push(persist.clone());
|
|
|
|
persist
|
|
|
|
}
|