Fix persistence logic for persistent vs support sessions
- Persistent agents (no code) now add to startup on launch - All agents add to startup, cleanup removes it on explicit exit - Persistent agents reconnect automatically on disconnect - Support sessions still exit without reconnecting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -165,13 +165,12 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
/// Clean up before exiting (remove from startup, etc.)
|
||||
fn cleanup_on_exit(is_support_session: bool) {
|
||||
if is_support_session {
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_agent(config: config::Config) -> Result<()> {
|
||||
@@ -181,11 +180,11 @@ async fn run_agent(config: config::Config) -> Result<()> {
|
||||
let hostname = config.hostname();
|
||||
|
||||
// Add to startup so we reconnect after reboot
|
||||
if is_support_session {
|
||||
// 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
|
||||
let tray = match tray::TrayController::new(&hostname, config.support_code.as_deref()) {
|
||||
@@ -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(());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user