An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.
Rust androidanydeskdartflatpakflutterflutter-appsioslinuxmacosp2prdpremote-controlremote-desktoprustrust-langteamviewervncwaylandwindows
fix(windows): show an installation tip for a missing service (#16948)
fufesou304e60492dc8
diff --git a/flutter/lib/desktop/pages/desktop_home_page.dart b/flutter/lib/desktop/pages/desktop_home_page.dartindex b9e6c98f2..e6f5a41aa 100644--- a/flutter/lib/desktop/pages/desktop_home_page.dart+++ b/flutter/lib/desktop/pages/desktop_home_page.dart@@ -428,6 +428,17 @@ class _DesktopHomePageState extends State<DesktopHomePage>}Widget buildHelpCards(String updateUrl) {+ if (isWindows &&+ !bind.isDisableInstallation() &&+ bind.mainIsInstalled() &&+ !bind.isOutgoingOnly() &&+ !mainGetBoolOptionSync(kOptionStopService) &&+ !bind.mainIsInstalledDaemon(prompt: false)) {+ return buildInstallCard("", "install_daemon_tip", "Install", () async {+ await rustDeskWinManager.closeAllSubWindows();+ await start_service(true);+ });+ }if (!bind.isCustomClient() &&updateUrl.isNotEmpty &&!isCardClosed &&diff --git a/src/platform/mod.rs b/src/platform/mod.rsindex add10e78f..f663dd4ea 100644--- a/src/platform/mod.rs+++ b/src/platform/mod.rs@@ -150,14 +150,25 @@ pub fn get_wakelock(_display: bool) -> WakeLock {}#[cfg(any(target_os = "windows", target_os = "linux"))]-pub(crate) struct InstallingService; // please use new+pub(crate) struct InstallingService; // please use a constructor#[cfg(any(target_os = "windows", target_os = "linux"))]impl InstallingService {+ #[cfg(target_os = "linux")]pub fn new() -> Self {*INSTALLING_SERVICE.lock().unwrap() = true;Self}++ #[cfg(windows)]+ pub fn try_new() -> Option<Self> {+ let mut installing = INSTALLING_SERVICE.lock().unwrap();+ if *installing {+ return None;+ }+ *installing = true;+ Some(Self)+ }}#[cfg(any(target_os = "windows", target_os = "linux"))]diff --git a/src/platform/windows.rs b/src/platform/windows.rsindex 03d2b5eea..d7d194a6a 100644--- a/src/platform/windows.rs+++ b/src/platform/windows.rs@@ -71,7 +71,9 @@ use winapi::{},};use windows::Win32::{- Foundation::{CloseHandle as WinCloseHandle, HANDLE as WinHANDLE},+ Foundation::{+ CloseHandle as WinCloseHandle, ERROR_SERVICE_DOES_NOT_EXIST, HANDLE as WinHANDLE,+ },Security::{GetTokenInformation as WinGetTokenInformation, IsWellKnownSid, TokenUser,WinLocalSystemSid, TOKEN_QUERY as WIN_TOKEN_QUERY, TOKEN_USER,@@ -89,10 +91,11 @@ use windows::Win32::{use windows_service::{define_windows_service,service::{- ServiceControl, ServiceControlAccept, ServiceExitCode, ServiceState, ServiceStatus,- ServiceType,+ ServiceAccess, ServiceControl, ServiceControlAccept, ServiceExitCode, ServiceState,+ ServiceStatus, ServiceType,},service_control_handler::{self, ServiceControlHandlerResult},+ service_manager::{ServiceManager, ServiceManagerAccess},};use winreg::{enums::*, RegKey};@@ -3476,21 +3479,25 @@ copy /Y \"%RUSTDESK_OUTPUT_DIR%\\{app_name} Tray.lnk\" \"%PROGRAMDATA%\\Microsof}pub fn install_service() -> bool {+ let Some(_installing) = crate::platform::InstallingService::try_new() else {+ log::trace!("Service installation is already in progress");+ return true;+ };log::info!("Installing service...");- let _installing = crate::platform::InstallingService::new();let (_, path, _, exe) = get_install_info();+ let previous_stop_service = Config::get_option("stop-service");Config::set_option("stop-service".into(), "".into());let cmds = match get_install_service_commands(&path, &exe) {Ok(cmds) => cmds,Err(err) => {- Config::set_option("stop-service".into(), "Y".into());+ Config::set_option("stop-service".into(), previous_stop_service);log::error!("Failed to prepare service installation: {err}");return true;}};crate::ipc::EXIT_RECV_CLOSE.store(false, Ordering::Relaxed);if let Err(err) = run_cmds(cmds, false, "install") {- Config::set_option("stop-service".into(), "Y".into());+ Config::set_option("stop-service".into(), previous_stop_service);crate::ipc::EXIT_RECV_CLOSE.store(true, Ordering::Relaxed);log::debug!("{err}");return true;@@ -4356,6 +4363,29 @@ pub fn is_service_running(service_name: &str) -> bool {}}+pub fn is_installed_daemon() -> bool {+ const SERVICE_QUERY_LOG_INTERVAL: std::time::Duration = std::time::Duration::from_secs(30);+ let service_name = crate::get_app_name();+ let service = ServiceManager::local_computer(None::<&str>, ServiceManagerAccess::CONNECT)+ .and_then(|manager| manager.open_service(&service_name, ServiceAccess::QUERY_STATUS));+ match service {+ Ok(_) => true,+ Err(windows_service::Error::Winapi(error))+ if error.raw_os_error() == Some(ERROR_SERVICE_DOES_NOT_EXIST.0 as i32) =>+ {+ false+ }+ Err(error) => {+ hbb_common::throttled_log!(+ SERVICE_QUERY_LOG_INTERVAL,+ error,+ "Failed to query service registration for {service_name}; suppressing installation tip: {error:?}"+ );+ true+ }+ }+}+pub fn is_x64() -> bool {const PROCESSOR_ARCHITECTURE_AMD64: u16 = 9;diff --git a/src/ui/index.tis b/src/ui/index.tisindex 905e679f1..4fee0bcfd 100644--- a/src/ui/index.tis+++ b/src/ui/index.tis@@ -711,6 +711,8 @@ class App: Reactor.Componentfunction render() {var is_can_screen_recording = handler.is_can_screen_recording(false);+ var show_install_daemon = is_win && !disable_installation && !outgoing_only && !service_stopped &&+ handler.is_installed() && !handler.is_installed_daemon(false);return<div .app><div .left-pane style={incoming_only ? "width:*" : ""}>@@ -729,11 +731,11 @@ class App: Reactor.Component{!outgoing_only && <PasswordArea />}</div>{(!is_win || handler.is_installed() || disable_installation) ? "" : <InstallMe />}- {software_update_url && !disable_installation ? <UpdateMe /> : ""}- {is_win && handler.is_installed() && !software_update_url && handler.is_installed_lower_version() && !disable_installation ? <UpgradeMe /> : ""}+ {software_update_url && !disable_installation && !show_install_daemon ? <UpdateMe /> : ""}+ {!show_install_daemon && is_win && handler.is_installed() && !software_update_url && handler.is_installed_lower_version() && !disable_installation ? <UpgradeMe /> : ""}{is_can_screen_recording ? "": <CanScreenRecording />}{is_can_screen_recording && !handler.is_process_trusted(false) ? <TrustMe /> : ""}- {!service_stopped && is_can_screen_recording && handler.is_process_trusted(false) && handler.is_installed() && !handler.is_installed_daemon(false) ? <InstallDaemon /> : ""}+ {(is_win ? show_install_daemon : !service_stopped && is_can_screen_recording && handler.is_process_trusted(false) && handler.is_installed() && !handler.is_installed_daemon(false)) ? <InstallDaemon /> : ""}{system_error ? <SystemError /> : ""}{!system_error && handler.is_login_wayland() && !handler.current_is_wayland() ? <FixWayland /> : ""}{!system_error && handler.current_is_wayland() ? <ModifyDefaultLogin /> : ""}@@ -922,7 +924,11 @@ class InstallDaemon: Reactor.Component {}event click $(#install-me) {- handler.is_installed_daemon(true);+ if (is_win) {+ handler.set_option("stop-service", default_option_no);+ } else {+ handler.is_installed_daemon(true);+ }}}diff --git a/src/ui_interface.rs b/src/ui_interface.rsindex 995d6d0cf..3c3f8cc4d 100644--- a/src/ui_interface.rs+++ b/src/ui_interface.rs@@ -747,7 +747,9 @@ pub fn is_can_screen_recording(_prompt: bool) -> bool {pub fn is_installed_daemon(_prompt: bool) -> bool {#[cfg(target_os = "macos")]return crate::platform::macos::is_installed_daemon(_prompt);- #[cfg(not(target_os = "macos"))]+ #[cfg(target_os = "windows")]+ return crate::platform::windows::is_installed_daemon();+ #[cfg(not(any(target_os = "macos", target_os = "windows")))]return true;}