mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-05-13 03:16:17 +02:00
parent
e8ea2f383f
commit
c69d59596b
4 changed files with 38 additions and 21 deletions
|
@ -202,7 +202,10 @@ class ServerModel with ChangeNotifier {
|
||||||
temporaryPassword.isNotEmpty) {
|
temporaryPassword.isNotEmpty) {
|
||||||
_serverPasswd.text = temporaryPassword;
|
_serverPasswd.text = temporaryPassword;
|
||||||
}
|
}
|
||||||
if (verificationMethod == kUsePermanentPassword ||
|
var stopped = option2bool(
|
||||||
|
"stop-service", await bind.mainGetOption(key: "stop-service"));
|
||||||
|
if (stopped ||
|
||||||
|
verificationMethod == kUsePermanentPassword ||
|
||||||
_approveMode == 'click') {
|
_approveMode == 'click') {
|
||||||
_serverPasswd.text = '-';
|
_serverPasswd.text = '-';
|
||||||
}
|
}
|
||||||
|
|
14
src/ipc.rs
14
src/ipc.rs
|
@ -1,4 +1,7 @@
|
||||||
use std::{collections::HashMap, sync::atomic::Ordering};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
|
};
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use std::{fs::File, io::prelude::*};
|
use std::{fs::File, io::prelude::*};
|
||||||
|
|
||||||
|
@ -38,6 +41,7 @@ pub enum PrivacyModeState {
|
||||||
}
|
}
|
||||||
// IPC actions here.
|
// IPC actions here.
|
||||||
pub const IPC_ACTION_CLOSE: &str = "close";
|
pub const IPC_ACTION_CLOSE: &str = "close";
|
||||||
|
pub static EXIT_RECV_CLOSE: AtomicBool = AtomicBool::new(true);
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(tag = "t", content = "c")]
|
#[serde(tag = "t", content = "c")]
|
||||||
|
@ -334,9 +338,11 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||||
}
|
}
|
||||||
Data::Close => {
|
Data::Close => {
|
||||||
log::info!("Receive close message");
|
log::info!("Receive close message");
|
||||||
#[cfg(not(target_os = "android"))]
|
if EXIT_RECV_CLOSE.load(Ordering::SeqCst) {
|
||||||
crate::server::input_service::fix_key_down_timeout_at_exit();
|
#[cfg(not(target_os = "android"))]
|
||||||
std::process::exit(0);
|
crate::server::input_service::fix_key_down_timeout_at_exit();
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Data::OnlineStatus(_) => {
|
Data::OnlineStatus(_) => {
|
||||||
let x = config::ONLINE
|
let x = config::ONLINE
|
||||||
|
|
|
@ -21,7 +21,7 @@ use std::{
|
||||||
os::windows::process::CommandExt,
|
os::windows::process::CommandExt,
|
||||||
path::*,
|
path::*,
|
||||||
ptr::null_mut,
|
ptr::null_mut,
|
||||||
sync::{Arc, Mutex},
|
sync::{atomic::Ordering, Arc, Mutex},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
use winapi::{
|
use winapi::{
|
||||||
|
@ -947,7 +947,7 @@ pub fn update_me() -> ResultType<()> {
|
||||||
cur_pid = get_current_pid(),
|
cur_pid = get_current_pid(),
|
||||||
);
|
);
|
||||||
run_cmds(cmds, false, "update")?;
|
run_cmds(cmds, false, "update")?;
|
||||||
run_after_run_cmds(false)?;
|
run_after_run_cmds(false);
|
||||||
std::process::Command::new(&exe)
|
std::process::Command::new(&exe)
|
||||||
.args(&["--remove", &src_exe])
|
.args(&["--remove", &src_exe])
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
@ -1143,7 +1143,7 @@ copy /Y \"{tmp_path}\\Uninstall {app_name}.lnk\" \"{path}\\\"
|
||||||
import_config = get_import_config(&exe),
|
import_config = get_import_config(&exe),
|
||||||
);
|
);
|
||||||
run_cmds(cmds, debug, "install")?;
|
run_cmds(cmds, debug, "install")?;
|
||||||
run_after_run_cmds(silent)?;
|
run_after_run_cmds(silent);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2152,6 +2152,7 @@ impl Drop for WakeLock {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uninstall_service(show_new_window: bool) -> ResultType<()> {
|
pub fn uninstall_service(show_new_window: bool) -> ResultType<()> {
|
||||||
|
log::info!("Uninstalling service...");
|
||||||
let filter = format!(" /FI \"PID ne {}\"", get_current_pid());
|
let filter = format!(" /FI \"PID ne {}\"", get_current_pid());
|
||||||
Config::set_option("stop-service".into(), "Y".into());
|
Config::set_option("stop-service".into(), "Y".into());
|
||||||
let cmds = format!(
|
let cmds = format!(
|
||||||
|
@ -2168,25 +2169,27 @@ pub fn uninstall_service(show_new_window: bool) -> ResultType<()> {
|
||||||
Config::set_option("stop-service".into(), "".into());
|
Config::set_option("stop-service".into(), "".into());
|
||||||
bail!(err);
|
bail!(err);
|
||||||
}
|
}
|
||||||
run_after_run_cmds(!show_new_window)?;
|
run_after_run_cmds(!show_new_window);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn install_service() -> ResultType<()> {
|
pub fn install_service() -> ResultType<()> {
|
||||||
|
log::info!("Installing service...");
|
||||||
let (_, _, _, exe) = get_install_info();
|
let (_, _, _, exe) = get_install_info();
|
||||||
let tmp_path = std::env::temp_dir().to_string_lossy().to_string();
|
let tmp_path = std::env::temp_dir().to_string_lossy().to_string();
|
||||||
let tray_shortcut = get_tray_shortcut(&exe, &tmp_path)?;
|
let tray_shortcut = get_tray_shortcut(&exe, &tmp_path)?;
|
||||||
let filter = format!(" /FI \"PID ne {}\"", get_current_pid());
|
let filter = format!(" /FI \"PID ne {}\"", get_current_pid());
|
||||||
Config::set_option("stop-service".into(), "".into());
|
Config::set_option("stop-service".into(), "".into());
|
||||||
|
crate::ipc::EXIT_RECV_CLOSE.store(false, Ordering::Relaxed);
|
||||||
let cmds = format!(
|
let cmds = format!(
|
||||||
"
|
"
|
||||||
chcp 65001
|
chcp 65001
|
||||||
|
taskkill /F /IM {app_name}.exe{filter}
|
||||||
cscript \"{tray_shortcut}\"
|
cscript \"{tray_shortcut}\"
|
||||||
copy /Y \"{tmp_path}\\{app_name} Tray.lnk\" \"%PROGRAMDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\\"
|
copy /Y \"{tmp_path}\\{app_name} Tray.lnk\" \"%PROGRAMDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\\"
|
||||||
{import_config}
|
{import_config}
|
||||||
{create_service}
|
{create_service}
|
||||||
if exist \"{tray_shortcut}\" del /f /q \"{tray_shortcut}\"
|
if exist \"{tray_shortcut}\" del /f /q \"{tray_shortcut}\"
|
||||||
taskkill /F /IM {app_name}.exe{filter}
|
|
||||||
",
|
",
|
||||||
app_name = crate::get_app_name(),
|
app_name = crate::get_app_name(),
|
||||||
import_config = get_import_config(&exe),
|
import_config = get_import_config(&exe),
|
||||||
|
@ -2194,9 +2197,10 @@ taskkill /F /IM {app_name}.exe{filter}
|
||||||
);
|
);
|
||||||
if let Err(err) = run_cmds(cmds, false, "install") {
|
if let Err(err) = run_cmds(cmds, false, "install") {
|
||||||
Config::set_option("stop-service".into(), "Y".into());
|
Config::set_option("stop-service".into(), "Y".into());
|
||||||
|
crate::ipc::EXIT_RECV_CLOSE.store(true, Ordering::Relaxed);
|
||||||
bail!(err);
|
bail!(err);
|
||||||
}
|
}
|
||||||
run_after_run_cmds(false)?;
|
run_after_run_cmds(false);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2224,6 +2228,8 @@ oLink.Save
|
||||||
|
|
||||||
fn get_import_config(exe: &str) -> String {
|
fn get_import_config(exe: &str) -> String {
|
||||||
format!("
|
format!("
|
||||||
|
sc stop {app_name}
|
||||||
|
sc delete {app_name}
|
||||||
sc create {app_name} binpath= \"\\\"{exe}\\\" --import-config \\\"{config_path}\\\"\" start= auto DisplayName= \"{app_name} Service\"
|
sc create {app_name} binpath= \"\\\"{exe}\\\" --import-config \\\"{config_path}\\\"\" start= auto DisplayName= \"{app_name} Service\"
|
||||||
sc start {app_name}
|
sc start {app_name}
|
||||||
sc stop {app_name}
|
sc stop {app_name}
|
||||||
|
@ -2249,17 +2255,20 @@ sc start {app_name}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_after_run_cmds(silent: bool) -> ResultType<()> {
|
fn run_after_run_cmds(silent: bool) {
|
||||||
let (_, _, _, exe) = get_install_info();
|
let (_, _, _, exe) = get_install_info();
|
||||||
std::thread::sleep(std::time::Duration::from_millis(2000));
|
|
||||||
if !silent {
|
if !silent {
|
||||||
std::process::Command::new(&exe).spawn()?;
|
log::debug!("Spawn new window");
|
||||||
|
allow_err!(std::process::Command::new("cmd")
|
||||||
|
.arg("/c")
|
||||||
|
.arg("timeout /t 2 & start rustdesk://")
|
||||||
|
.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW)
|
||||||
|
.spawn());
|
||||||
}
|
}
|
||||||
if Config::get_option("stop-service") != "Y" {
|
if Config::get_option("stop-service") != "Y" {
|
||||||
std::process::Command::new(&exe).arg("--tray").spawn()?;
|
allow_err!(std::process::Command::new(&exe).arg("--tray").spawn());
|
||||||
}
|
}
|
||||||
std::thread::sleep(std::time::Duration::from_millis(1000));
|
std::thread::sleep(std::time::Duration::from_millis(300));
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub fn get_id() -> String {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn goto_install() {
|
pub fn goto_install() {
|
||||||
allow_err!(crate::run_me(vec!["--install"]));
|
allow_err!(crate::run_me(vec!["--install"]));
|
||||||
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -277,19 +278,17 @@ pub fn set_option(key: String, value: String) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
#[cfg(any(target_os = "windows"))]
|
#[cfg(any(target_os = "windows"))]
|
||||||
{
|
{
|
||||||
if crate::platform::is_installed() {
|
if crate::platform::is_installed() {
|
||||||
if value == "Y" {
|
if value == "Y" {
|
||||||
crate::platform::install_service().ok();
|
allow_err!(crate::platform::uninstall_service(true));
|
||||||
} else {
|
} else {
|
||||||
crate::platform::uninstall_service(true).ok();
|
allow_err!(crate::platform::install_service());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
options.remove(&key);
|
options.remove(&key);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue