fix: reattach the terminal after an app restart
The terminal session id lived only in memory, so the first time the panel opened after a launch it always created another PTY. The old shell stayed on the server (unattached shells live for half an hour) but the client could no longer find it. The id is now remembered per connection and directory. On first open the panel lists /api/terminal/sessions?cwd=<dir> and attaches to the remembered session while the server still has it, showing its replayed history. Without that id it adopts the newest running session of the directory, and only when the directory has nothing does it create one. An explicit "close terminal" forgets the id and forces a fresh shell, and a fatal SESSION_NOT_FOUND clears it and recovers, so a server restart cannot leave a dead panel. The panel is still one terminal per project, not a tab strip. 0.4.2 (402).
This commit is contained in:
1 parent
d25167de58
commit
675d19d563
9 files changed
+287
-11
No files matched your search
@@ -173,7 +173,7 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
_t.link == TerminalLinkState.error) {
|
||||
// A dead session cannot restart in place; a fresh one replaces it.
|
||||
await _t.closeSession();
|
||||
await _t.ensureOpen();
|
||||
await _t.ensureOpen(fresh: true);
|
||||
return;
|
||||
}
|
||||
await _t.restart();
|
||||
@@ -181,7 +181,9 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
|
||||
Future<void> _closeSession() async {
|
||||
await _t.closeSession();
|
||||
if (mounted) await _t.ensureOpen();
|
||||
// An explicit close must not adopt one of the server's other sessions for
|
||||
// this directory (or the old one, if the DELETE lagged): start a new shell.
|
||||
if (mounted) await _t.ensureOpen(fresh: true);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- key bar
|
||||
|
||||
Reference in new issue
Block a user