rustdesk/flutter/lib/models
fufesou 0016033937
feat(terminal): add reconnection buffer support for persistent sessions (#14377)
* feat(terminal): add reconnection buffer support for persistent sessions

Fix two related issues:
1. Reconnecting to persistent sessions shows blank screen - server now
   automatically sends historical buffer on reconnection via SessionState
   machine with pending_buffer, eliminating the need for client-initiated
   buffer requests.
2. Terminal output before view ready causes NaN errors - buffer output
   chunks on client side until terminal view has valid dimensions, then
   flush in order on first valid resize.

Rust side:
- Introduce SessionState enum (Closed/Active) replacing bool is_opened
- Auto-attach pending buffer on reconnection in handle_open()
- Always drain output channel in read_outputs() to prevent overflow
- Increase channel buffer from 100 to 500
- Optimize get_recent() to collect whole chunks (avoids ANSI truncation)
- Extract create_terminal_data_response() helper (DRY)
- Add reconnected flag to TerminalOpened protobuf message

Flutter side:
- Buffer output chunks until terminal view has valid dimensions
- Flush buffered output on first valid resize via _markViewReady()
- Clear terminal on reconnection to avoid duplicate output from buffer replay
- Fix max_bytes type (u32) to match protobuf definition
- Pass reconnected field through FlutterHandler event

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(terminal): add two-phase SIGWINCH for TUI app redraw and session remap on reconnection

Fix TUI apps (top, htop) not redrawing after reconnection. A single
resize-then-restore is too fast for ncurses to detect a size change,
so split across two read_outputs() polling cycles (~30ms apart) to
force a full redraw.

Also fix reconnection failure when client terminal_id doesn't match
any surviving server-side session ID by remapping the lowest surviving
session to the requested ID.

Rust side:
- Add two-phase SIGWINCH state machine (SigwinchPhase: TempResize →
  Restore → Idle) with retry logic (max 3 attempts per phase)
- Add do_sigwinch_resize() for cross-platform PTY resize (direct PTY
  and Windows helper mode)
- Add session remap logic for non-contiguous terminal_id reconnection
- Extract try_send_output() helper with rate-limited drop logging (DRY)
- Add 3-byte limit to UTF-8 continuation byte skipping in get_recent()
  to prevent runaway on non-UTF-8 binary data
- Remove reconnected flag from flutter.rs (unused on client side)

Flutter side:
- Add reconnection screen clear and deferred flush logic
- Filter self from persistent_sessions restore list
- Add comments for web-related changes

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
2026-02-24 21:12:06 +08:00
..
ab_model.dart remove gzip encoding in Legacy AB pushes (#13937) 2026-01-02 10:24:47 +08:00
chat_model.dart fix: web chat (#9588) 2024-10-08 15:23:00 +08:00
cm_file_model.dart feat(fs): delegate win --server file reading to CM (#13736) 2025-12-28 15:39:35 +08:00
desktop_render_texture.dart view camera (#11040) 2025-03-10 21:06:53 +08:00
file_model.dart feat(fs): delegate win --server file reading to CM (#13736) 2025-12-28 15:39:35 +08:00
group_model.dart set allowMalformed to true when decode utf8 (#12693) 2025-08-20 14:55:52 +08:00
input_model.dart fix(ios): capsLock, workaround #5871 (#14194) 2026-01-30 17:32:18 +08:00
model.dart fix(mobile): account for safe area padding in canvas size calculation (#14285) 2026-02-15 14:52:27 +08:00
native_model.dart fix: ios, file transfer, home dir (#12657) 2025-08-15 00:00:05 +08:00
peer_model.dart show peer note (#13140) 2025-10-12 14:59:42 +08:00
peer_tab_model.dart disable-discovery-pane 2025-09-01 17:07:29 +08:00
platform_model.dart fix: web send audit note (#9582) 2024-10-07 21:37:43 +08:00
printer_model.dart feat: take screenshot (#11591) 2025-04-30 17:23:35 +08:00
relative_mouse_model.dart feat: Add relative mouse mode (#13928) 2026-01-09 10:03:14 +08:00
server_model.dart keep-awake-during-incoming-sessions (#14082) 2026-01-21 16:25:57 +08:00
state_model.dart feat: Add relative mouse mode (#13928) 2026-01-09 10:03:14 +08:00
terminal_model.dart feat(terminal): add reconnection buffer support for persistent sessions (#14377) 2026-02-24 21:12:06 +08:00
user_model.dart - UI display: display_name first (#14358) 2026-02-22 14:59:25 +08:00
web_model.dart Revert "try fix firefox v2 paste problem" (#12126) 2025-06-19 22:31:40 +08:00