2023-10-18 08:07:00 +08:00
|
|
|
#[cfg(windows)]
|
2023-09-07 21:29:49 +08:00
|
|
|
use crate::client::translate;
|
2023-04-08 15:35:10 +08:00
|
|
|
#[cfg(not(debug_assertions))]
|
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
2023-03-20 10:02:59 +08:00
|
|
|
use crate::platform::breakdown_callback;
|
2023-05-17 23:19:20 +08:00
|
|
|
use hbb_common::log;
|
2023-04-06 17:53:07 +08:00
|
|
|
#[cfg(not(debug_assertions))]
|
2023-02-19 11:40:59 +08:00
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
|
|
use hbb_common::platform::register_breakdown_handler;
|
2023-09-07 21:29:49 +08:00
|
|
|
#[cfg(windows)]
|
|
|
|
use tauri_winrt_notification::{Duration, Sound, Toast};
|
2022-08-11 18:59:26 +08:00
|
|
|
|
2023-07-08 12:34:40 +08:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! my_println{
|
|
|
|
($($arg:tt)*) => {
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
println!("{}", format_args!($($arg)*));
|
|
|
|
#[cfg(windows)]
|
|
|
|
crate::platform::message_box(
|
|
|
|
&format!("{}", format_args!($($arg)*))
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-01 17:10:21 +08:00
|
|
|
#[inline]
|
|
|
|
fn is_empty_uni_link(arg: &str) -> bool {
|
|
|
|
if !arg.starts_with("rustdesk://") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
arg["rustdesk://".len()..].chars().all(|c| c == '/')
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:41:43 +08:00
|
|
|
/// shared by flutter and sciter main function
|
2022-11-14 19:48:42 +08:00
|
|
|
///
|
2022-11-14 15:41:43 +08:00
|
|
|
/// [Note]
|
|
|
|
/// If it returns [`None`], then the process will terminate, and flutter gui will not be started.
|
|
|
|
/// If it returns [`Some`], then the process will continue, and flutter gui will be started.
|
2023-03-27 19:13:29 +08:00
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
2022-09-15 17:41:10 +08:00
|
|
|
pub fn core_main() -> Option<Vec<String>> {
|
2023-07-19 14:45:11 +08:00
|
|
|
#[cfg(windows)]
|
|
|
|
crate::platform::windows::bootstrap();
|
2022-09-15 17:41:10 +08:00
|
|
|
let mut args = Vec::new();
|
2022-10-11 14:52:46 +08:00
|
|
|
let mut flutter_args = Vec::new();
|
2022-09-15 17:41:10 +08:00
|
|
|
let mut i = 0;
|
2022-09-29 09:00:04 +08:00
|
|
|
let mut _is_elevate = false;
|
|
|
|
let mut _is_run_as_system = false;
|
2022-11-19 10:57:17 +08:00
|
|
|
let mut _is_quick_support = false;
|
2023-07-07 12:22:39 +08:00
|
|
|
let mut _is_flutter_invoke_new_connection = false;
|
2022-11-10 14:38:25 +08:00
|
|
|
let mut arg_exe = Default::default();
|
2022-09-15 17:41:10 +08:00
|
|
|
for arg in std::env::args() {
|
2022-11-10 14:38:25 +08:00
|
|
|
if i == 0 {
|
|
|
|
arg_exe = arg;
|
2022-09-15 17:41:10 +08:00
|
|
|
} else if i > 0 {
|
2022-10-13 09:58:46 +08:00
|
|
|
#[cfg(feature = "flutter")]
|
2023-07-07 12:22:39 +08:00
|
|
|
if [
|
|
|
|
"--connect",
|
|
|
|
"--play",
|
|
|
|
"--file-transfer",
|
|
|
|
"--port-forward",
|
|
|
|
"--rdp",
|
|
|
|
]
|
|
|
|
.contains(&arg.as_str())
|
|
|
|
{
|
|
|
|
_is_flutter_invoke_new_connection = true;
|
2022-10-13 09:58:46 +08:00
|
|
|
}
|
2022-09-29 09:00:04 +08:00
|
|
|
if arg == "--elevate" {
|
|
|
|
_is_elevate = true;
|
|
|
|
} else if arg == "--run-as-system" {
|
|
|
|
_is_run_as_system = true;
|
2022-11-19 10:57:17 +08:00
|
|
|
} else if arg == "--quick_support" {
|
|
|
|
_is_quick_support = true;
|
2022-09-29 09:00:04 +08:00
|
|
|
} else {
|
|
|
|
args.push(arg);
|
|
|
|
}
|
2022-08-11 18:59:26 +08:00
|
|
|
}
|
2022-09-15 17:41:10 +08:00
|
|
|
i += 1;
|
|
|
|
}
|
2023-06-10 01:55:32 +08:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
|
|
if args.is_empty() {
|
|
|
|
if crate::check_process("--server", false) && !crate::check_process("--tray", true) {
|
2023-07-07 13:33:08 +08:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
hbb_common::allow_err!(crate::platform::check_autostart_config());
|
2023-06-10 01:55:32 +08:00
|
|
|
hbb_common::allow_err!(crate::run_me(vec!["--tray"]));
|
|
|
|
}
|
|
|
|
}
|
2023-04-06 17:53:07 +08:00
|
|
|
#[cfg(not(debug_assertions))]
|
2023-02-19 11:40:59 +08:00
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
2023-03-20 10:02:59 +08:00
|
|
|
register_breakdown_handler(breakdown_callback);
|
2023-01-05 14:27:28 +08:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[cfg(feature = "flutter")]
|
|
|
|
{
|
2023-07-30 11:09:14 +08:00
|
|
|
let (k, v) = ("LIBGL_ALWAYS_SOFTWARE", "1");
|
2023-01-05 14:27:28 +08:00
|
|
|
if !hbb_common::config::Config::get_option("allow-always-software-render").is_empty() {
|
|
|
|
std::env::set_var(k, v);
|
|
|
|
} else {
|
|
|
|
std::env::remove_var(k);
|
|
|
|
}
|
|
|
|
}
|
2023-07-24 14:17:09 +08:00
|
|
|
#[cfg(windows)]
|
|
|
|
if args.contains(&"--connect".to_string()) {
|
|
|
|
hbb_common::platform::windows::start_cpu_performance_monitor();
|
|
|
|
}
|
2022-10-13 09:58:46 +08:00
|
|
|
#[cfg(feature = "flutter")]
|
2023-07-07 12:22:39 +08:00
|
|
|
if _is_flutter_invoke_new_connection {
|
2022-10-11 19:52:03 +08:00
|
|
|
return core_main_invoke_new_connection(std::env::args());
|
2022-10-12 16:06:15 +08:00
|
|
|
}
|
2022-11-10 14:38:25 +08:00
|
|
|
let click_setup = cfg!(windows) && args.is_empty() && crate::common::is_setup(&arg_exe);
|
|
|
|
if click_setup {
|
|
|
|
args.push("--install".to_owned());
|
|
|
|
flutter_args.push("--install".to_string());
|
2022-09-15 17:41:10 +08:00
|
|
|
}
|
2022-10-11 14:52:46 +08:00
|
|
|
if args.contains(&"--noinstall".to_string()) {
|
|
|
|
args.clear();
|
|
|
|
}
|
2022-09-15 17:41:10 +08:00
|
|
|
if args.len() > 0 && args[0] == "--version" {
|
2023-07-27 10:51:27 +08:00
|
|
|
println!("{}", crate::VERSION);
|
2022-09-15 17:41:10 +08:00
|
|
|
return None;
|
|
|
|
}
|
2023-01-28 16:39:24 +08:00
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
_is_quick_support |= !crate::platform::is_installed()
|
|
|
|
&& args.is_empty()
|
2023-09-07 15:17:07 +08:00
|
|
|
&& (arg_exe.to_lowercase().contains("-qs-")
|
2023-01-28 16:39:24 +08:00
|
|
|
|| (!click_setup && crate::platform::is_elevated(None).unwrap_or(false)));
|
|
|
|
crate::portable_service::client::set_quick_support(_is_quick_support);
|
|
|
|
}
|
2023-03-04 17:26:24 +08:00
|
|
|
let mut log_name = "".to_owned();
|
|
|
|
if args.len() > 0 && args[0].starts_with("--") {
|
|
|
|
let name = args[0].replace("--", "");
|
|
|
|
if !name.is_empty() {
|
|
|
|
log_name = name;
|
2022-09-15 17:41:10 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-04 17:26:24 +08:00
|
|
|
hbb_common::init_log(false, &log_name);
|
2023-06-10 18:24:03 +08:00
|
|
|
|
|
|
|
// linux uni (url) go here.
|
|
|
|
#[cfg(all(target_os = "linux", feature = "flutter"))]
|
|
|
|
if args.len() > 0 && args[0].starts_with("rustdesk:") {
|
|
|
|
return try_send_by_dbus(args[0].clone());
|
|
|
|
}
|
|
|
|
|
2022-11-10 10:27:13 +08:00
|
|
|
#[cfg(windows)]
|
2022-11-19 10:57:17 +08:00
|
|
|
if !crate::platform::is_installed()
|
|
|
|
&& args.is_empty()
|
|
|
|
&& _is_quick_support
|
|
|
|
&& !_is_elevate
|
|
|
|
&& !_is_run_as_system
|
|
|
|
{
|
2023-01-12 21:03:05 +08:00
|
|
|
use crate::portable_service::client;
|
|
|
|
if let Err(e) = client::start_portable_service(client::StartPara::Direct) {
|
2023-11-18 09:47:08 +08:00
|
|
|
log::error!("Failed to start portable service: {:?}", e);
|
2022-11-16 20:32:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#[cfg(windows)]
|
2022-11-10 10:27:13 +08:00
|
|
|
if !crate::platform::is_installed() && (_is_elevate || _is_run_as_system) {
|
|
|
|
crate::platform::elevate_or_run_as_system(click_setup, _is_elevate, _is_run_as_system);
|
|
|
|
return None;
|
|
|
|
}
|
2023-04-23 15:40:55 +08:00
|
|
|
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
2023-05-15 19:07:55 +08:00
|
|
|
init_plugins(&args);
|
2023-08-01 15:57:38 +08:00
|
|
|
log::info!("main start args:{:?}", args);
|
2023-08-01 17:10:21 +08:00
|
|
|
if args.is_empty() || is_empty_uni_link(&args[0]) {
|
2022-09-15 17:41:10 +08:00
|
|
|
std::thread::spawn(move || crate::start_server(false));
|
|
|
|
} else {
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
use crate::platform;
|
|
|
|
if args[0] == "--uninstall" {
|
2023-03-02 21:40:03 +08:00
|
|
|
if let Err(err) = platform::uninstall_me(true) {
|
2022-09-15 17:41:10 +08:00
|
|
|
log::error!("Failed to uninstall: {}", err);
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
} else if args[0] == "--after-install" {
|
|
|
|
if let Err(err) = platform::run_after_install() {
|
|
|
|
log::error!("Failed to after-install: {}", err);
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
} else if args[0] == "--before-uninstall" {
|
|
|
|
if let Err(err) = platform::run_before_uninstall() {
|
|
|
|
log::error!("Failed to before-uninstall: {}", err);
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
} else if args[0] == "--silent-install" {
|
2023-09-07 21:29:49 +08:00
|
|
|
let res = platform::install_me(
|
2023-03-20 12:13:52 +08:00
|
|
|
"desktopicon startmenu driverCert",
|
2022-09-15 17:41:10 +08:00
|
|
|
"".to_owned(),
|
|
|
|
true,
|
|
|
|
args.len() > 1,
|
2023-09-07 21:29:49 +08:00
|
|
|
);
|
|
|
|
let text = match res {
|
|
|
|
Ok(_) => translate("Installation Successful!".to_string()),
|
|
|
|
Err(_) => translate("Installation failed!".to_string()),
|
|
|
|
};
|
|
|
|
Toast::new(Toast::POWERSHELL_APP_ID)
|
|
|
|
.title(&hbb_common::config::APP_NAME.read().unwrap())
|
|
|
|
.text1(&text)
|
|
|
|
.sound(Some(Sound::Default))
|
|
|
|
.duration(Duration::Short)
|
|
|
|
.show()
|
|
|
|
.ok();
|
2022-09-15 17:41:10 +08:00
|
|
|
return None;
|
2023-03-07 22:38:01 +08:00
|
|
|
} else if args[0] == "--install-cert" {
|
|
|
|
#[cfg(windows)]
|
|
|
|
hbb_common::allow_err!(crate::platform::windows::install_cert(&args[1]));
|
2023-11-18 12:14:21 +08:00
|
|
|
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
2023-11-20 21:44:25 +08:00
|
|
|
if crate::virtual_display_manager::is_virtual_display_supported() {
|
|
|
|
hbb_common::allow_err!(crate::virtual_display_manager::install_update_driver());
|
|
|
|
}
|
2023-03-07 22:38:01 +08:00
|
|
|
return None;
|
2023-06-05 15:17:05 +08:00
|
|
|
} else if args[0] == "--uninstall-cert" {
|
|
|
|
#[cfg(windows)]
|
|
|
|
hbb_common::allow_err!(crate::platform::windows::uninstall_cert());
|
|
|
|
return None;
|
2022-11-10 10:27:13 +08:00
|
|
|
} else if args[0] == "--portable-service" {
|
|
|
|
crate::platform::elevate_or_run_as_system(
|
|
|
|
click_setup,
|
|
|
|
_is_elevate,
|
|
|
|
_is_run_as_system,
|
|
|
|
);
|
|
|
|
return None;
|
2022-09-15 17:41:10 +08:00
|
|
|
}
|
2022-05-30 16:16:20 +08:00
|
|
|
}
|
2022-09-15 17:41:10 +08:00
|
|
|
if args[0] == "--remove" {
|
|
|
|
if args.len() == 2 {
|
|
|
|
// sleep a while so that process of removed exe exit
|
|
|
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
|
|
|
std::fs::remove_file(&args[1]).ok();
|
|
|
|
return None;
|
|
|
|
}
|
2023-02-09 21:28:42 +08:00
|
|
|
} else if args[0] == "--tray" {
|
2023-06-09 22:33:38 +08:00
|
|
|
if !crate::check_process("--tray", true) {
|
|
|
|
crate::tray::start_tray();
|
|
|
|
}
|
2023-02-09 21:28:42 +08:00
|
|
|
return None;
|
2023-07-27 16:49:19 +08:00
|
|
|
} else if args[0] == "--install-service" {
|
|
|
|
log::info!("start --install-service");
|
|
|
|
crate::platform::install_service();
|
|
|
|
return None;
|
|
|
|
} else if args[0] == "--uninstall-service" {
|
|
|
|
log::info!("start --uninstall-service");
|
|
|
|
crate::platform::uninstall_service(false);
|
2022-09-15 17:41:10 +08:00
|
|
|
} else if args[0] == "--service" {
|
2023-09-04 15:50:13 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
crate::platform::macos::hide_dock();
|
2022-09-15 17:41:10 +08:00
|
|
|
log::info!("start --service");
|
|
|
|
crate::start_os_service();
|
|
|
|
return None;
|
|
|
|
} else if args[0] == "--server" {
|
2022-12-14 00:32:03 +08:00
|
|
|
log::info!("start --server with user {}", crate::username());
|
2023-11-14 12:11:38 +08:00
|
|
|
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
|
|
|
crate::privacy_mode::restore_reg_connectivity();
|
2023-02-09 21:28:42 +08:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
2022-09-07 20:08:12 +08:00
|
|
|
{
|
2022-09-15 17:41:10 +08:00
|
|
|
crate::start_server(true);
|
|
|
|
return None;
|
2022-09-07 20:08:12 +08:00
|
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
2022-11-04 19:20:51 +08:00
|
|
|
{
|
2022-11-04 19:28:30 +08:00
|
|
|
let handler = std::thread::spawn(move || crate::start_server(true));
|
2023-02-09 21:28:42 +08:00
|
|
|
crate::tray::start_tray();
|
2022-11-19 20:06:17 +08:00
|
|
|
// prevent server exit when encountering errors from tray
|
2022-11-10 23:26:09 +08:00
|
|
|
hbb_common::allow_err!(handler.join());
|
2022-11-04 19:20:51 +08:00
|
|
|
}
|
2022-09-15 17:41:10 +08:00
|
|
|
} else if args[0] == "--import-config" {
|
|
|
|
if args.len() == 2 {
|
|
|
|
let filepath;
|
|
|
|
let path = std::path::Path::new(&args[1]);
|
|
|
|
if !path.is_absolute() {
|
|
|
|
let mut cur = std::env::current_dir().unwrap();
|
|
|
|
cur.push(path);
|
|
|
|
filepath = cur.to_str().unwrap().to_string();
|
|
|
|
} else {
|
|
|
|
filepath = path.to_str().unwrap().to_string();
|
|
|
|
}
|
|
|
|
import_config(&filepath);
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
} else if args[0] == "--password" {
|
|
|
|
if args.len() == 2 {
|
2023-07-31 21:57:37 +08:00
|
|
|
if crate::platform::is_installed() && is_root() {
|
2023-07-25 17:07:55 +08:00
|
|
|
if let Err(err) = crate::ipc::set_permanent_password(args[1].to_owned()) {
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("{err}");
|
2023-07-25 17:07:55 +08:00
|
|
|
} else {
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("Done!");
|
2023-07-25 17:07:55 +08:00
|
|
|
}
|
2022-12-06 11:49:07 +08:00
|
|
|
} else {
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("Installation and administrative privileges required!");
|
2022-12-06 11:49:07 +08:00
|
|
|
}
|
2022-09-07 20:08:12 +08:00
|
|
|
}
|
2022-09-15 17:41:10 +08:00
|
|
|
return None;
|
2023-03-02 23:37:32 +08:00
|
|
|
} else if args[0] == "--get-id" {
|
2023-07-31 21:57:37 +08:00
|
|
|
if crate::platform::is_installed() && is_root() {
|
|
|
|
println!("{}", crate::ipc::get_id());
|
2022-12-09 16:19:44 +08:00
|
|
|
} else {
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("Installation and administrative privileges required!");
|
2022-12-09 16:19:44 +08:00
|
|
|
}
|
2023-07-19 17:11:57 +08:00
|
|
|
return None;
|
|
|
|
} else if args[0] == "--set-id" {
|
|
|
|
if args.len() == 2 {
|
2023-07-31 21:57:37 +08:00
|
|
|
if crate::platform::is_installed() && is_root() {
|
2023-07-19 17:11:57 +08:00
|
|
|
let old_id = crate::ipc::get_id();
|
|
|
|
let mut res = crate::ui_interface::change_id_shared(args[1].to_owned(), old_id);
|
|
|
|
if res.is_empty() {
|
|
|
|
res = "Done!".to_owned();
|
|
|
|
}
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("{}", res);
|
2023-07-19 17:11:57 +08:00
|
|
|
} else {
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("Installation and administrative privileges required!");
|
2023-07-19 17:11:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
} else if args[0] == "--config" {
|
2023-07-25 16:37:39 +08:00
|
|
|
if args.len() == 2 && !args[0].contains("host=") {
|
2023-07-31 21:57:37 +08:00
|
|
|
if crate::platform::is_installed() && is_root() {
|
2023-07-25 16:37:39 +08:00
|
|
|
// encrypted string used in renaming exe.
|
2023-07-22 14:30:47 +08:00
|
|
|
let name = if args[1].ends_with(".exe") {
|
|
|
|
args[1].to_owned()
|
|
|
|
} else {
|
|
|
|
format!("{}.exe", args[1])
|
|
|
|
};
|
2023-07-19 17:11:57 +08:00
|
|
|
if let Ok(lic) = crate::license::get_license_from_string(&name) {
|
|
|
|
if !lic.host.is_empty() {
|
|
|
|
crate::ui_interface::set_option("key".into(), lic.key);
|
|
|
|
crate::ui_interface::set_option(
|
|
|
|
"custom-rendezvous-server".into(),
|
|
|
|
lic.host,
|
|
|
|
);
|
|
|
|
crate::ui_interface::set_option("api-server".into(), lic.api);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("Installation and administrative privileges required!");
|
2023-07-19 17:11:57 +08:00
|
|
|
}
|
|
|
|
}
|
2022-12-09 16:19:44 +08:00
|
|
|
return None;
|
2023-07-28 17:52:43 +08:00
|
|
|
} else if args[0] == "--option" {
|
2023-07-31 21:57:37 +08:00
|
|
|
if crate::platform::is_installed() && is_root() {
|
2023-07-28 17:52:43 +08:00
|
|
|
if args.len() == 2 {
|
|
|
|
let options = crate::ipc::get_options();
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("{}", options.get(&args[1]).unwrap_or(&"".to_owned()));
|
2023-07-28 17:52:43 +08:00
|
|
|
} else if args.len() == 3 {
|
|
|
|
crate::ipc::set_option(&args[1], &args[2]);
|
|
|
|
}
|
|
|
|
} else {
|
2023-07-31 21:57:37 +08:00
|
|
|
println!("Installation and administrative privileges required!");
|
2023-07-28 17:52:43 +08:00
|
|
|
}
|
2023-07-28 17:55:33 +08:00
|
|
|
return None;
|
2023-08-02 19:48:33 +08:00
|
|
|
} else if args[0] == "--assign" {
|
|
|
|
if crate::platform::is_installed() && is_root() {
|
|
|
|
let max = args.len() - 1;
|
|
|
|
let pos = args.iter().position(|x| x == "--token").unwrap_or(max);
|
|
|
|
if pos < max {
|
|
|
|
let token = args[pos + 1].to_owned();
|
|
|
|
let id = crate::ipc::get_id();
|
|
|
|
let uuid = crate::encode64(hbb_common::get_uuid());
|
|
|
|
let mut user_name = None;
|
|
|
|
let pos = args.iter().position(|x| x == "--user_name").unwrap_or(max);
|
|
|
|
if pos < max {
|
|
|
|
user_name = Some(args[pos + 1].to_owned());
|
|
|
|
}
|
|
|
|
let mut strategy_name = None;
|
|
|
|
let pos = args
|
|
|
|
.iter()
|
|
|
|
.position(|x| x == "--strategy_name")
|
|
|
|
.unwrap_or(max);
|
|
|
|
if pos < max {
|
|
|
|
strategy_name = Some(args[pos + 1].to_owned());
|
|
|
|
}
|
|
|
|
let mut body = serde_json::json!({
|
|
|
|
"id": id,
|
|
|
|
"uuid": uuid,
|
|
|
|
});
|
|
|
|
let header = "Authorization: Bearer ".to_owned() + &token;
|
|
|
|
if user_name.is_none() && strategy_name.is_none() {
|
|
|
|
println!("--user_name or --strategy_name is required!");
|
|
|
|
} else {
|
|
|
|
if let Some(name) = user_name {
|
|
|
|
body["user_name"] = serde_json::json!(name);
|
|
|
|
}
|
|
|
|
if let Some(name) = strategy_name {
|
|
|
|
body["strategy_name"] = serde_json::json!(name);
|
|
|
|
}
|
|
|
|
let url = crate::ui_interface::get_api_server() + "/api/devices/cli";
|
2023-08-11 13:19:23 +08:00
|
|
|
match crate::post_request_sync(url, body.to_string(), &header) {
|
|
|
|
Err(err) => println!("{}", err),
|
|
|
|
Ok(text) => {
|
|
|
|
if text.is_empty() {
|
|
|
|
println!("Done!");
|
|
|
|
} else {
|
|
|
|
println!("{}", text);
|
|
|
|
}
|
|
|
|
}
|
2023-08-02 19:48:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("--token is required!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("Installation and administrative privileges required!");
|
|
|
|
}
|
|
|
|
return None;
|
2022-09-15 17:41:10 +08:00
|
|
|
} else if args[0] == "--check-hwcodec-config" {
|
|
|
|
#[cfg(feature = "hwcodec")]
|
|
|
|
scrap::hwcodec::check_config();
|
|
|
|
return None;
|
|
|
|
} else if args[0] == "--cm" {
|
|
|
|
// call connection manager to establish connections
|
|
|
|
// meanwhile, return true to call flutter window to show control panel
|
2022-11-20 15:53:08 +08:00
|
|
|
crate::ui_interface::start_option_status_sync();
|
2023-03-30 18:16:48 +08:00
|
|
|
} else if args[0] == "--cm-no-ui" {
|
|
|
|
#[cfg(feature = "flutter")]
|
2023-09-09 15:23:26 +08:00
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios", target_os = "windows")))]
|
2023-03-30 18:16:48 +08:00
|
|
|
crate::flutter::connection_manager::start_cm_no_ui();
|
|
|
|
return None;
|
2023-05-09 19:47:26 +08:00
|
|
|
} else {
|
|
|
|
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
|
|
if args[0] == "--plugin-install" {
|
2023-05-15 19:07:55 +08:00
|
|
|
if args.len() == 2 {
|
|
|
|
crate::plugin::change_uninstall_plugin(&args[1], false);
|
|
|
|
} else if args.len() == 3 {
|
2023-05-10 23:57:46 +08:00
|
|
|
crate::plugin::install_plugin_with_url(&args[1], &args[2]);
|
2023-05-09 19:47:26 +08:00
|
|
|
}
|
|
|
|
return None;
|
2023-05-15 19:07:55 +08:00
|
|
|
} else if args[0] == "--plugin-uninstall" {
|
|
|
|
if args.len() == 2 {
|
|
|
|
crate::plugin::change_uninstall_plugin(&args[1], true);
|
|
|
|
}
|
|
|
|
return None;
|
2023-05-09 19:47:26 +08:00
|
|
|
}
|
2022-09-15 17:41:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//_async_logger_holder.map(|x| x.flush());
|
2022-10-11 14:52:46 +08:00
|
|
|
#[cfg(feature = "flutter")]
|
|
|
|
return Some(flutter_args);
|
|
|
|
#[cfg(not(feature = "flutter"))]
|
|
|
|
return Some(args);
|
2022-09-15 17:41:10 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 19:07:55 +08:00
|
|
|
#[inline]
|
|
|
|
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
|
|
fn init_plugins(args: &Vec<String>) {
|
|
|
|
if args.is_empty() || "--server" == (&args[0] as &str) {
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
let load_plugins = true;
|
|
|
|
#[cfg(not(debug_assertions))]
|
|
|
|
let load_plugins = crate::platform::is_installed();
|
|
|
|
if load_plugins {
|
|
|
|
crate::plugin::init();
|
|
|
|
}
|
|
|
|
} else if "--service" == (&args[0] as &str) {
|
2023-05-17 23:19:20 +08:00
|
|
|
hbb_common::allow_err!(crate::plugin::remove_uninstalled());
|
2023-05-15 19:07:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-15 17:41:10 +08:00
|
|
|
fn import_config(path: &str) {
|
|
|
|
use hbb_common::{config::*, get_exe_time, get_modified_time};
|
|
|
|
let path2 = path.replace(".toml", "2.toml");
|
|
|
|
let path2 = std::path::Path::new(&path2);
|
|
|
|
let path = std::path::Path::new(path);
|
|
|
|
log::info!("import config from {:?} and {:?}", path, path2);
|
|
|
|
let config: Config = load_path(path.into());
|
|
|
|
if config.is_empty() {
|
|
|
|
log::info!("Empty source config, skipped");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if get_modified_time(&path) > get_modified_time(&Config::file())
|
|
|
|
&& get_modified_time(&path) < get_exe_time()
|
|
|
|
{
|
|
|
|
if store_path(Config::file(), config).is_err() {
|
|
|
|
log::info!("config written");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let config2: Config2 = load_path(path2.into());
|
|
|
|
if get_modified_time(&path2) > get_modified_time(&Config2::file()) {
|
|
|
|
if store_path(Config2::file(), config2).is_err() {
|
|
|
|
log::info!("config2 written");
|
2022-08-25 17:35:45 +08:00
|
|
|
}
|
2022-05-30 16:16:20 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-11 19:52:03 +08:00
|
|
|
|
|
|
|
/// invoke a new connection
|
|
|
|
///
|
|
|
|
/// [Note]
|
2022-10-13 09:58:46 +08:00
|
|
|
/// this is for invoke new connection from dbus.
|
2022-11-14 15:41:43 +08:00
|
|
|
/// If it returns [`None`], then the process will terminate, and flutter gui will not be started.
|
|
|
|
/// If it returns [`Some`], then the process will continue, and flutter gui will be started.
|
2022-10-13 09:58:46 +08:00
|
|
|
#[cfg(feature = "flutter")]
|
2022-11-10 14:38:25 +08:00
|
|
|
fn core_main_invoke_new_connection(mut args: std::env::Args) -> Option<Vec<String>> {
|
2023-07-07 12:22:39 +08:00
|
|
|
let mut authority = None;
|
|
|
|
let mut id = None;
|
|
|
|
let mut param_array = vec![];
|
|
|
|
while let Some(arg) = args.next() {
|
|
|
|
match arg.as_str() {
|
|
|
|
"--connect" | "--play" | "--file-transfer" | "--port-forward" | "--rdp" => {
|
|
|
|
authority = Some((&arg.to_string()[2..]).to_owned());
|
|
|
|
id = args.next();
|
|
|
|
}
|
|
|
|
"--password" => {
|
|
|
|
if let Some(password) = args.next() {
|
|
|
|
param_array.push(format!("password={password}"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"--relay" => {
|
|
|
|
param_array.push(format!("relay=true"));
|
|
|
|
}
|
|
|
|
// inner
|
|
|
|
"--switch_uuid" => {
|
|
|
|
if let Some(switch_uuid) = args.next() {
|
|
|
|
param_array.push(format!("switch_uuid={switch_uuid}"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2023-06-05 00:01:46 +08:00
|
|
|
}
|
2023-07-07 12:22:39 +08:00
|
|
|
let mut uni_links = Default::default();
|
|
|
|
if let Some(authority) = authority {
|
|
|
|
if let Some(mut id) = id {
|
|
|
|
let app_name = crate::get_app_name();
|
|
|
|
let ext = format!(".{}", app_name.to_lowercase());
|
|
|
|
if id.ends_with(&ext) {
|
|
|
|
id = id.replace(&ext, "");
|
|
|
|
}
|
|
|
|
let params = param_array.join("&");
|
|
|
|
let params_flag = if params.is_empty() { "" } else { "?" };
|
|
|
|
uni_links = format!("rustdesk://{}/{}{}{}", authority, id, params_flag, params);
|
2023-01-17 21:43:39 +08:00
|
|
|
}
|
|
|
|
}
|
2023-07-07 12:22:39 +08:00
|
|
|
if uni_links.is_empty() {
|
|
|
|
return None;
|
2023-02-01 19:49:41 +08:00
|
|
|
}
|
2023-01-17 21:43:39 +08:00
|
|
|
|
2022-10-11 19:52:03 +08:00
|
|
|
#[cfg(target_os = "linux")]
|
2023-06-10 18:24:03 +08:00
|
|
|
return try_send_by_dbus(uni_links);
|
2022-10-11 19:52:03 +08:00
|
|
|
|
2022-11-14 19:48:42 +08:00
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
use winapi::um::winuser::WM_USER;
|
|
|
|
let res = crate::platform::send_message_to_hnwd(
|
|
|
|
"FLUTTER_RUNNER_WIN32_WINDOW",
|
|
|
|
"RustDesk",
|
2022-12-26 01:21:13 +08:00
|
|
|
(WM_USER + 2) as _, // referred from unilinks desktop pub
|
2022-11-14 19:48:42 +08:00
|
|
|
uni_links.as_str(),
|
2023-01-20 12:03:03 +08:00
|
|
|
false,
|
2022-11-14 19:48:42 +08:00
|
|
|
);
|
|
|
|
return if res { None } else { Some(Vec::new()) };
|
|
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
2023-02-04 16:18:54 +08:00
|
|
|
{
|
|
|
|
return if let Err(_) = crate::ipc::send_url_scheme(uni_links) {
|
|
|
|
Some(Vec::new())
|
|
|
|
} else {
|
|
|
|
None
|
2023-02-09 21:28:42 +08:00
|
|
|
};
|
2023-02-04 16:18:54 +08:00
|
|
|
}
|
2022-10-11 19:52:03 +08:00
|
|
|
}
|
2023-06-10 18:24:03 +08:00
|
|
|
|
|
|
|
#[cfg(all(target_os = "linux", feature = "flutter"))]
|
|
|
|
fn try_send_by_dbus(uni_links: String) -> Option<Vec<String>> {
|
|
|
|
use crate::dbus::invoke_new_connection;
|
|
|
|
|
|
|
|
match invoke_new_connection(uni_links) {
|
|
|
|
Ok(()) => {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
log::error!("{}", err.as_ref());
|
|
|
|
// return Some to invoke this url by self
|
|
|
|
return Some(Vec::new());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-31 21:57:37 +08:00
|
|
|
|
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
|
|
fn is_root() -> bool {
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
return crate::platform::is_elevated(None).unwrap_or_default()
|
|
|
|
|| crate::platform::is_root();
|
|
|
|
}
|
|
|
|
#[allow(unreachable_code)]
|
|
|
|
crate::platform::is_root()
|
|
|
|
}
|