feat: a settings page, a server footer in the sidebar, and follow-up behaviour
- The sidebar's server switch moves to a footer bar: the connected server's name on the left (tap for the server sheet) and a settings key on the right, matching the first-party phone layout. - Settings has three groups: 外观 (theme mode and seed colour, stored on the device only in shared_preferences), 聊天 (the server's followUpBehavior: steer or queue) and a 宠物 placeholder. The app theme now reads the seed and mode. - The chat's short send while a turn runs uses the configured follow-up behaviour; the long-press sheet offers both and marks the default. The value is read from GET /api/config/settings?surface=mobile on connect, on resume and when the page opens, and written back with PUT. - Tests: settings page groups and choice, sidebar footer naming the server and opening settings, follow-up normalization. - 0.3.17 (317).
This commit is contained in:
1 parent
1aa84a53e5
commit
e646130d1f
13 files changed
+544
-15
No files matched your search
@@ -1621,6 +1621,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
if (!chat.running) return _send();
|
||||
final text = _draftCtrl.text.trim();
|
||||
if (text.isEmpty && _attachments.isEmpty) return;
|
||||
// The configured behavior is what a short press does; mark it here too.
|
||||
final fallback = widget.app.followUpBehavior;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final picked = await showModalBottomSheet<String>(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
@@ -1639,12 +1642,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
leading: const Icon(Icons.alt_route),
|
||||
title: const Text('转向当前回合'),
|
||||
subtitle: const Text('在下一步加入,工作继续'),
|
||||
trailing: fallback == 'steer'
|
||||
? Icon(Icons.check, size: 20, color: scheme.primary)
|
||||
: null,
|
||||
onTap: () => Navigator.pop(sheet, 'steer'),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.schedule),
|
||||
title: const Text('排队'),
|
||||
subtitle: const Text('等本轮结束后发送'),
|
||||
trailing: fallback == 'queue'
|
||||
? Icon(Icons.check, size: 20, color: scheme.primary)
|
||||
: null,
|
||||
onTap: () => Navigator.pop(sheet, 'queue'),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -1659,9 +1668,10 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
Future<void> _send({String? delivery}) async {
|
||||
final text = _draftCtrl.text.trim();
|
||||
if (text.isEmpty && _attachments.isEmpty) return;
|
||||
// An ordinary send while a turn runs joins it, as dsh-Go does; the
|
||||
// long-press sheet can choose to wait instead.
|
||||
final effective = chat.running ? (delivery ?? 'steer') : null;
|
||||
// A short send while a turn runs uses the configured follow-up behavior;
|
||||
// the long-press sheet can choose the other one for this message.
|
||||
final effective =
|
||||
chat.running ? (delivery ?? widget.app.followUpBehavior) : null;
|
||||
// Files ride with the prompt as data URLs.
|
||||
final files = <Map<String, String>>[];
|
||||
final images = <String>[];
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
import '../api/models.dart';
|
||||
import '../state.dart';
|
||||
import 'servers_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
|
||||
/// The session list: a drawer on a phone, a persistent column on a wide
|
||||
/// layout. Sessions are grouped by project, dated within it, and a row swipes
|
||||
@@ -69,11 +70,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
padding: const EdgeInsets.fromLTRB(4, 6, 4, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.dns_outlined),
|
||||
tooltip: '服务器',
|
||||
onPressed: _instancesSheet,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Text('会话',
|
||||
style: TextStyle(
|
||||
@@ -132,6 +129,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
),
|
||||
),
|
||||
Expanded(child: _body(scheme)),
|
||||
_serverFooter(scheme),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -139,6 +137,67 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
);
|
||||
}
|
||||
|
||||
/// The bottom bar: the connected server on the left (tap to switch), the
|
||||
/// settings key on the right, as the first-party phone sidebar has it.
|
||||
Widget _serverFooter(ColorScheme scheme) {
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(color: scheme.outlineVariant.withValues(alpha: 0.6)),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 4, 4, 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: _instancesSheet,
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 6, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.dns_outlined,
|
||||
size: 18, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_app.connectionName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.settings_outlined),
|
||||
tooltip: '设置',
|
||||
onPressed: _openSettings,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _openSettings() {
|
||||
// A phone's list is a drawer: close it before the settings page covers
|
||||
// the shell.
|
||||
widget.onOpened?.call();
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (_) => SettingsScreen(app: _app),
|
||||
));
|
||||
}
|
||||
|
||||
Widget _body(ColorScheme scheme) {
|
||||
final app = _app;
|
||||
if (app.sessionsLoading && app.sessions.isEmpty) {
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
// Settings. Three groups for now: appearance (device-local theme), chat (the
|
||||
// server's follow-up behavior) and a pet placeholder.
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../appearance_prefs.dart';
|
||||
import '../state.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
final AppState app;
|
||||
const SettingsScreen({super.key, required this.app});
|
||||
|
||||
@override
|
||||
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Pick up a change made on another client while this page opens.
|
||||
widget.app.refreshFollowUpBehavior();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final look = AppearancePrefs.instance;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('设置')),
|
||||
body: ListenableBuilder(
|
||||
listenable: Listenable.merge([widget.app, look]),
|
||||
builder: (context, _) {
|
||||
final theme = Theme.of(context);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(top: 4, bottom: 32),
|
||||
children: [
|
||||
const _SectionHeader('外观', note: '仅当前设备生效,不同步到服务器'),
|
||||
_appearance(theme, look),
|
||||
const _SectionHeader('聊天'),
|
||||
_chat(theme),
|
||||
const _SectionHeader('宠物'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 4, 20, 8),
|
||||
child: Text('暂未提供设置',
|
||||
style: TextStyle(fontSize: 13, color: theme.hintColor)),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- appearance
|
||||
|
||||
Widget _appearance(ThemeData theme, AppearancePrefs look) {
|
||||
const modes = [
|
||||
(ThemeMode.system, '跟随系统'),
|
||||
(ThemeMode.light, '浅色'),
|
||||
(ThemeMode.dark, '深色'),
|
||||
];
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const _Label('主题模式'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 12),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (final (mode, label) in modes)
|
||||
ChoiceChip(
|
||||
label: Text(label),
|
||||
selected: look.themeMode == mode,
|
||||
onSelected: (_) => look.setThemeMode(mode),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const _Label('主题色'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
for (final seed in appearanceSeeds) _swatch(theme, look, seed),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _swatch(ThemeData theme, AppearancePrefs look, int seed) {
|
||||
final color = Color(seed);
|
||||
final selected = look.seedColor.toARGB32() == seed;
|
||||
return Semantics(
|
||||
button: true,
|
||||
selected: selected,
|
||||
label: '主题色 ${seed.toRadixString(16)}',
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
onTap: () => look.setSeedColor(seed),
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: selected
|
||||
? theme.colorScheme.onSurface
|
||||
: theme.colorScheme.outlineVariant,
|
||||
width: selected ? 2.5 : 1,
|
||||
),
|
||||
),
|
||||
child: selected
|
||||
? const Icon(Icons.check, size: 20, color: Colors.white)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- chat
|
||||
|
||||
Widget _chat(ThemeData theme) {
|
||||
final steer = widget.app.followUpBehavior == 'steer';
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const ListTile(
|
||||
title: Text('追问处理行为'),
|
||||
subtitle: Text('运行中按发送时,消息默认怎么处理。与网页端设置同步。'),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 6),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
label: const Text('转向'),
|
||||
selected: steer,
|
||||
onSelected: (_) => _setFollowUp('steer'),
|
||||
),
|
||||
ChoiceChip(
|
||||
label: const Text('排队'),
|
||||
selected: !steer,
|
||||
onSelected: (_) => _setFollowUp('queue'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Text(
|
||||
steer ? '转向:在下一步加入当前回合,工作继续。' : '排队:等当前回合结束后再发送。',
|
||||
style: TextStyle(fontSize: 12.5, color: theme.hintColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _setFollowUp(String value) async {
|
||||
final ok = await widget.app.setFollowUpBehavior(value);
|
||||
if (!ok && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(widget.app.lastError ?? '保存失败')),
|
||||
);
|
||||
widget.app.clearLastError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionHeader extends StatelessWidget {
|
||||
final String title;
|
||||
final String? note;
|
||||
const _SectionHeader(this.title, {this.note});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 18, 20, 6),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: theme.colorScheme.primary,
|
||||
)),
|
||||
if (note != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: Text(note!,
|
||||
style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Label extends StatelessWidget {
|
||||
final String text;
|
||||
const _Label(this.text);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 2, 20, 6),
|
||||
child: Text(text,
|
||||
style: const TextStyle(fontSize: 13.5, fontWeight: FontWeight.w500)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user