mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-27 15:17:38 +00:00
better session management
This commit is contained in:
parent
35bc91e0de
commit
8bea2c87f6
1 changed files with 43 additions and 4 deletions
|
|
@ -275,13 +275,52 @@ func (s *Session) AttachSpawnedSession() error {
|
||||||
}
|
}
|
||||||
s.pty = pty
|
s.pty = pty
|
||||||
|
|
||||||
// Start the PTY with the command from session info
|
// Update session status
|
||||||
if err := s.pty.Start(); err != nil {
|
s.info.Status = string(StatusRunning)
|
||||||
return fmt.Errorf("failed to start PTY: %w", err)
|
s.info.Pid = pty.Pid()
|
||||||
|
|
||||||
|
if err := s.info.Save(s.Path()); err != nil {
|
||||||
|
if err := pty.Close(); err != nil {
|
||||||
|
log.Printf("[ERROR] Failed to close PTY: %v", err)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("failed to update session info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a channel to signal when PTY.Run() completes
|
||||||
|
ptyDone := make(chan struct{})
|
||||||
|
|
||||||
|
// Start the PTY I/O loop in a goroutine (like Start() does)
|
||||||
|
go func() {
|
||||||
|
defer close(ptyDone)
|
||||||
|
if err := s.pty.Run(); err != nil {
|
||||||
|
if os.Getenv("VIBETUNNEL_DEBUG") != "" {
|
||||||
|
log.Printf("[DEBUG] Session %s: PTY.Run() exited with error: %v", s.ID[:8], err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if os.Getenv("VIBETUNNEL_DEBUG") != "" {
|
||||||
|
log.Printf("[DEBUG] Session %s: PTY.Run() exited normally", s.ID[:8])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Ensure session status is updated
|
||||||
|
s.UpdateStatus()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Start control listener
|
||||||
|
s.startControlListener()
|
||||||
|
|
||||||
// Attach to the PTY to connect stdin/stdout
|
// Attach to the PTY to connect stdin/stdout
|
||||||
return s.pty.Attach()
|
attachErr := s.pty.Attach()
|
||||||
|
|
||||||
|
// Wait a moment for PTY cleanup to complete
|
||||||
|
select {
|
||||||
|
case <-ptyDone:
|
||||||
|
// PTY.Run() already completed
|
||||||
|
case <-time.After(500 * time.Millisecond):
|
||||||
|
// Give it a bit more time to update status
|
||||||
|
s.UpdateStatus()
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) SendKey(key string) error {
|
func (s *Session) SendKey(key string) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue