From ea106354af1a124ba877fade3f23ef25c86c7eba Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Mon, 12 May 2025 21:46:05 +0800 Subject: [PATCH] fix: win, only start tray if is installed exe (#11737) Signed-off-by: fufesou --- src/core_main.rs | 7 ++++--- src/platform/windows.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index 0805e32cd..771ee4ca8 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -78,13 +78,14 @@ pub fn core_main() -> Option> { #[cfg(any(target_os = "linux", target_os = "windows"))] if args.is_empty() { #[cfg(target_os = "linux")] - let is_server_running = crate::check_process("--server", false); + let should_check_start_tray = crate::check_process("--server", false); // We can use `crate::check_process("--server", false)` on Windows. // Because `--server` process is the System user's process. We can't get the arguments in `check_process()`. // We can assume that self service running means the server is also running on Windows. #[cfg(target_os = "windows")] - let is_server_running = crate::platform::is_self_service_running(); - if is_server_running && !crate::check_process("--tray", true) { + let should_check_start_tray = crate::platform::is_self_service_running() + && crate::platform::is_cur_exe_the_installed(); + if should_check_start_tray && !crate::check_process("--tray", true) { #[cfg(target_os = "linux")] hbb_common::allow_err!(crate::platform::check_autostart_config()); hbb_common::allow_err!(crate::run_me(vec!["--tray"])); diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 63302cfad..f17b21044 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -3177,6 +3177,20 @@ pub fn is_msi_installed() -> std::io::Result { Ok(1 == uninstall_key.get_value::("WindowsInstaller")?) } +pub fn is_cur_exe_the_installed() -> bool { + let (_, _, _, exe) = get_install_info(); + // Check if is installed, because `exe` is the default path if is not installed. + if !std::fs::metadata(&exe).is_ok() { + return false; + } + let mut path = std::env::current_exe().unwrap_or_default(); + if let Ok(linked) = path.read_link() { + path = linked; + } + let path = path.to_string_lossy().to_lowercase(); + path == exe.to_lowercase() +} + #[cfg(not(target_pointer_width = "64"))] pub fn get_pids_with_first_arg_check_session, S2: AsRef>( name: S1,