feat: the terminal, project knowledge, and downloads that can be cancelled
- lib/api/terminal.dart: the PTY protocol (create/resize/restart/close, and the /api/terminal/ws binary control frames) with a reconnecting socket that replays the server snapshot at the size it was drawn for. - lib/terminal_state.dart: an xterm model plus that socket, kept per workspace on AppState, so closing the panel or switching tabs keeps the shell; the app reattaches when it returns from the background. - lib/screens/terminal_panel.dart: TerminalView, a status bar (keyboard, restart, clear, close) and a Termux-style key bar whose CTRL/ALT/SHIFT modifiers also apply to what the phone keyboard types. - lib/screens/knowledge_panel.dart: notes, todos and plans from /api/project-context, searchable, with a full page for a plan's Markdown and its raw editor. - Downloads stream with a progress dialog (bytes, total, percent) and a cancel that aborts the request; the save dialog only opens on success. The request asks for `accept-encoding: identity` so Content-Length exists. - MarkdownView renders task lists as ✅/⬜ instead of material_ui's Checkbox, which wants a material_ui Material ancestor the app lacks. - Dialogs own their TextEditingControllers, so closing one no longer trips a framework assertion in debug builds. - 0.3.11 (311).
This commit is contained in:
1 parent
60d02083d3
commit
5f95e2da97
14 files changed
+2347
-57
No files matched your search
+54
-2
@@ -35,7 +35,11 @@ class TransportResponse {
|
||||
final int status;
|
||||
final Map<String, String> headers;
|
||||
final Stream<List<int>> body;
|
||||
const TransportResponse(this.status, this.headers, this.body);
|
||||
|
||||
/// Drops the connection while the body is still being read (a download the
|
||||
/// user cancelled); null when the reply already finished.
|
||||
final void Function()? abort;
|
||||
const TransportResponse(this.status, this.headers, this.body, {this.abort});
|
||||
}
|
||||
|
||||
/// The one seam every request goes through.
|
||||
@@ -43,10 +47,45 @@ abstract class Transport {
|
||||
/// Sends [request], completing when the reply head arrives.
|
||||
Future<TransportResponse> send(TransportRequest request);
|
||||
|
||||
/// Opens a WebSocket on [path] (the terminal stream). Through the same
|
||||
/// sockets as [send], so proxies and certificates keep working.
|
||||
Future<WebSocket> webSocket(String path,
|
||||
{String? rawQuery, Map<String, String> headers = const {}});
|
||||
|
||||
/// Releases whatever sockets the transport holds.
|
||||
void close();
|
||||
}
|
||||
|
||||
/// Lets a caller abandon a download: [cancel] aborts the request and makes the
|
||||
/// reader stop at its next chunk.
|
||||
class CancelToken {
|
||||
bool _cancelled = false;
|
||||
void Function()? _abort;
|
||||
|
||||
bool get isCancelled => _cancelled;
|
||||
|
||||
/// Called by the downloader once the request is in flight.
|
||||
void attach(void Function() abort) {
|
||||
_abort = abort;
|
||||
if (_cancelled) abort();
|
||||
}
|
||||
|
||||
void detach() => _abort = null;
|
||||
|
||||
void cancel() {
|
||||
if (_cancelled) return;
|
||||
_cancelled = true;
|
||||
_abort?.call();
|
||||
}
|
||||
}
|
||||
|
||||
/// Thrown by a download the user cancelled.
|
||||
class DownloadCancelled implements Exception {
|
||||
const DownloadCancelled();
|
||||
@override
|
||||
String toString() => '下载已取消';
|
||||
}
|
||||
|
||||
/// A proxy as configured: an HTTP CONNECT proxy, or a SOCKS5 one.
|
||||
class ProxyConfig {
|
||||
final String scheme; // http | https | socks5 | socks5h
|
||||
@@ -166,7 +205,20 @@ class DirectTransport implements Transport {
|
||||
res.headers.forEach((name, values) {
|
||||
headers[name.toLowerCase()] = values.join(', ');
|
||||
});
|
||||
return TransportResponse(res.statusCode, headers, res);
|
||||
return TransportResponse(res.statusCode, headers, res,
|
||||
abort: req.abort);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WebSocket> webSocket(String path,
|
||||
{String? rawQuery, Map<String, String> headers = const {}}) {
|
||||
// ws:// is http:// with the upgrade; wss:// checks the same certificates,
|
||||
// so the configured client is reused as it stands.
|
||||
final base = this.base.replace(
|
||||
scheme: this.base.scheme == 'https' ? 'wss' : 'ws');
|
||||
final query = rawQuery ?? '';
|
||||
final uri = base.resolve(path).replace(query: query.isEmpty ? null : query);
|
||||
return WebSocket.connect(uri.toString(), headers: headers, customClient: _http);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in new issue
Block a user