refactor core_main, also fix windows flutter restart repeated fatal
error crash
This commit is contained in:
parent
5b4357b8c4
commit
f4871a992f
@ -1,3 +1,5 @@
|
|||||||
|
// original cm window in Sciter version.
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -259,7 +259,6 @@ class ServerModel with ChangeNotifier {
|
|||||||
Future<Null> startService() async {
|
Future<Null> startService() async {
|
||||||
_isStart = true;
|
_isStart = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
// TODO
|
|
||||||
parent.target?.ffiModel.updateEventListener("");
|
parent.target?.ffiModel.updateEventListener("");
|
||||||
await parent.target?.invokeMethod("init_service");
|
await parent.target?.invokeMethod("init_service");
|
||||||
await bind.mainStartService();
|
await bind.mainStartService();
|
||||||
@ -274,7 +273,6 @@ class ServerModel with ChangeNotifier {
|
|||||||
/// Stop the screen sharing service.
|
/// Stop the screen sharing service.
|
||||||
Future<Null> stopService() async {
|
Future<Null> stopService() async {
|
||||||
_isStart = false;
|
_isStart = false;
|
||||||
// TODO
|
|
||||||
closeAll();
|
closeAll();
|
||||||
await parent.target?.invokeMethod("stop_service");
|
await parent.target?.invokeMethod("stop_service");
|
||||||
await bind.mainStopService();
|
await bind.mainStopService();
|
||||||
|
@ -49,7 +49,7 @@ packages:
|
|||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.8.2"
|
version: "2.9.0"
|
||||||
back_button_interceptor:
|
back_button_interceptor:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -147,7 +147,7 @@ packages:
|
|||||||
name: characters
|
name: characters
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.2.1"
|
||||||
charcode:
|
charcode:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -168,7 +168,7 @@ packages:
|
|||||||
name: clock
|
name: clock
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.1"
|
||||||
code_builder:
|
code_builder:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -324,7 +324,7 @@ packages:
|
|||||||
name: fake_async
|
name: fake_async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0"
|
version: "1.3.1"
|
||||||
ffi:
|
ffi:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -418,8 +418,8 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "9021e21de36c84edf01d5034f38eda580463163b"
|
ref: "47179378523c993092f70d95f93d53f40af01f02"
|
||||||
resolved-ref: "9021e21de36c84edf01d5034f38eda580463163b"
|
resolved-ref: "47179378523c993092f70d95f93d53f40af01f02"
|
||||||
url: "https://github.com/Kingtous/rustdesk_flutter_custom_cursor"
|
url: "https://github.com/Kingtous/rustdesk_flutter_custom_cursor"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
@ -630,14 +630,14 @@ packages:
|
|||||||
name: matcher
|
name: matcher
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.11"
|
version: "0.12.12"
|
||||||
material_color_utilities:
|
material_color_utilities:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: material_color_utilities
|
name: material_color_utilities
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.1.4"
|
version: "0.1.5"
|
||||||
menu_base:
|
menu_base:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -651,7 +651,7 @@ packages:
|
|||||||
name: meta
|
name: meta
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.7.0"
|
version: "1.8.0"
|
||||||
mime:
|
mime:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -728,7 +728,7 @@ packages:
|
|||||||
name: path
|
name: path
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.1"
|
version: "1.8.2"
|
||||||
path_provider:
|
path_provider:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -980,7 +980,7 @@ packages:
|
|||||||
name: source_span
|
name: source_span
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.2"
|
version: "1.9.0"
|
||||||
sqflite:
|
sqflite:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1022,7 +1022,7 @@ packages:
|
|||||||
name: string_scanner
|
name: string_scanner
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.1"
|
||||||
synchronized:
|
synchronized:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1036,14 +1036,14 @@ packages:
|
|||||||
name: term_glyph
|
name: term_glyph
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.2.1"
|
||||||
test_api:
|
test_api:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.4.9"
|
version: "0.4.12"
|
||||||
timing:
|
timing:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -2,7 +2,6 @@ use std::sync::{Arc, Mutex};
|
|||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub use arboard::Clipboard as ClipboardContext;
|
pub use arboard::Clipboard as ClipboardContext;
|
||||||
use serde_json::json;
|
|
||||||
|
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
allow_err,
|
allow_err,
|
||||||
|
193
src/core_main.rs
193
src/core_main.rs
@ -1,39 +1,188 @@
|
|||||||
use hbb_common::log;
|
use hbb_common::log;
|
||||||
|
|
||||||
use crate::{flutter::connection_manager, start_os_service, start_server};
|
// shared by flutter and sciter main function
|
||||||
|
pub fn core_main() -> Option<Vec<String>> {
|
||||||
/// Main entry of the RustDesk Core.
|
// https://docs.rs/flexi_logger/latest/flexi_logger/error_info/index.html#write
|
||||||
/// Return true if the app should continue running with UI(possibly Flutter), false if the app should exit.
|
// though async logger more efficient, but it also causes more problems, disable it for now
|
||||||
pub fn core_main() -> bool {
|
// let mut _async_logger_holder: Option<flexi_logger::LoggerHandle> = None;
|
||||||
let args = std::env::args().collect::<Vec<_>>();
|
let mut args = Vec::new();
|
||||||
// TODO: implement core_main()
|
let mut i = 0;
|
||||||
if args.len() > 1 {
|
let mut is_setup = false;
|
||||||
if args[1] == "--cm" {
|
for arg in std::env::args() {
|
||||||
// call connection manager to establish connections
|
// to-do: how to pass to flutter?
|
||||||
// meanwhile, return true to call flutter window to show control panel
|
if i == 0 && crate::common::is_setup(&arg) {
|
||||||
connection_manager::start_listen_ipc_thread();
|
is_setup = true;
|
||||||
return true;
|
} else if i > 0 {
|
||||||
|
args.push(arg);
|
||||||
}
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
if is_setup {
|
||||||
|
if args.is_empty() {
|
||||||
|
args.push("--install".to_owned());
|
||||||
|
} else if args[0] == "--noinstall" {
|
||||||
|
args.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if args.len() > 0 && args[0] == "--version" {
|
||||||
|
println!("{}", crate::VERSION);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
use hbb_common::env_logger::*;
|
use hbb_common::env_logger::*;
|
||||||
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
|
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
|
||||||
if args[1] == "--service" {
|
}
|
||||||
log::info!("start --service");
|
#[cfg(not(debug_assertions))]
|
||||||
start_os_service();
|
{
|
||||||
return false;
|
let mut path = hbb_common::config::Config::log_path();
|
||||||
|
if args.len() > 0 && args[0].starts_with("--") {
|
||||||
|
let name = args[0].replace("--", "");
|
||||||
|
if !name.is_empty() {
|
||||||
|
path.push(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if args[1] == "--server" {
|
use flexi_logger::*;
|
||||||
|
if let Ok(x) = Logger::try_with_env_or_str("debug") {
|
||||||
|
// _async_logger_holder =
|
||||||
|
x.log_to_file(FileSpec::default().directory(path))
|
||||||
|
//.write_mode(WriteMode::Async)
|
||||||
|
.format(opt_format)
|
||||||
|
.rotate(
|
||||||
|
Criterion::Age(Age::Day),
|
||||||
|
Naming::Timestamps,
|
||||||
|
Cleanup::KeepLogFiles(6),
|
||||||
|
)
|
||||||
|
.start()
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if args.is_empty() {
|
||||||
|
std::thread::spawn(move || crate::start_server(false));
|
||||||
|
} else {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
use crate::platform;
|
||||||
|
if args[0] == "--uninstall" {
|
||||||
|
if let Err(err) = platform::uninstall_me() {
|
||||||
|
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] == "--update" {
|
||||||
|
hbb_common::allow_err!(platform::update_me());
|
||||||
|
return None;
|
||||||
|
} else if args[0] == "--reinstall" {
|
||||||
|
hbb_common::allow_err!(platform::uninstall_me());
|
||||||
|
hbb_common::allow_err!(platform::install_me(
|
||||||
|
"desktopicon startmenu",
|
||||||
|
"".to_owned(),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
));
|
||||||
|
return None;
|
||||||
|
} else if args[0] == "--silent-install" {
|
||||||
|
hbb_common::allow_err!(platform::install_me(
|
||||||
|
"desktopicon startmenu",
|
||||||
|
"".to_owned(),
|
||||||
|
true,
|
||||||
|
args.len() > 1,
|
||||||
|
));
|
||||||
|
return None;
|
||||||
|
} else if args[0] == "--extract" {
|
||||||
|
#[cfg(feature = "with_rc")]
|
||||||
|
hbb_common::allow_err!(crate::rc::extract_resources(&args[1]));
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
} else if args[0] == "--service" {
|
||||||
|
log::info!("start --service");
|
||||||
|
crate::start_os_service();
|
||||||
|
return None;
|
||||||
|
} else if args[0] == "--server" {
|
||||||
log::info!("start --server");
|
log::info!("start --server");
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
{
|
{
|
||||||
start_server(true);
|
crate::start_server(true);
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
std::thread::spawn(move || start_server(true));
|
std::thread::spawn(move || start_server(true));
|
||||||
|
// to-do: for flutter, starting tray not ready yet, or we can reuse sciter's tray implementation.
|
||||||
}
|
}
|
||||||
return false;
|
} 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 {
|
||||||
|
crate::ipc::set_permanent_password(args[1].to_owned()).unwrap();
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
} 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
|
||||||
|
#[cfg(feature = "flutter")]
|
||||||
|
crate::flutter::connection_manager::start_listen_ipc_thread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//_async_logger_holder.map(|x| x.flush());
|
||||||
|
Some(args)
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,6 @@ use crate::{
|
|||||||
|
|
||||||
fn initialize(app_dir: &str) {
|
fn initialize(app_dir: &str) {
|
||||||
*config::APP_DIR.write().unwrap() = app_dir.to_owned();
|
*config::APP_DIR.write().unwrap() = app_dir.to_owned();
|
||||||
#[cfg(feature = "cli")]
|
|
||||||
{
|
|
||||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
|
||||||
{
|
|
||||||
crate::common::test_rendezvous_server();
|
|
||||||
crate::common::test_nat_type();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
{
|
{
|
||||||
android_logger::init_once(
|
android_logger::init_once(
|
||||||
@ -58,13 +50,6 @@ fn initialize(app_dir: &str) {
|
|||||||
{
|
{
|
||||||
crate::common::check_software_update();
|
crate::common::check_software_update();
|
||||||
}
|
}
|
||||||
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
|
|
||||||
{
|
|
||||||
use hbb_common::env_logger::*;
|
|
||||||
if let Err(e) = try_init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "debug")) {
|
|
||||||
log::debug!("{}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FFI for rustdesk core's main entry.
|
/// FFI for rustdesk core's main entry.
|
||||||
@ -72,7 +57,7 @@ fn initialize(app_dir: &str) {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rustdesk_core_main() -> bool {
|
pub extern "C" fn rustdesk_core_main() -> bool {
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
return crate::core_main::core_main();
|
return crate::core_main::core_main().is_some();
|
||||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@ -843,8 +828,6 @@ pub fn main_start_service() {
|
|||||||
config::Config::set_option("stop-service".into(), "".into());
|
config::Config::set_option("stop-service".into(), "".into());
|
||||||
crate::rendezvous_mediator::RendezvousMediator::restart();
|
crate::rendezvous_mediator::RendezvousMediator::restart();
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "android"))]
|
|
||||||
std::thread::spawn(move || start_server(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_update_temporary_password() {
|
pub fn main_update_temporary_password() {
|
||||||
|
13
src/lib.rs
13
src/lib.rs
@ -10,10 +10,10 @@ mod server;
|
|||||||
pub use self::server::*;
|
pub use self::server::*;
|
||||||
mod client;
|
mod client;
|
||||||
#[cfg(not(any(target_os = "ios")))]
|
#[cfg(not(any(target_os = "ios")))]
|
||||||
mod rendezvous_mediator;
|
|
||||||
#[cfg(not(any(target_os = "ios")))]
|
|
||||||
mod lan;
|
mod lan;
|
||||||
#[cfg(not(any(target_os = "ios")))]
|
#[cfg(not(any(target_os = "ios")))]
|
||||||
|
mod rendezvous_mediator;
|
||||||
|
#[cfg(not(any(target_os = "ios")))]
|
||||||
pub use self::rendezvous_mediator::*;
|
pub use self::rendezvous_mediator::*;
|
||||||
/// cbindgen:ignore
|
/// cbindgen:ignore
|
||||||
pub mod common;
|
pub mod common;
|
||||||
@ -30,13 +30,10 @@ pub mod flutter;
|
|||||||
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
|
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
|
||||||
pub mod flutter_ffi;
|
pub mod flutter_ffi;
|
||||||
use common::*;
|
use common::*;
|
||||||
#[cfg(all(
|
|
||||||
not(any(target_os = "android", target_os = "ios")),
|
|
||||||
feature = "flutter"
|
|
||||||
))]
|
|
||||||
pub mod core_main;
|
|
||||||
#[cfg(feature = "cli")]
|
#[cfg(feature = "cli")]
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||||
|
pub mod core_main;
|
||||||
#[cfg(all(windows, feature = "hbbs"))]
|
#[cfg(all(windows, feature = "hbbs"))]
|
||||||
mod hbbs;
|
mod hbbs;
|
||||||
mod lang;
|
mod lang;
|
||||||
@ -47,9 +44,9 @@ mod port_forward;
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod tray;
|
mod tray;
|
||||||
|
|
||||||
|
mod ui_cm_interface;
|
||||||
mod ui_interface;
|
mod ui_interface;
|
||||||
mod ui_session_interface;
|
mod ui_session_interface;
|
||||||
mod ui_cm_interface;
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub mod clipboard_file;
|
pub mod clipboard_file;
|
||||||
|
179
src/main.rs
179
src/main.rs
@ -2,7 +2,6 @@
|
|||||||
// Requires Rust 1.18.
|
// Requires Rust 1.18.
|
||||||
//#![windows_subsystem = "windows"]
|
//#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
use hbb_common::log;
|
|
||||||
use librustdesk::*;
|
use librustdesk::*;
|
||||||
|
|
||||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
@ -15,184 +14,14 @@ fn main() {
|
|||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||||
fn main() {
|
fn main() {
|
||||||
// https://docs.rs/flexi_logger/latest/flexi_logger/error_info/index.html#write
|
if let Some(args) = crate::core_main::core_main().as_mut() {
|
||||||
let mut _async_logger_holder: Option<flexi_logger::LoggerHandle> = None;
|
ui::start(args);
|
||||||
let mut args = Vec::new();
|
|
||||||
let mut i = 0;
|
|
||||||
let mut is_setup = false;
|
|
||||||
for arg in std::env::args() {
|
|
||||||
if i == 0 && common::is_setup(&arg) {
|
|
||||||
is_setup = true;
|
|
||||||
} else if i > 0 {
|
|
||||||
args.push(arg);
|
|
||||||
}
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
if is_setup {
|
|
||||||
if args.is_empty() {
|
|
||||||
args.push("--install".to_owned());
|
|
||||||
} else if args[0] == "--noinstall" {
|
|
||||||
args.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if args.len() > 0 && args[0] == "--version" {
|
|
||||||
println!("{}", crate::VERSION);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "inline"))]
|
|
||||||
{
|
|
||||||
use hbb_common::env_logger::*;
|
|
||||||
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
|
|
||||||
}
|
|
||||||
#[cfg(feature = "inline")]
|
|
||||||
{
|
|
||||||
let mut path = hbb_common::config::Config::log_path();
|
|
||||||
if args.len() > 0 && args[0].starts_with("--") {
|
|
||||||
let name = args[0].replace("--", "");
|
|
||||||
if !name.is_empty() {
|
|
||||||
path.push(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
use flexi_logger::*;
|
|
||||||
if let Ok(x) = Logger::try_with_env_or_str("debug") {
|
|
||||||
_async_logger_holder = x
|
|
||||||
.log_to_file(FileSpec::default().directory(path))
|
|
||||||
.write_mode(WriteMode::Async)
|
|
||||||
.format(opt_format)
|
|
||||||
.rotate(
|
|
||||||
Criterion::Age(Age::Day),
|
|
||||||
Naming::Timestamps,
|
|
||||||
Cleanup::KeepLogFiles(6),
|
|
||||||
)
|
|
||||||
.start()
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if args.is_empty() {
|
|
||||||
std::thread::spawn(move || start_server(false));
|
|
||||||
} else {
|
|
||||||
#[cfg(windows)]
|
|
||||||
{
|
|
||||||
if args[0] == "--uninstall" {
|
|
||||||
if let Err(err) = platform::uninstall_me() {
|
|
||||||
log::error!("Failed to uninstall: {}", err);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if args[0] == "--after-install" {
|
|
||||||
if let Err(err) = platform::run_after_install() {
|
|
||||||
log::error!("Failed to after-install: {}", err);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if args[0] == "--before-uninstall" {
|
|
||||||
if let Err(err) = platform::run_before_uninstall() {
|
|
||||||
log::error!("Failed to before-uninstall: {}", err);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if args[0] == "--update" {
|
|
||||||
hbb_common::allow_err!(platform::update_me());
|
|
||||||
return;
|
|
||||||
} else if args[0] == "--reinstall" {
|
|
||||||
hbb_common::allow_err!(platform::uninstall_me());
|
|
||||||
hbb_common::allow_err!(platform::install_me(
|
|
||||||
"desktopicon startmenu",
|
|
||||||
"".to_owned(),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
} else if args[0] == "--silent-install" {
|
|
||||||
hbb_common::allow_err!(platform::install_me(
|
|
||||||
"desktopicon startmenu",
|
|
||||||
"".to_owned(),
|
|
||||||
true,
|
|
||||||
args.len() > 1,
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
} else if args[0] == "--extract" {
|
|
||||||
#[cfg(feature = "with_rc")]
|
|
||||||
hbb_common::allow_err!(crate::rc::extract_resources(&args[1]));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
} else if args[0] == "--service" {
|
|
||||||
log::info!("start --service");
|
|
||||||
start_os_service();
|
|
||||||
return;
|
|
||||||
} else if args[0] == "--server" {
|
|
||||||
log::info!("start --server");
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
{
|
|
||||||
start_server(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
{
|
|
||||||
std::thread::spawn(move || start_server(true));
|
|
||||||
}
|
|
||||||
} 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;
|
|
||||||
} else if args[0] == "--password" {
|
|
||||||
if args.len() == 2 {
|
|
||||||
ipc::set_permanent_password(args[1].to_owned()).unwrap();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if args[0] == "--check-hwcodec-config" {
|
|
||||||
#[cfg(feature = "hwcodec")]
|
|
||||||
scrap::hwcodec::check_config();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui::start(&mut args[..]);
|
|
||||||
_async_logger_holder.map(|x| x.flush());
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "cli")]
|
#[cfg(feature = "cli")]
|
||||||
fn main() {
|
fn main() {
|
||||||
|
use hbb_common::log;
|
||||||
use clap::App;
|
use clap::App;
|
||||||
let args = format!(
|
let args = format!(
|
||||||
"-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]'
|
"-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]'
|
||||||
@ -235,4 +64,4 @@ fn main() {
|
|||||||
let token = LocalConfig::get_option("access_token");
|
let token = LocalConfig::get_option("access_token");
|
||||||
cli::start_one_port_forward(options[0].clone(), port, remote_host, remote_port, key, token);
|
cli::start_one_port_forward(options[0].clone(), port, remote_host, remote_port, key, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user