Merge pull request #2225 from 21pages/portable-service

portable-service: enable quick support by rename as xxxqs.exe
This commit is contained in:
RustDesk
2022-11-19 13:53:21 +08:00
committed by GitHub
9 changed files with 49 additions and 46 deletions

View File

@@ -14,6 +14,7 @@ pub fn core_main() -> Option<Vec<String>> {
let mut i = 0;
let mut _is_elevate = false;
let mut _is_run_as_system = false;
let mut _is_quick_support = false;
let mut _is_flutter_connect = false;
let mut arg_exe = Default::default();
for arg in std::env::args() {
@@ -29,6 +30,8 @@ pub fn core_main() -> Option<Vec<String>> {
_is_elevate = true;
} else if arg == "--run-as-system" {
_is_run_as_system = true;
} else if arg == "--quick_support" {
_is_quick_support = true;
} else {
args.push(arg);
}
@@ -40,6 +43,11 @@ pub fn core_main() -> Option<Vec<String>> {
return core_main_invoke_new_connection(std::env::args());
}
let click_setup = cfg!(windows) && args.is_empty() && crate::common::is_setup(&arg_exe);
#[cfg(not(feature = "flutter"))]
{
_is_quick_support =
cfg!(windows) && args.is_empty() && arg_exe.to_lowercase().ends_with("qs.exe");
}
if click_setup {
args.push("--install".to_owned());
flutter_args.push("--install".to_string());
@@ -81,8 +89,12 @@ pub fn core_main() -> Option<Vec<String>> {
}
}
#[cfg(windows)]
#[cfg(feature = "quick_start")]
if !crate::platform::is_installed() && args.is_empty() && !_is_elevate && !_is_run_as_system {
if !crate::platform::is_installed()
&& args.is_empty()
&& _is_quick_support
&& !_is_elevate
&& !_is_run_as_system
{
if let Err(e) = crate::portable_service::client::start_portable_service() {
log::error!("Failed to start portable service:{:?}", e);
}

View File

@@ -1178,6 +1178,7 @@ pub fn main_account_auth_result() -> String {
}
pub fn main_on_main_window_close() {
// may called more than one times
#[cfg(windows)]
crate::portable_service::client::drop_portable_service_shared_memory();
}

View File

@@ -237,11 +237,10 @@ pub mod server {
fn run_exit_check() {
loop {
if EXIT.lock().unwrap().clone() {
std::thread::sleep(Duration::from_secs(1));
log::info!("exit from seperate check thread");
std::thread::sleep(Duration::from_millis(50));
std::process::exit(0);
}
std::thread::sleep(Duration::from_secs(1));
std::thread::sleep(Duration::from_millis(50));
}
}
@@ -406,9 +405,8 @@ pub mod server {
Pong => {
nack = 0;
}
ConnCount(Some(_n)) => {
#[cfg(not(feature = "quick_start"))]
if _n == 0 {
ConnCount(Some(n)) => {
if n == 0 {
log::info!("Connnection count equals 0, exit");
stream.send(&Data::DataPortableService(WillClose)).await.ok();
break;
@@ -436,7 +434,6 @@ pub mod server {
break;
}
stream.send(&Data::DataPortableService(Ping)).await.ok();
#[cfg(not(feature = "quick_start"))]
stream.send(&Data::DataPortableService(ConnCount(None))).await.ok();
}
}
@@ -626,6 +623,17 @@ pub mod client {
use DataPortableService::*;
let rx = Arc::new(tokio::sync::Mutex::new(rx));
let postfix = IPC_PROFIX;
#[cfg(feature = "flutter")]
let quick_support = {
let args: Vec<_> = std::env::args().collect();
args.contains(&"--quick_support".to_string())
};
#[cfg(not(feature = "flutter"))]
let quick_support = std::env::current_exe()
.unwrap_or("".into())
.to_string_lossy()
.to_lowercase()
.ends_with("qs.exe");
match new_listener(postfix).await {
Ok(mut incoming) => loop {
@@ -663,8 +671,10 @@ pub mod client {
*PORTABLE_SERVICE_RUNNING.lock().unwrap() = true;
},
ConnCount(None) => {
let cnt = crate::server::CONN_COUNT.lock().unwrap().clone();
stream.send(&Data::DataPortableService(ConnCount(Some(cnt)))).await.ok();
if !quick_support {
let cnt = crate::server::CONN_COUNT.lock().unwrap().clone();
stream.send(&Data::DataPortableService(ConnCount(Some(cnt)))).await.ok();
}
},
WillClose => {
log::info!("portable service will close");

View File

@@ -15,7 +15,7 @@ use hbb_common::{
protobuf::Message as _,
rendezvous_proto::*,
tcp::FramedStream,
tokio::{self, sync::mpsc},
tokio,
};
use crate::common::get_app_name;
@@ -44,23 +44,6 @@ lazy_static::lazy_static! {
struct UIHostHandler;
// to-do: dead code?
fn check_connect_status(
reconnect: bool,
) -> (
Arc<Mutex<Status>>,
Arc<Mutex<HashMap<String, String>>>,
mpsc::UnboundedSender<ipc::Data>,
Arc<Mutex<String>>,
) {
let status = Arc::new(Mutex::new((0, false, 0, "".to_owned())));
let options = Arc::new(Mutex::new(Config::get_options()));
let (tx, rx) = mpsc::unbounded_channel::<ipc::Data>();
let password = Arc::new(Mutex::new(String::default()));
std::thread::spawn(move || crate::ui_interface::check_connect_status_(reconnect, rx));
(status, options, tx, password)
}
pub fn start(args: &mut [String]) {
#[cfg(target_os = "macos")]
macos::show_dock();