diff --git a/agent/src/main.rs b/agent/src/main.rs index a724bf0..824ec5c 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -165,12 +165,11 @@ async fn main() -> Result<()> { } /// Clean up before exiting (remove from startup, etc.) -fn cleanup_on_exit(is_support_session: bool) { - if is_support_session { - info!("Cleaning up before exit"); - if let Err(e) = startup::remove_from_startup() { - warn!("Failed to remove from startup: {}", e); - } +/// Called when user explicitly ends session or support session completes +fn cleanup_on_exit() { + info!("Cleaning up before exit"); + if let Err(e) = startup::remove_from_startup() { + warn!("Failed to remove from startup: {}", e); } } @@ -181,10 +180,10 @@ async fn run_agent(config: config::Config) -> Result<()> { let hostname = config.hostname(); // Add to startup so we reconnect after reboot - if is_support_session { - if let Err(e) = startup::add_to_startup() { - warn!("Failed to add to startup: {}. Agent won't persist through reboot.", e); - } + // Persistent agents (no support code) should ALWAYS be in startup + // Support sessions only need startup temporarily while active + if let Err(e) = startup::add_to_startup() { + warn!("Failed to add to startup: {}. Agent won't persist through reboot.", e); } // Create tray icon @@ -233,14 +232,14 @@ async fn run_agent(config: config::Config) -> Result<()> { // Check if this is a user-initiated exit if error_msg.contains("USER_EXIT") { info!("Session ended by user"); - cleanup_on_exit(is_support_session); + cleanup_on_exit(); return Ok(()); } // Check if this is a cancellation if error_msg.contains("SESSION_CANCELLED") { info!("Session was cancelled by technician"); - cleanup_on_exit(is_support_session); + cleanup_on_exit(); show_message_box( "Support Session Ended", "The support session was cancelled by the technician.\n\nThis window will close automatically.", @@ -271,7 +270,7 @@ async fn run_agent(config: config::Config) -> Result<()> { // Check if connection was rejected due to cancelled code if error_msg.contains("cancelled") { info!("Support code was cancelled before connection"); - cleanup_on_exit(is_support_session); + cleanup_on_exit(); show_message_box( "Support Session Cancelled", "This support session has been cancelled.\n\nPlease contact your technician for a new support code.", @@ -287,7 +286,7 @@ async fn run_agent(config: config::Config) -> Result<()> { // For support sessions, don't reconnect if something goes wrong if is_support_session { info!("Support session ended, not reconnecting"); - cleanup_on_exit(is_support_session); + cleanup_on_exit(); return Ok(()); } @@ -295,7 +294,7 @@ async fn run_agent(config: config::Config) -> Result<()> { if let Some(ref t) = tray { if t.exit_requested() { info!("Exit requested by user"); - cleanup_on_exit(is_support_session); + cleanup_on_exit(); return Ok(()); } }