Add startup persistence for support sessions
- Added startup.rs module for Windows registry operations - Agent adds itself to HKCU\...\Run on session start - Agent removes itself from startup on session end - Works with user-level registry (no admin required) - Added Win32_System_Registry feature to windows crate 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ mod config;
|
||||
mod encoder;
|
||||
mod input;
|
||||
mod session;
|
||||
mod startup;
|
||||
mod transport;
|
||||
mod tray;
|
||||
|
||||
@@ -162,12 +163,29 @@ async fn main() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_agent(config: config::Config) -> Result<()> {
|
||||
// Create session manager
|
||||
let mut session = session::SessionManager::new(config.clone());
|
||||
let is_support_session = config.support_code.is_some();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Create tray icon
|
||||
let tray = match tray::TrayController::new(&hostname, config.support_code.as_deref()) {
|
||||
Ok(t) => {
|
||||
@@ -208,12 +226,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);
|
||||
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);
|
||||
show_message_box(
|
||||
"Support Session Ended",
|
||||
"The support session was cancelled by the technician.\n\nThis window will close automatically.",
|
||||
@@ -231,6 +251,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);
|
||||
show_message_box(
|
||||
"Support Session Cancelled",
|
||||
"This support session has been cancelled.\n\nPlease contact your technician for a new support code.",
|
||||
@@ -246,6 +267,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);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -253,6 +275,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);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user