generated from nhcarrigan/template
fix: persist stats across session changes, only reset on disconnect
- Reuse existing WslBridge when reconnecting (preserves stats) - Move reset_session() from start() to stop() so stats only clear on explicit disconnect - Stats now persist through permission prompts, interrupts, and question prompts Closes #59
This commit is contained in:
@@ -29,7 +29,7 @@ impl BridgeManager {
|
||||
conversation_id: &str,
|
||||
options: ClaudeStartOptions,
|
||||
) -> Result<(), String> {
|
||||
// Check if a bridge already exists for this conversation
|
||||
// Check if a bridge already exists and is running for this conversation
|
||||
if self.bridges.get(conversation_id).map(|b| b.is_running()).unwrap_or(false) {
|
||||
return Err("Claude is already running for this conversation".to_string());
|
||||
}
|
||||
@@ -38,15 +38,15 @@ impl BridgeManager {
|
||||
.ok_or_else(|| "App handle not set".to_string())?
|
||||
.clone();
|
||||
|
||||
// Create a new bridge for this conversation
|
||||
let mut bridge = WslBridge::new_with_conversation_id(conversation_id.to_string());
|
||||
// Reuse existing bridge if it exists (preserves stats across reconnects)
|
||||
// Only create a new bridge if one doesn't exist for this conversation
|
||||
let bridge = self.bridges
|
||||
.entry(conversation_id.to_string())
|
||||
.or_insert_with(|| WslBridge::new_with_conversation_id(conversation_id.to_string()));
|
||||
|
||||
// Start the Claude process
|
||||
bridge.start(app, options)?;
|
||||
|
||||
// Store the bridge
|
||||
self.bridges.insert(conversation_id.to_string(), bridge);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -292,8 +292,8 @@ impl WslBridge {
|
||||
self.stdin = stdin;
|
||||
self.process = Some(child);
|
||||
|
||||
// Reset session stats when starting new session
|
||||
self.stats.write().reset_session();
|
||||
// Note: We no longer reset stats here - stats persist across reconnects
|
||||
// Stats are only reset when explicitly disconnecting via stop()
|
||||
|
||||
// Load saved achievements
|
||||
let app_handle = app.clone();
|
||||
@@ -411,6 +411,10 @@ impl WslBridge {
|
||||
self.stdin = None;
|
||||
self.session_id = None;
|
||||
self.mcp_config_file = None; // Temp file is automatically deleted when dropped
|
||||
|
||||
// Reset session stats on explicit disconnect
|
||||
self.stats.write().reset_session();
|
||||
|
||||
emit_connection_status(app, ConnectionStatus::Disconnected, self.conversation_id.clone());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user