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) .padding(.vertical, 4)
.background(Color(uiColor: .secondarySystemBackground)) .background(Color(uiColor: .secondarySystemBackground))
} }
.task { await initialBootstrap() } .task { await bootstrap() }
.task { await registry.refresh(credential: credential) } // T-2.6 .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 .sheet(isPresented: $showSwitcher) { // T-2.6
SessionSwitcher(registry: registry, credential: credential) { session in SessionSwitcher(registry: registry, credential: credential) { session in
activeSessionId = session.id activeSessionId = session.id
@ -77,23 +63,12 @@ struct MainTerminalView: View {
// MARK: - Bootstrap // MARK: - Bootstrap
private func initialBootstrap() async { private func bootstrap() async {
statusText = "Looking for sessions…" statusText = "Looking for sessions…"
do { do {
let sessionId = try await resolveSession() let sessionId = try await resolveSession()
await bootstrap(sessionId: sessionId) statusText = "Connecting to \(sessionId)"
} catch { let conn = SessionConnection(id: sessionId, credential: credential)
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)
// Wire live ANSI stream terminal // Wire live ANSI stream terminal
conn.stream conn.stream
@ -186,6 +161,9 @@ struct MainTerminalView: View {
? ResumeCursor().lastSeq(for: sessionId) ? ResumeCursor().lastSeq(for: sessionId)
: nil : nil
await conn.resume(from: lastSeq) await conn.resume(from: lastSeq)
} catch {
statusText = "Error: \(error.localizedDescription)"
}
} }
// MARK: - Session resolution // MARK: - Session resolution