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) {
|
||||
_serverPasswd.text = temporaryPassword;
|
||||
}
|
||||
if (verificationMethod == kUsePermanentPassword ||
|
||||
var stopped = option2bool(
|
||||
"stop-service", await bind.mainGetOption(key: "stop-service"));
|
||||
if (stopped ||
|
||||
verificationMethod == kUsePermanentPassword ||
|
||||
_approveMode == 'click') {
|
||||
_serverPasswd.text = '-';
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use std::{collections::HashMap, sync::atomic::Ordering};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
#[cfg(not(windows))]
|
||||
use std::{fs::File, io::prelude::*};
|
||||
|
||||
|
@ -38,6 +41,7 @@ pub enum PrivacyModeState {
|
|||
}
|
||||
// IPC actions here.
|
||||
pub const IPC_ACTION_CLOSE: &str = "close";
|
||||
pub static EXIT_RECV_CLOSE: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
|
@ -334,10 +338,12 @@ async fn handle(data: Data, stream: &mut Connection) {
|
|||
}
|
||||
Data::Close => {
|
||||
log::info!("Receive close message");
|
||||
if EXIT_RECV_CLOSE.load(Ordering::SeqCst) {
|
||||
#[cfg(not(target_os = "android"))]
|
||||
crate::server::input_service::fix_key_down_timeout_at_exit();
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
Data::OnlineStatus(_) => {
|
||||
let x = config::ONLINE
|
||||
.lock()
|
||||
|
|
|
@ -21,7 +21,7 @@ use std::{
|
|||
os::windows::process::CommandExt,
|
||||
path::*,
|
||||
ptr::null_mut,
|
||||
sync::{Arc, Mutex},
|
||||
sync::{atomic::Ordering, Arc, Mutex},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use winapi::{
|
||||
|
@ -947,7 +947,7 @@ pub fn update_me() -> ResultType<()> {
|
|||
cur_pid = get_current_pid(),
|
||||
);
|
||||
run_cmds(cmds, false, "update")?;
|
||||
run_after_run_cmds(false)?;
|
||||
run_after_run_cmds(false);
|
||||
std::process::Command::new(&exe)
|
||||
.args(&["--remove", &src_exe])
|
||||
.spawn()?;
|
||||
|
@ -1143,7 +1143,7 @@ copy /Y \"{tmp_path}\\Uninstall {app_name}.lnk\" \"{path}\\\"
|
|||
import_config = get_import_config(&exe),
|
||||
);
|
||||
run_cmds(cmds, debug, "install")?;
|
||||
run_after_run_cmds(silent)?;
|
||||
run_after_run_cmds(silent);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -2152,6 +2152,7 @@ impl Drop for WakeLock {
|
|||
}
|
||||
|
||||
pub fn uninstall_service(show_new_window: bool) -> ResultType<()> {
|
||||
log::info!("Uninstalling service...");
|
||||
let filter = format!(" /FI \"PID ne {}\"", get_current_pid());
|
||||
Config::set_option("stop-service".into(), "Y".into());
|
||||
let cmds = format!(
|
||||
|
@ -2168,25 +2169,27 @@ pub fn uninstall_service(show_new_window: bool) -> ResultType<()> {
|
|||
Config::set_option("stop-service".into(), "".into());
|
||||
bail!(err);
|
||||
}
|
||||
run_after_run_cmds(!show_new_window)?;
|
||||
run_after_run_cmds(!show_new_window);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
pub fn install_service() -> ResultType<()> {
|
||||
log::info!("Installing service...");
|
||||
let (_, _, _, exe) = get_install_info();
|
||||
let tmp_path = std::env::temp_dir().to_string_lossy().to_string();
|
||||
let tray_shortcut = get_tray_shortcut(&exe, &tmp_path)?;
|
||||
let filter = format!(" /FI \"PID ne {}\"", get_current_pid());
|
||||
Config::set_option("stop-service".into(), "".into());
|
||||
crate::ipc::EXIT_RECV_CLOSE.store(false, Ordering::Relaxed);
|
||||
let cmds = format!(
|
||||
"
|
||||
chcp 65001
|
||||
taskkill /F /IM {app_name}.exe{filter}
|
||||
cscript \"{tray_shortcut}\"
|
||||
copy /Y \"{tmp_path}\\{app_name} Tray.lnk\" \"%PROGRAMDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\\"
|
||||
{import_config}
|
||||
{create_service}
|
||||
if exist \"{tray_shortcut}\" del /f /q \"{tray_shortcut}\"
|
||||
taskkill /F /IM {app_name}.exe{filter}
|
||||
",
|
||||
app_name = crate::get_app_name(),
|
||||
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") {
|
||||
Config::set_option("stop-service".into(), "Y".into());
|
||||
crate::ipc::EXIT_RECV_CLOSE.store(true, Ordering::Relaxed);
|
||||
bail!(err);
|
||||
}
|
||||
run_after_run_cmds(false)?;
|
||||
run_after_run_cmds(false);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
|
@ -2224,6 +2228,8 @@ oLink.Save
|
|||
|
||||
fn get_import_config(exe: &str) -> String {
|
||||
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 start {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();
|
||||
std::thread::sleep(std::time::Duration::from_millis(2000));
|
||||
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" {
|
||||
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));
|
||||
Ok(())
|
||||
std::thread::sleep(std::time::Duration::from_millis(300));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -59,6 +59,7 @@ pub fn get_id() -> String {
|
|||
#[inline]
|
||||
pub fn goto_install() {
|
||||
allow_err!(crate::run_me(vec!["--install"]));
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -277,19 +278,17 @@ pub fn set_option(key: String, value: String) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
#[cfg(any(target_os = "windows"))]
|
||||
{
|
||||
if crate::platform::is_installed() {
|
||||
if value == "Y" {
|
||||
crate::platform::install_service().ok();
|
||||
allow_err!(crate::platform::uninstall_service(true));
|
||||
} else {
|
||||
crate::platform::uninstall_service(true).ok();
|
||||
allow_err!(crate::platform::install_service());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
if value.is_empty() {
|
||||
options.remove(&key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue