Compare commits

..

No commits in common. "f74887f8986552e9e103644f486bde7648b89230" and "df85c9e85bcff538a072ad005629b84afa73293d" have entirely different histories.

1 changed files with 7 additions and 29 deletions

View File

@ -48,22 +48,8 @@ struct MainTerminalView: View {
.padding(.vertical, 4)
.background(Color(uiColor: .secondarySystemBackground))
}
.task { await initialBootstrap() }
.task { await bootstrap() }
.task { await registry.refresh(credential: credential) } // T-2.6
.onChange(of: activeSessionId) { _, newId in
guard let newId else { return }
// Avoid reconnect storm if id already matches the current connection.
if connection?.id == newId { return }
Task {
if let oldConn = connection { await oldConn.suspend() }
cancellables.removeAll()
connection = nil
currentPiState = nil
sessionName = ""
terminalVC.feed(data: Data("\u{1B}[H\u{1B}[2J".utf8))
await bootstrap(sessionId: newId)
}
}
.sheet(isPresented: $showSwitcher) { // T-2.6
SessionSwitcher(registry: registry, credential: credential) { session in
activeSessionId = session.id
@ -77,21 +63,10 @@ struct MainTerminalView: View {
// MARK: - Bootstrap
private func initialBootstrap() async {
private func bootstrap() async {
statusText = "Looking for sessions…"
do {
let sessionId = try await resolveSession()
await bootstrap(sessionId: sessionId)
} catch {
statusText = "Error: \(error.localizedDescription)"
}
}
private func bootstrap(sessionId: String) async {
// Keep activeSessionId in sync. The .onChange handler guards against
// re-entry via `connection?.id == newId` check (connection is still nil here
// on first call, but we set it below before any further state change).
activeSessionId = sessionId
statusText = "Connecting to \(sessionId)"
let conn = SessionConnection(id: sessionId, credential: credential)
@ -186,6 +161,9 @@ struct MainTerminalView: View {
? ResumeCursor().lastSeq(for: sessionId)
: nil
await conn.resume(from: lastSeq)
} catch {
statusText = "Error: \(error.localizedDescription)"
}
}
// MARK: - Session resolution