feat: a transport seam, image previews, native forms, a phone drawer
- lib/api/transport.dart: TransportRequest/TransportResponse/Transport, with DirectTransport holding the old behaviour (HTTP CONNECT, SOCKS5/socks5h, self-signed and pinned certificates). Client goes through it, so a relay tunnel only adds an implementation. - User rows decode the server's inline attachment data and open the shared image preview on tap; the local path stays the fallback. - The agent's native forms: models from @opencode/client, the form list, replies and cancels, form.* events, and a dock above the composer with when-rules and required-field validation (a switch must be on). - HomeScreen: the session list is the phone's left drawer and a persistent column from 840 px, the chat beside it; the newest session opens on start. - 0.3.10 (310).
This commit is contained in:
1 parent
9b53338908
commit
60d02083d3
11 files changed
+1272
-320
No files matched your search
@@ -0,0 +1,126 @@
|
||||
// The connected shell. A phone treats the session list as the left drawer and
|
||||
// the chat as the screen; a wide layout shows both side by side, which is
|
||||
// where a tablet or a desktop window lands.
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../state.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'sessions_screen.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
final AppState app;
|
||||
const HomeScreen({super.key, required this.app});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
final GlobalKey<ScaffoldState> _scaffold = GlobalKey();
|
||||
bool _opening = false;
|
||||
|
||||
static const _wideBreakpoint = 840.0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.app.addListener(_maybeOpenFirst);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _maybeOpenFirst());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.app.removeListener(_maybeOpenFirst);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Like the first-party client, a phone lands in a conversation rather than
|
||||
/// on an empty pane: open the newest one when nothing is open yet.
|
||||
void _maybeOpenFirst() {
|
||||
final app = widget.app;
|
||||
if (!mounted || _opening) return;
|
||||
if (app.chat != null || app.sessions.isEmpty) return;
|
||||
_opening = true;
|
||||
app.openChat(app.sessions.first).whenComplete(() => _opening = false);
|
||||
}
|
||||
|
||||
void _closeDrawer() {
|
||||
_scaffold.currentState?.closeDrawer();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListenableBuilder(
|
||||
listenable: widget.app,
|
||||
builder: (context, _) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= _wideBreakpoint;
|
||||
final chat = widget.app.chat;
|
||||
final chatView = chat == null
|
||||
? _empty(wide)
|
||||
: ChatScreen(
|
||||
key: ValueKey(chat.session.id),
|
||||
app: widget.app,
|
||||
session: chat.session,
|
||||
onOpenSessions: wide ? null : () =>
|
||||
_scaffold.currentState?.openDrawer(),
|
||||
);
|
||||
if (wide) {
|
||||
return Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 320,
|
||||
child: SessionListPane(app: widget.app),
|
||||
),
|
||||
const VerticalDivider(width: 1),
|
||||
Expanded(child: chatView),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
key: _scaffold,
|
||||
drawer: Drawer(
|
||||
width: constraints.maxWidth * 0.86 > 380
|
||||
? 380
|
||||
: constraints.maxWidth * 0.86,
|
||||
child: SessionListPane(
|
||||
app: widget.app,
|
||||
onOpened: _closeDrawer,
|
||||
),
|
||||
),
|
||||
body: chatView,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _empty(bool wide) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.forum_outlined, size: 40, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(height: 12),
|
||||
Text('选择一个会话',
|
||||
style: TextStyle(fontSize: 16, color: scheme.onSurfaceVariant)),
|
||||
if (!wide) ...[
|
||||
const SizedBox(height: 12),
|
||||
FilledButton(
|
||||
onPressed: () => _scaffold.currentState?.openDrawer(),
|
||||
child: const Text('打开会话列表'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user